From 8a890cf945cfbd72f6e4b64f8c7b52d2c6ca099e Mon Sep 17 00:00:00 2001 From: peterbell10 Date: Mon, 22 May 2017 21:27:55 +0100 Subject: Store cChunk::m_BlockEntities in a map (#3717) * Store block entities in a map from block index * Cleanup ForEachBlockEntity * Cleanup DoWithBlockEntityAt --- src/SetChunkData.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src/SetChunkData.cpp') diff --git a/src/SetChunkData.cpp b/src/SetChunkData.cpp index d85f78459..cb530b3b6 100644 --- a/src/SetChunkData.cpp +++ b/src/SetChunkData.cpp @@ -34,7 +34,7 @@ cSetChunkData::cSetChunkData( const cChunkDef::HeightMap * a_HeightMap, const cChunkDef::BiomeMap * a_Biomes, cEntityList && a_Entities, - cBlockEntityList && a_BlockEntities, + cBlockEntities && a_BlockEntities, bool a_ShouldMarkDirty ) : m_ChunkX(a_ChunkX), @@ -119,23 +119,21 @@ void cSetChunkData::CalculateHeightMap(void) void cSetChunkData::RemoveInvalidBlockEntities(void) { - for (cBlockEntityList::iterator itr = m_BlockEntities.begin(); itr != m_BlockEntities.end();) + for (cBlockEntities::iterator itr = m_BlockEntities.begin(); itr != m_BlockEntities.end();) { - BLOCKTYPE EntityBlockType = (*itr)->GetBlockType(); - BLOCKTYPE WorldBlockType = cChunkDef::GetBlock(m_BlockTypes, (*itr)->GetRelX(), (*itr)->GetPosY(), (*itr)->GetRelZ()); + cBlockEntity * BlockEntity = itr->second; + BLOCKTYPE EntityBlockType = BlockEntity->GetBlockType(); + BLOCKTYPE WorldBlockType = cChunkDef::GetBlock(m_BlockTypes, BlockEntity->GetRelX(), BlockEntity->GetPosY(), BlockEntity->GetRelZ()); if (EntityBlockType != WorldBlockType) { // Bad blocktype, remove the block entity: LOGD("Block entity blocktype mismatch at {%d, %d, %d}: entity for blocktype %s(%d) in block %s(%d). Deleting the block entity.", - (*itr)->GetPosX(), (*itr)->GetPosY(), (*itr)->GetPosZ(), + BlockEntity->GetPosX(), BlockEntity->GetPosY(), BlockEntity->GetPosZ(), ItemTypeToString(EntityBlockType).c_str(), EntityBlockType, ItemTypeToString(WorldBlockType).c_str(), WorldBlockType ); - cBlockEntityList::iterator itr2 = itr; - ++itr2; - delete *itr; - m_BlockEntities.erase(itr); - itr = itr2; + delete BlockEntity; + itr = m_BlockEntities.erase(itr); } else { -- cgit v1.2.3