Skip to content

Commit

Permalink
Clamp teleportation position (#4203)
Browse files Browse the repository at this point in the history
  • Loading branch information
stone3311 committed Mar 20, 2020
1 parent 7d8f8c9 commit 0a1cfda
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Entities/Entity.cpp
Expand Up @@ -2239,8 +2239,16 @@ Vector3d cEntity::GetLookVector(void) const
// Set position
void cEntity::SetPosition(const Vector3d & a_Position)
{
// Clamp the positions to exactly representable single-precision floating point values
// This is necessary to avoid rounding errors in the noise generator and overflows in the chunk loader
const double MaxFloat = std::pow(2, std::numeric_limits<float>().digits);

const double ClampedPosX = Clamp(a_Position.x, -MaxFloat, MaxFloat);
const double ClampedPosY = Clamp(a_Position.y, -MaxFloat, MaxFloat);
const double ClampedPosZ = Clamp(a_Position.z, -MaxFloat, MaxFloat);

m_LastPosition = m_Position;
m_Position = a_Position;
m_Position = {ClampedPosX, ClampedPosY, ClampedPosZ};
}


Expand Down

0 comments on commit 0a1cfda

Please sign in to comment.