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/ProjectileEntity.cpp | 40 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 24 deletions(-) (limited to 'src/Entities/ProjectileEntity.cpp') diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 1017f954a..0649e5b95 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -126,8 +126,7 @@ protected: //////////////////////////////////////////////////////////////////////////////// // cProjectileEntityCollisionCallback: -class cProjectileEntityCollisionCallback : - public cEntityCallback +class cProjectileEntityCollisionCallback { public: cProjectileEntityCollisionCallback(cProjectileEntity * a_Projectile, const Vector3d & a_Pos, const Vector3d & a_NextPos) : @@ -140,11 +139,11 @@ public: } - virtual bool Item(cEntity * a_Entity) override + bool operator () (cEntity & a_Entity) { if ( - (a_Entity == m_Projectile) || // Do not check collisions with self - (a_Entity->GetUniqueID() == m_Projectile->GetCreatorUniqueID()) // Do not check whoever shot the projectile + (&a_Entity == m_Projectile) || // Do not check collisions with self + (a_Entity.GetUniqueID() == m_Projectile->GetCreatorUniqueID()) // Do not check whoever shot the projectile ) { // Don't check creator only for the first 5 ticks so that projectiles can collide with the creator @@ -154,7 +153,7 @@ public: } } - cBoundingBox EntBox(a_Entity->GetPosition(), a_Entity->GetWidth() / 2, a_Entity->GetHeight()); + cBoundingBox EntBox(a_Entity.GetPosition(), a_Entity.GetWidth() / 2, a_Entity.GetHeight()); // Instead of colliding the bounding box with another bounding box in motion, we collide an enlarged bounding box with a hairline. // The results should be good enough for our purposes @@ -168,20 +167,20 @@ public: } if ( - !a_Entity->IsMob() && - !a_Entity->IsMinecart() && + !a_Entity.IsMob() && + !a_Entity.IsMinecart() && ( - !a_Entity->IsPlayer() || - static_cast(a_Entity)->IsGameModeSpectator() + !a_Entity.IsPlayer() || + static_cast(a_Entity).IsGameModeSpectator() ) && - !a_Entity->IsBoat() + !a_Entity.IsBoat() ) { // Not an entity that interacts with a projectile return false; } - if (cPluginManager::Get()->CallHookProjectileHitEntity(*m_Projectile, *a_Entity)) + if (cPluginManager::Get()->CallHookProjectileHitEntity(*m_Projectile, a_Entity)) { // A plugin disagreed. return false; @@ -191,7 +190,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 @@ -327,20 +326,13 @@ void cProjectileEntity::OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos) // If we were created by a player and we hit a pawn, notify attacking player's wolves if (a_EntityHit.IsPawn() && (GetCreatorName() != "")) { - class cNotifyWolves : public cEntityCallback - { - public: - cPawn * m_EntityHit; - - virtual bool Item(cEntity * a_Hitter) override + auto EntityHit = static_cast(&a_EntityHit); + m_World->DoWithEntityByID(GetCreatorUniqueID(), [=](cEntity & a_Hitter) { - static_cast(a_Hitter)->NotifyNearbyWolves(m_EntityHit, true); + static_cast(a_Hitter).NotifyNearbyWolves(EntityHit, true); return true; } - } Callback; - - Callback.m_EntityHit = static_cast(&a_EntityHit); - m_World->DoWithEntityByID(GetCreatorUniqueID(), Callback); + ); } } -- cgit v1.2.3