From 49c443896dcac8c4eaf08c4024e8bd2366ad899a Mon Sep 17 00:00:00 2001 From: LogicParrot Date: Sat, 2 Sep 2017 10:45:06 +0300 Subject: Revert "Replace ItemCallbacks with lambdas (#3948)" This reverts commit 496c337cdfa593654018c171f6a74c28272265b5. --- src/Chunk.cpp | 85 +++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 35 deletions(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 3a81b9ed1..78a8461d3 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -1,4 +1,4 @@ - + #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #ifndef _WIN32 @@ -2114,12 +2114,17 @@ bool cChunk::HasEntity(UInt32 a_EntityID) -bool cChunk::ForEachEntity(const cEntityCallback & a_Callback) +bool cChunk::ForEachEntity(cEntityCallback & a_Callback) { // The entity list is locked by the parent chunkmap's CS - for (const auto & Entity : m_Entities) + for (auto itr = m_Entities.begin(), itr2 = itr; itr != m_Entities.end(); itr = itr2) { - if (Entity->IsTicking() && a_Callback(*Entity)) + ++itr2; + if (!(*itr)->IsTicking()) + { + continue; + } + if (a_Callback.Item(itr->get())) { return false; } @@ -2131,22 +2136,23 @@ bool cChunk::ForEachEntity(const cEntityCallback & a_Callback) -bool cChunk::ForEachEntityInBox(const cBoundingBox & a_Box, const cEntityCallback & a_Callback) +bool cChunk::ForEachEntityInBox(const cBoundingBox & a_Box, cEntityCallback & a_Callback) { // The entity list is locked by the parent chunkmap's CS - for (const auto & Entity : m_Entities) + for (auto itr = m_Entities.begin(), itr2 = itr; itr != m_Entities.end(); itr = itr2) { - if (!Entity->IsTicking()) + ++itr2; + if (!(*itr)->IsTicking()) { continue; } - cBoundingBox EntBox(Entity->GetPosition(), Entity->GetWidth() / 2, Entity->GetHeight()); + cBoundingBox EntBox((*itr)->GetPosition(), (*itr)->GetWidth() / 2, (*itr)->GetHeight()); if (!EntBox.DoesIntersect(a_Box)) { // The entity is not in the specified box continue; } - if (a_Callback(*Entity)) + if (a_Callback.Item(itr->get())) { return false; } @@ -2158,14 +2164,23 @@ bool cChunk::ForEachEntityInBox(const cBoundingBox & a_Box, const cEntityCallbac -bool cChunk::DoWithEntityByID(UInt32 a_EntityID, const cEntityCallback & a_Callback, bool & a_CallbackResult) +bool cChunk::DoWithEntityByID(UInt32 a_EntityID, cEntityCallback & a_Callback, bool & a_CallbackResult) +{ + return DoWithEntityByID(a_EntityID, std::bind(&cEntityCallback::Item, &a_Callback, std::placeholders::_1), a_CallbackResult); +} + + + + + +bool cChunk::DoWithEntityByID(UInt32 a_EntityID, cLambdaEntityCallback a_Callback, bool & a_CallbackResult) { // The entity list is locked by the parent chunkmap's CS for (const auto & Entity : m_Entities) { if ((Entity->GetUniqueID() == a_EntityID) && (Entity->IsTicking())) { - a_CallbackResult = a_Callback(*Entity); + a_CallbackResult = a_Callback(Entity.get()); return true; } } // for itr - m_Entitites[] @@ -2177,7 +2192,7 @@ bool cChunk::DoWithEntityByID(UInt32 a_EntityID, const cEntityCallback & a_Callb template -bool cChunk::GenericForEachBlockEntity(const std::function & a_Callback) +bool cChunk::GenericForEachBlockEntity(cItemCallback& a_Callback) { // The blockentity list is locked by the parent chunkmap's CS for (auto & KeyPair : m_BlockEntities) @@ -2188,7 +2203,7 @@ bool cChunk::GenericForEachBlockEntity(const std::function & a (IsOneOf(Block->GetBlockType())) ) { - if (a_Callback(*static_cast(Block))) + if (a_Callback.Item(static_cast(Block))) { return false; } @@ -2201,7 +2216,7 @@ bool cChunk::GenericForEachBlockEntity(const std::function & a -bool cChunk::ForEachBlockEntity(const cBlockEntityCallback & a_Callback) +bool cChunk::ForEachBlockEntity(cBlockEntityCallback & a_Callback) { return GenericForEachBlockEntity(a_Callback); } @@ -2210,7 +2225,7 @@ bool cChunk::ForEachBlockEntity(const cBlockEntityCallback & a_Callback) -bool cChunk::ForEachBrewingstand(const cBrewingstandCallback & a_Callback) +bool cChunk::ForEachBrewingstand(cBrewingstandCallback & a_Callback) { return GenericForEachBlockEntity -bool cChunk::GenericDoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, const std::function & a_Callback) +bool cChunk::GenericDoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cItemCallback& a_Callback) { // The blockentity list is locked by the parent chunkmap's CS cBlockEntity * Block = GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ); @@ -2294,14 +2309,14 @@ bool cChunk::GenericDoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ { return false; // Not any of the given tBlocktypes } - return !a_Callback(*static_cast(Block)); + return !a_Callback.Item(static_cast(Block)); } -bool cChunk::DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, const cBlockEntityCallback & a_Callback) +bool cChunk::DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBlockEntityCallback & a_Callback) { return GenericDoWithBlockEntityAt(a_BlockX, a_BlockY, a_BlockZ, a_Callback); } @@ -2309,7 +2324,7 @@ bool cChunk::DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, const -bool cChunk::DoWithBeaconAt(int a_BlockX, int a_BlockY, int a_BlockZ, const cBeaconCallback & a_Callback) +bool cChunk::DoWithBeaconAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBeaconCallback & a_Callback) { return GenericDoWithBlockEntityAt