Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clamp teleportation position #4203

Merged
merged 5 commits into from Mar 20, 2020
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/Entities/Entity.cpp
Expand Up @@ -2203,8 +2203,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