From b20fffb9312bd628146559a3810988e7373ed019 Mon Sep 17 00:00:00 2001 From: blockmaster2000 Date: Tue, 15 Nov 2016 16:37:31 +0100 Subject: [PATCH] Fix some things --- src/content_mapblock.cpp | 29 ++++++++++++++++------------- src/mapblock_mesh.cpp | 7 +++++-- src/selection_mesh.cpp | 2 +- src/tile.h | 3 +++ 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/content_mapblock.cpp b/src/content_mapblock.cpp index bba16a3..44a48ce 100644 --- a/src/content_mapblock.cpp +++ b/src/content_mapblock.cpp @@ -34,7 +34,10 @@ #include "sound.h" #ifndef SERVER - +float roundf(float x) +{ + return (float)((x < 0) ? (ceil((x) - 0.5)) : (floor((x) + 0.5))); +} static const v3s16 corners[8] = { v3s16(-1, 1, 1), v3s16( 1, 1, 1), @@ -2709,10 +2712,10 @@ void meshgen_liquid(MeshMakeData *data, v3s16 p, MapNode &n, SelectedNode &selec if (top_is_same_liquid == false) { video::S3DVertex vertices[4] = { - video::S3DVertex(-0.5*data->m_BS,0, 0.5*data->m_BS, 0,0,0, video::SColor(255,255,255,255), tiles[0].texture.x1(), tiles[0].texture.y1()), - video::S3DVertex( 0.5*data->m_BS,0, 0.5*data->m_BS, 0,0,0, video::SColor(255,255,255,255), tiles[0].texture.x0(), tiles[0].texture.y1()), - video::S3DVertex( 0.5*data->m_BS,0,-0.5*data->m_BS, 0,0,0, video::SColor(255,255,255,255), tiles[0].texture.x0(), tiles[0].texture.y0()), - video::S3DVertex(-0.5*data->m_BS,0,-0.5*data->m_BS, 0,0,0, video::SColor(255,255,255,255), tiles[0].texture.x1(), tiles[0].texture.y0()) + video::S3DVertex(-0.5*data->m_BS,0, 0.5*data->m_BS, 0,0,0, video::SColor(255,255,255,255), tiles[0].texture.x0(), tiles[0].texture.y1()), + video::S3DVertex( 0.5*data->m_BS,0, 0.5*data->m_BS, 0,0,0, video::SColor(255,255,255,255), tiles[0].texture.x1(), tiles[0].texture.y1()), + video::S3DVertex( 0.5*data->m_BS,0,-0.5*data->m_BS, 0,0,0, video::SColor(255,255,255,255), tiles[0].texture.x1(), tiles[0].texture.y0()), + video::S3DVertex(-0.5*data->m_BS,0,-0.5*data->m_BS, 0,0,0, video::SColor(255,255,255,255), tiles[0].texture.x0(), tiles[0].texture.y0()) }; // To get backface culling right, the vertices need to go @@ -2730,15 +2733,15 @@ void meshgen_liquid(MeshMakeData *data, v3s16 p, MapNode &n, SelectedNode &selec // -Z towards +Z, thus the direction is +Z. // Rotate texture to make animation go in flow direction // Positive if liquid moves towards +Z - int dz = (corner_levels[side_corners[2][0]] + - corner_levels[side_corners[2][1]] < - corner_levels[side_corners[3][0]] + - corner_levels[side_corners[3][1]]); + int dz = (corner_levels[side_corners[3][0]] + + corner_levels[side_corners[3][1]]) - + (corner_levels[side_corners[2][0]] + + corner_levels[side_corners[2][1]]); // Positive if liquid moves towards +X - int dx = (corner_levels[side_corners[0][0]] + - corner_levels[side_corners[0][1]] < - corner_levels[side_corners[1][0]] + - corner_levels[side_corners[1][1]]); + int dx = (corner_levels[side_corners[1][0]] + + corner_levels[side_corners[1][1]]) - + (corner_levels[side_corners[0][0]] + + corner_levels[side_corners[0][1]]); // -X if (-dx >= abs(dz)) { v2f t = vertices[0].TCoords; diff --git a/src/mapblock_mesh.cpp b/src/mapblock_mesh.cpp index 2eb2b6c..8a335b7 100644 --- a/src/mapblock_mesh.cpp +++ b/src/mapblock_mesh.cpp @@ -480,6 +480,7 @@ void MapBlockMesh::animate(float time) AnimationData temp_data = it->second; const TileSpec &tile = temp_data.tile; + // Figure out current frame int frame = (int)(time * 1000 / tile.animation_frame_length_ms) % tile.animation_frame_count; @@ -500,7 +501,7 @@ void MapBlockMesh::animate(float time) scene::IMeshBuffer *buf = m_mesh->getMeshBuffer(it->first); // Create new texture name from original - if (g_texturesource && buf != 0) { + if (g_texturesource && frame >= 0) { std::ostringstream os(std::ios::binary); os << g_texturesource->getTextureName(tile.texture.id); os << "^[verticalframe:" << (int)tile.animation_frame_count << ":" << frame; @@ -725,12 +726,14 @@ void MapBlockMesh::generate(MeshMakeData *data, v3s16 camera_offset, JMutex *mut m_meshdata.swap(data->m_meshdata); m_fardata.swap(data->m_fardata); refresh(data->m_daynight_ratio); - animate(0.0); // get first frame of animation m_mesh->recalculateBoundingBox(); if (mutex != NULL) mutex->Unlock(); + // Get frist frame of animation AFTER the mutex is unlocked + animate(0.0); + END_DEBUG_EXCEPTION_HANDLER(errorstream) } diff --git a/src/selection_mesh.cpp b/src/selection_mesh.cpp index 3c8d8d6..d750e6b 100644 --- a/src/selection_mesh.cpp +++ b/src/selection_mesh.cpp @@ -262,7 +262,7 @@ void SelectionMesh::generate(MeshMakeData *data) // it's a typedeffed CMeshBuffer scene::SMeshBuffer *buf = new scene::SMeshBuffer(); // Set material - buf->Material = d.material; + buf->Material = d.tile.getMaterial(); // Add to mesh mesh->addMeshBuffer(buf); // Mesh grabbed it diff --git a/src/tile.h b/src/tile.h index 064609d..c4611b3 100644 --- a/src/tile.h +++ b/src/tile.h @@ -292,8 +292,11 @@ struct TileSpec animation_frame_count(0), animation_frame_length_ms(0) { +#ifndef SERVER + // init material only on clients video::SMaterial m; m_material = m; +#endif } bool operator==(TileSpec &other)