From bc6446fc4a9ab2f87eeb4563caed69ab4626884e Mon Sep 17 00:00:00 2001 From: BlockMen Date: Tue, 25 Apr 2017 23:59:59 +0200 Subject: [PATCH] Don't copy material, return ref const instead Also update AnimData directly (maybe this causes SegFaulting? idk) --- src/mapblock_mesh.cpp | 11 ++++------- src/selection_mesh.cpp | 11 ++++------- src/tile.h | 2 +- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/mapblock_mesh.cpp b/src/mapblock_mesh.cpp index 4dab601..138bc5b 100644 --- a/src/mapblock_mesh.cpp +++ b/src/mapblock_mesh.cpp @@ -478,21 +478,18 @@ void MapBlockMesh::animate(float time) for (std::map::iterator it = m_animation_data.begin(); it != m_animation_data.end(); ++it) { - AnimationData temp_data = it->second; - const TileSpec &tile = temp_data.tile; + const TileSpec &tile = it->second.tile; // Figure out current frame int frame = (int)(time * 1000 / tile.animation_frame_length_ms) % tile.animation_frame_count; // If frame doesn't change, skip - if (frame == temp_data.frame) + if (frame == it->second.frame) continue; - temp_data.frame = frame; + m_animation_data[it->first].frame = frame; - m_animation_data[it->first] = temp_data; - - // Make sure we don't cause an overflow. Can get removed if future is no problems occuring + // Make sure we don't cause an overflow. Can get removed in future if no problems occuring if (it->first >= m_mesh->getMeshBufferCount()) { errorstream << ": animate() Tying to index non existent Buffer." << std::endl; return; diff --git a/src/selection_mesh.cpp b/src/selection_mesh.cpp index 782f5cb..81ef1d5 100644 --- a/src/selection_mesh.cpp +++ b/src/selection_mesh.cpp @@ -163,19 +163,16 @@ void SelectionMesh::animate(float time) for (std::map::iterator it = m_animation_data.begin(); it != m_animation_data.end(); ++it) { - AnimationData temp_data = it->second; - const TileSpec &tile = temp_data.tile; + const TileSpec &tile = it->second.tile; // Figure out current frame int frame = (int)(time * 1000 / tile.animation_frame_length_ms) % tile.animation_frame_count; // If frame doesn't change, skip - if (frame == temp_data.frame)// || temp_data.frame < 0) + if (frame == it->second.frame)// || temp_data.frame < 0) continue; - - temp_data.frame = frame; - - m_animation_data[it->first] = temp_data; + + m_animation_data[it->first].frame = frame; // Make sure we don't cause an overflow. Can get removed if future is no problems occuring if (it->first >= m_mesh->getMeshBufferCount()) { diff --git a/src/tile.h b/src/tile.h index 064609d..09f78c8 100644 --- a/src/tile.h +++ b/src/tile.h @@ -335,7 +335,7 @@ struct TileSpec material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING) ? true : false; } - video::SMaterial getMaterial() + const video::SMaterial &getMaterial() { applyMaterialOptions(m_material); m_material.setTexture(0, texture.atlas);