Skip to content

Commit

Permalink
Avoid movement jitter (#13093)
Browse files Browse the repository at this point in the history
This allows the client and server to agree on the position of objects and attached players even when there is lag.
  • Loading branch information
lhofhansl committed Dec 10, 2023
1 parent 55fafb7 commit a98200b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/client/client.cpp
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/collision.cpp
Expand Up @@ -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!"<<std::endl;
}
dtime = 0.5f;
dtime = DTIME_LIMIT;
} else {
time_notification_done = false;
}
Expand Down
7 changes: 7 additions & 0 deletions src/constants.h
Expand Up @@ -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
#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
*/
Expand Down
4 changes: 2 additions & 2 deletions src/server.cpp
Expand Up @@ -577,8 +577,8 @@ void Server::stop()
void Server::step(float dtime)
{
// Limit a bit
if (dtime > 2.0)
dtime = 2.0;
if (dtime > DTIME_LIMIT)
dtime = DTIME_LIMIT;
{
MutexAutoLock lock(m_step_dtime_mutex);
m_step_dtime += dtime;
Expand Down

0 comments on commit a98200b

Please sign in to comment.