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/Entities/Player.cpp | 73 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 56 insertions(+), 17 deletions(-) (limited to 'src/Entities/Player.cpp') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 93368f6fb..fb2274cad 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1005,21 +1005,36 @@ bool cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI) void cPlayer::NotifyNearbyWolves(cPawn * a_Opponent, bool a_IsPlayerInvolved) { ASSERT(a_Opponent != nullptr); + class LookForWolves : public cEntityCallback + { + public: + cPlayer * m_Player; + cPawn * m_Attacker; + bool m_IsPlayerInvolved; + + LookForWolves(cPlayer * a_Me, cPawn * a_MyAttacker, bool a_PlayerInvolved) : + m_Player(a_Me), + m_Attacker(a_MyAttacker), + m_IsPlayerInvolved(a_PlayerInvolved) + { + } - m_World->ForEachEntityInBox(cBoundingBox(GetPosition(), 16), [&] (cEntity & a_Entity) + virtual bool Item(cEntity * a_Entity) override { - if (a_Entity.IsMob()) + if (a_Entity->IsMob()) { - auto & Mob = static_cast(a_Entity); - if (Mob.GetMobType() == mtWolf) + cMonster * Mob = static_cast(a_Entity); + if (Mob->GetMobType() == mtWolf) { - auto & Wolf = static_cast(Mob); - Wolf.ReceiveNearbyFightInfo(GetUUID(), a_Opponent, a_IsPlayerInvolved); + cWolf * Wolf = static_cast(Mob); + Wolf->ReceiveNearbyFightInfo(m_Player->GetUUID(), m_Attacker, m_IsPlayerInvolved); } } return false; } - ); + } Callback(this, a_Opponent, a_IsPlayerInvolved); + + m_World->ForEachEntityInBox(cBoundingBox(GetPosition(), 16), Callback); } @@ -2417,12 +2432,17 @@ void cPlayer::HandleFloater() { return; } - m_World->DoWithEntityByID(m_FloaterID, [](cEntity & a_Entity) + class cFloaterCallback : + public cEntityCallback + { + public: + virtual bool Item(cEntity * a_Entity) override { - a_Entity.Destroy(true); + a_Entity->Destroy(true); return true; } - ); + } Callback; + m_World->DoWithEntityByID(m_FloaterID, Callback); SetIsFishing(false); } @@ -2666,18 +2686,29 @@ bool cPlayer::DoesPlacingBlocksIntersectEntity(const sSetBlockVector & a_Blocks) cWorld * World = GetWorld(); // Check to see if any entity intersects any block being placed - return !World->ForEachEntityInBox(PlacingBounds, [&](cEntity & a_Entity) + class DoesIntersectBlock : public cEntityCallback + { + public: + const std::vector & m_BoundingBoxes; + + // The distance inside the block the entity can still be. + const double EPSILON = 0.0005; + + DoesIntersectBlock(const std::vector & a_BoundingBoxes) : + m_BoundingBoxes(a_BoundingBoxes) { - // The distance inside the block the entity can still be. - const double EPSILON = 0.0005; + } - if (!a_Entity.DoesPreventBlockPlacement()) + virtual bool Item(cEntity * a_Entity) override + { + if (!a_Entity->DoesPreventBlockPlacement()) { return false; } - cBoundingBox EntBox(a_Entity.GetPosition(), a_Entity.GetWidth() / 2, a_Entity.GetHeight()); - for (auto BlockBox : PlacementBoxes) + cBoundingBox EntBox(a_Entity->GetPosition(), a_Entity->GetWidth() / 2, a_Entity->GetHeight()); + for (auto BlockBox: m_BoundingBoxes) { + // Put in a little bit of wiggle room BlockBox.Expand(-EPSILON, -EPSILON, -EPSILON); if (EntBox.DoesIntersect(BlockBox)) @@ -2687,7 +2718,15 @@ bool cPlayer::DoesPlacingBlocksIntersectEntity(const sSetBlockVector & a_Blocks) } return false; } - ); + } Callback(PlacementBoxes); + + // See if any entities in that bounding box collide with anyone + if (!World->ForEachEntityInBox(PlacingBounds, Callback)) + { + return true; + } + + return false; } -- cgit v1.2.3