From e225b7f8262df48ad4d7094bc295add3007b0649 Mon Sep 17 00:00:00 2001 From: peterbell10 Date: Mon, 11 Sep 2017 22:20:49 +0100 Subject: Replace ItemCallbacks with lambdas (#3993) --- src/Entities/Floater.cpp | 45 ++++++++------------------------------------- 1 file changed, 8 insertions(+), 37 deletions(-) (limited to 'src/Entities/Floater.cpp') diff --git a/src/Entities/Floater.cpp b/src/Entities/Floater.cpp index eeaa6cf3d..de5824068 100644 --- a/src/Entities/Floater.cpp +++ b/src/Entities/Floater.cpp @@ -13,8 +13,7 @@ //////////////////////////////////////////////////////////////////////////////// // cFloaterEntityCollisionCallback -class cFloaterEntityCollisionCallback : - public cEntityCallback +class cFloaterEntityCollisionCallback { public: cFloaterEntityCollisionCallback(cFloater * a_Floater, const Vector3d & a_Pos, const Vector3d & a_NextPos) : @@ -25,14 +24,14 @@ public: m_HitEntity(nullptr) { } - virtual bool Item(cEntity * a_Entity) override + bool operator () (cEntity & a_Entity) { - if (!a_Entity->IsMob()) // Floaters can only pull mobs not other entities. + if (!a_Entity.IsMob()) // Floaters can only pull mobs not other entities. { return false; } - cBoundingBox EntBox(a_Entity->GetPosition(), a_Entity->GetWidth() / 2, a_Entity->GetHeight()); + cBoundingBox EntBox(a_Entity.GetPosition(), a_Entity.GetWidth() / 2, a_Entity.GetHeight()); double LineCoeff; eBlockFace Face; @@ -47,7 +46,7 @@ public: { // The entity is closer than anything we've stored so far, replace it as the potential victim m_MinCoeff = LineCoeff; - m_HitEntity = a_Entity; + m_HitEntity = &a_Entity; } // Don't break the enumeration, we want all the entities @@ -75,32 +74,6 @@ protected: -//////////////////////////////////////////////////////////////////////////////// -// cFloaterCheckEntityExist -class cFloaterCheckEntityExist : - public cEntityCallback -{ -public: - cFloaterCheckEntityExist(void) : - m_EntityExists(false) - { - } - - bool Item(cEntity * a_Entity) override - { - m_EntityExists = true; - return false; - } - - bool DoesExist(void) const { return m_EntityExists; } -protected: - bool m_EntityExists; -} ; - - - - - cFloater::cFloater(double a_X, double a_Y, double a_Z, Vector3d a_Speed, UInt32 a_PlayerID, int a_CountDownTime) : cEntity(etFloater, a_X, a_Y, a_Z, 0.2, 0.2), m_BitePos(Vector3d(a_X, a_Y, a_Z)), @@ -200,18 +173,16 @@ void cFloater::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) } } - cFloaterCheckEntityExist EntityCallback; - m_World->DoWithEntityByID(m_PlayerID, EntityCallback); - if (!EntityCallback.DoesExist()) // The owner doesn't exist anymore. Destroy the floater entity. + if (!m_World->DoWithEntityByID(m_PlayerID, [](cEntity &) { return true; })) // The owner doesn't exist anymore. Destroy the floater entity. { Destroy(true); } if (m_AttachedMobID != cEntity::INVALID_ID) { - m_World->DoWithEntityByID(m_AttachedMobID, EntityCallback); // The mob the floater was attached to doesn't exist anymore. - if (!EntityCallback.DoesExist()) + if (!m_World->DoWithEntityByID(m_AttachedMobID, [](cEntity &) { return true; })) { + // The mob the floater was attached to doesn't exist anymore. m_AttachedMobID = cEntity::INVALID_ID; } } -- cgit v1.2.3