From a4dbb5c58270959884c17d720185da06464fa256 Mon Sep 17 00:00:00 2001 From: peterbell10 Date: Wed, 2 May 2018 08:50:36 +0100 Subject: Prefer static_cast to reinterpret_cast (#4223) * Change reinterpret_cast -> static_cast wherever possible * Remove more unnecessary `const_cast`s. reinterpret_casts should be avoided for the same reason as c-style casts - they don't do any type-checking. reinterpret_cast was mainly being used for down-casting in inheritance hierarchies but static_cast works just as well while also making sure that there is actually an inheritance relationship there. --- src/Entities/Entity.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/Entities/Entity.cpp') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 73749d7a3..d1fdcfd39 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -410,7 +410,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) if ((a_TDI.Attacker != nullptr) && (a_TDI.Attacker->IsPlayer())) { - cPlayer * Player = reinterpret_cast(a_TDI.Attacker); + cPlayer * Player = static_cast(a_TDI.Attacker); Player->GetEquippedItem().GetHandler()->OnEntityAttack(Player, this); @@ -441,7 +441,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) { if (IsMob()) { - cMonster * Monster = reinterpret_cast(this); + cMonster * Monster = static_cast(this); switch (Monster->GetMobType()) { case mtSkeleton: @@ -460,7 +460,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) { if (IsMob()) { - cMonster * Monster = reinterpret_cast(this); + cMonster * Monster = static_cast(this); switch (Monster->GetMobType()) { case mtSpider: @@ -496,7 +496,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) } else if (IsMob() && !IsInWater()) { - cMonster * Monster = reinterpret_cast(this); + cMonster * Monster = static_cast(this); switch (Monster->GetMobType()) { case mtGhast: @@ -871,7 +871,7 @@ void cEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) // Handle cactus damage or destruction: if ( IsMob() || IsPickup() || - (IsPlayer() && !((reinterpret_cast(this))->IsGameModeCreative() || (reinterpret_cast(this))->IsGameModeSpectator())) + (IsPlayer() && !((static_cast(this))->IsGameModeCreative() || (static_cast(this))->IsGameModeSpectator())) ) { DetectCacti(); @@ -1362,7 +1362,7 @@ bool cEntity::DetectPortal() return false; } - if (IsPlayer() && !(reinterpret_cast(this))->IsGameModeCreative() && (m_PortalCooldownData.m_TicksDelayed != 80)) + if (IsPlayer() && !(static_cast(this))->IsGameModeCreative() && (m_PortalCooldownData.m_TicksDelayed != 80)) { // Delay teleportation for four seconds if the entity is a non-creative player m_PortalCooldownData.m_TicksDelayed++; @@ -1385,7 +1385,7 @@ bool cEntity::DetectPortal() if (IsPlayer()) { // Send a respawn packet before world is loaded / generated so the client isn't left in limbo - (reinterpret_cast(this))->GetClientHandle()->SendRespawn(DestionationDim); + (static_cast(this))->GetClientHandle()->SendRespawn(DestionationDim); } Vector3d TargetPos = GetPosition(); @@ -1414,10 +1414,10 @@ bool cEntity::DetectPortal() { if (DestionationDim == dimNether) { - reinterpret_cast(this)->AwardAchievement(achEnterPortal); + static_cast(this)->AwardAchievement(achEnterPortal); } - reinterpret_cast(this)->GetClientHandle()->SendRespawn(DestionationDim); + static_cast(this)->GetClientHandle()->SendRespawn(DestionationDim); } Vector3d TargetPos = GetPosition(); @@ -1454,7 +1454,7 @@ bool cEntity::DetectPortal() if (IsPlayer()) { - cPlayer * Player = reinterpret_cast(this); + cPlayer * Player = static_cast(this); if (Player->GetBedWorld() == DestinationWorld) { Player->TeleportToCoords(Player->GetLastBedPos().x, Player->GetLastBedPos().y, Player->GetLastBedPos().z); @@ -1487,9 +1487,9 @@ bool cEntity::DetectPortal() { if (DestionationDim == dimEnd) { - reinterpret_cast(this)->AwardAchievement(achEnterTheEnd); + static_cast(this)->AwardAchievement(achEnterTheEnd); } - reinterpret_cast(this)->GetClientHandle()->SendRespawn(DestionationDim); + static_cast(this)->GetClientHandle()->SendRespawn(DestionationDim); } cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedEndWorldName()); @@ -1717,7 +1717,7 @@ void cEntity::HandleAir(void) if (RespirationLevel > 0) { - reinterpret_cast(this)->AddEntityEffect(cEntityEffect::effNightVision, 200, 5, 0); + static_cast(this)->AddEntityEffect(cEntityEffect::effNightVision, 200, 5, 0); } if (m_AirLevel <= 0) -- cgit v1.2.3