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.
This commit is contained in:
lhofhansl 2023-12-10 10:12:37 -08:00 committed by GitHub
parent 55fafb7d25
commit a98200bb4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 7 deletions

View File

@ -393,8 +393,8 @@ void Client::connect(Address address, bool is_local_server)
void Client::step(float dtime) void Client::step(float dtime)
{ {
// Limit a bit // Limit a bit
if (dtime > 2.0) if (dtime > DTIME_LIMIT)
dtime = 2.0; dtime = DTIME_LIMIT;
m_animation_time += dtime; m_animation_time += dtime;
if(m_animation_time > 60.0) if(m_animation_time > 60.0)

View File

@ -241,13 +241,13 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
/* /*
Calculate new velocity Calculate new velocity
*/ */
if (dtime > 0.5f) { if (dtime > DTIME_LIMIT) {
if (!time_notification_done) { if (!time_notification_done) {
time_notification_done = true; time_notification_done = true;
infostream << "collisionMoveSimple: maximum step interval exceeded," warningstream << "collisionMoveSimple: maximum step interval exceeded,"
" lost movement details!"<<std::endl; " lost movement details!"<<std::endl;
} }
dtime = 0.5f; dtime = DTIME_LIMIT;
} else { } else {
time_notification_done = false; time_notification_done = false;
} }

View File

@ -56,6 +56,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
// Override for the previous one when distance of block is very low // Override for the previous one when distance of block is very low
#define BLOCK_SEND_DISABLE_LIMITS_MAX_D 1 #define BLOCK_SEND_DISABLE_LIMITS_MAX_D 1
/*
Client/Server
*/
// Limit maximum dtime in client/server step(...) and for collision detection
#define DTIME_LIMIT 2.5f
/* /*
Map-related things Map-related things
*/ */

View File

@ -577,8 +577,8 @@ void Server::stop()
void Server::step(float dtime) void Server::step(float dtime)
{ {
// Limit a bit // Limit a bit
if (dtime > 2.0) if (dtime > DTIME_LIMIT)
dtime = 2.0; dtime = DTIME_LIMIT;
{ {
MutexAutoLock lock(m_step_dtime_mutex); MutexAutoLock lock(m_step_dtime_mutex);
m_step_dtime += dtime; m_step_dtime += dtime;