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/Chunk.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/Chunk.h') diff --git a/src/Chunk.h b/src/Chunk.h index d7ebd2a77..e5fb162be 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -276,6 +276,12 @@ public: bool DoWithEntityByID(UInt32 a_EntityID, cEntityCallback & a_Callback, bool & a_CallbackResult); // Lua-accessible bool DoWithEntityByID(UInt32 a_EntityID, cLambdaEntityCallback a_Callback, bool & a_CallbackResult); // Lambda version + /** Calls the callback for each tyEntity; returns true if all block entities processed, false if the callback aborted by returning true + tBlocktypes are all blocktypes convertible to tyEntity which are to be called. If no block type is given the callback is called for every block entity + Accessible only from within Chunk.cpp */ + template + bool GenericForEachBlockEntity(cItemCallback& a_Callback); + /** Calls the callback for each block entity; returns true if all block entities processed, false if the callback aborted by returning true */ bool ForEachBlockEntity(cBlockEntityCallback & a_Callback); // Lua-accessible @@ -297,6 +303,12 @@ public: /** Calls the callback for each furnace; returns true if all furnaces processed, false if the callback aborted by returning true */ bool ForEachFurnace(cFurnaceCallback & a_Callback); // Lua-accessible + /** Calls the callback for the tyEntity at the specified coords; returns false if there's no such block entity at those coords, true if found + tBlocktype is a list of the blocktypes to be called. If no BLOCKTYPE template arguments are given the callback is called for any block entity + Accessible only from within Chunk.cpp */ + template + bool GenericDoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cItemCallback& a_Callback); + /** Calls the callback for the block entity at the specified coords; returns false if there's no block entity at those coords, true if found */ bool DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback & a_Callback); // Lua-acessible @@ -524,7 +536,7 @@ private: // A critical section is not needed, because all chunk access is protected by its parent ChunkMap's csLayers std::vector m_LoadedByClient; cEntityList m_Entities; - cBlockEntityList m_BlockEntities; + cBlockEntities m_BlockEntities; /** Number of times the chunk has been requested to stay (by various cChunkStay objects); if zero, the chunk can be unloaded */ int m_StayCount; @@ -566,7 +578,10 @@ private: void RemoveBlockEntity(cBlockEntity * a_BlockEntity); void AddBlockEntity (cBlockEntity * a_BlockEntity); - /** Creates a block entity for each block that needs a block entity and doesn't have one in the list */ + /** Add a block entity to the chunk without marking the chunk dirty */ + void AddBlockEntityClean(cBlockEntity * a_BlockEntity); + + /** Creates a block entity for each block that needs a block entity and doesn't have one already */ void CreateBlockEntities(void); /** Wakes up each simulator for its specific blocks; through all the blocks in the chunk */ -- cgit v1.2.3