From 5eaee560300eb97ac0930f79bede8ee6c2dadbfc Mon Sep 17 00:00:00 2001 From: obligaron Date: Sat, 22 Oct 2022 22:50:57 +0200 Subject: [PATCH] Avoid dramatically speed up in solo multiplayer --- Source/nthread.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Source/nthread.cpp b/Source/nthread.cpp index 189fadb43..0cbb575a9 100644 --- a/Source/nthread.cpp +++ b/Source/nthread.cpp @@ -216,9 +216,23 @@ bool nthread_has_500ms_passed() { int currentTickCount = SDL_GetTicks(); int ticksElapsed = currentTickCount - last_tick; - if (!gbIsMultiplayer && ticksElapsed > gnTickDelay * 10) { - last_tick = currentTickCount; - ticksElapsed = 0; + // Check if we missed multiple game ticks (> 10) + if (ticksElapsed > gnTickDelay * 10) { + bool resetLastTick = true; + if (gbIsMultiplayer) { + for (size_t i = 0; i < Players.size(); i++) { + if ((player_state[i] & PS_CONNECTED) != 0 && i != MyPlayerId) { + // Reset last tick is not allowed when other players are connected, cause the elapsed time is needed to sync the game ticks between the clients + resetLastTick = false; + break; + } + } + } + if (resetLastTick) { + // Reset last tick to avoid caught up of all missed game ticks (game speed is dramatically increased for a short time) + last_tick = currentTickCount; + ticksElapsed = 0; + } } return ticksElapsed >= 0; }