From a98200bb4c1edb2c982577fb01b30075665ab488 Mon Sep 17 00:00:00 2001 From: lhofhansl Date: Sun, 10 Dec 2023 10:12:37 -0800 Subject: [PATCH] Avoid movement jitter (#13093) This allows the client and server to agree on the position of objects and attached players even when there is lag. --- src/client/client.cpp | 4 ++-- src/collision.cpp | 6 +++--- src/constants.h | 7 +++++++ src/server.cpp | 4 ++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index c17fa2ab9..a49578ae0 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -393,8 +393,8 @@ void Client::connect(Address address, bool is_local_server) void Client::step(float dtime) { // Limit a bit - if (dtime > 2.0) - dtime = 2.0; + if (dtime > DTIME_LIMIT) + dtime = DTIME_LIMIT; m_animation_time += dtime; if(m_animation_time > 60.0) diff --git a/src/collision.cpp b/src/collision.cpp index 0649b5ced..0814791ed 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -241,13 +241,13 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, /* Calculate new velocity */ - if (dtime > 0.5f) { + if (dtime > DTIME_LIMIT) { if (!time_notification_done) { time_notification_done = true; - infostream << "collisionMoveSimple: maximum step interval exceeded," + warningstream << "collisionMoveSimple: maximum step interval exceeded," " lost movement details!"< 2.0) - dtime = 2.0; + if (dtime > DTIME_LIMIT) + dtime = DTIME_LIMIT; { MutexAutoLock lock(m_step_dtime_mutex); m_step_dtime += dtime;