| 215 | } |
| 216 | |
| 217 | bool nthread_has_500ms_passed(bool *drawGame /*= nullptr*/) |
| 218 | { |
| 219 | int currentTickCount = SDL_GetTicks(); |
| 220 | int ticksElapsed = currentTickCount - last_tick; |
| 221 | // Check if we missed multiple game ticks (> 10) |
| 222 | if (ticksElapsed > gnTickDelay * 10) { |
| 223 | bool resetLastTick = true; |
| 224 | if (gbIsMultiplayer) { |
| 225 | for (size_t i = 0; i < Players.size(); i++) { |
| 226 | if ((player_state[i] & PS_CONNECTED) != 0 && i != MyPlayerId) { |
| 227 | // 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 |
| 228 | resetLastTick = false; |
| 229 | break; |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | if (resetLastTick) { |
| 234 | // Reset last tick to avoid catching up with all missed game ticks (game speed is dramatically increased for a short time) |
| 235 | last_tick = currentTickCount; |
| 236 | ticksElapsed = 0; |
| 237 | } |
| 238 | } |
| 239 | if (drawGame != nullptr) { |
| 240 | // Check if we missed a game tick. |
| 241 | // This can happen when we run a low-end device that can't render fast enough (typically 20fps). |
| 242 | // If this happens, try to speed-up the game by skipping the rendering. |
| 243 | // This avoids desyncs and hourglasses when running multiplayer and slowdowns in singleplayer. |
| 244 | *drawGame = ticksElapsed <= gnTickDelay; |
| 245 | } |
| 246 | return ticksElapsed >= 0; |
| 247 | } |
| 248 | |
| 249 | void nthread_UpdateProgressToNextGameTick() |
| 250 | { |
no test coverage detected