fix(network): correct LAN frame pacing unit mismatch on Linux#113
Merged
Conversation
Network::timeForNewFrame() used microseconds for timestamps but the configured counter frequency (m_perfCountFreq) was set to 1000, making frameDelay compute orders of magnitude too small on Linux. Fix: set m_perfCountFreq = 1000000000 (nanoseconds per second) to match the CLOCK_MONOTONIC nanosecond domain, and update both stall-check and frame-pacing clock_gettime conversions from microseconds to nanoseconds. Without this fix, LAN games on Linux advanced at roughly 1000x the intended 30 FPS logic rate, causing computer players to annihilate the human player in seconds. Fixes #97
Both sessions dated 2026-04-27 preserved: - SDL fullscreen macOS backbuffer sizing (from main) - LAN network pacing time unit consistency (from fix/issue-97-main-origin)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LAN matches on Linux (and likely macOS) ran at an absurdly high speed — computer players would annihilate the human player in seconds — because the network frame pacing code used inconsistent time units.
Root Cause
Network::init()on Linux setm_perfCountFreq = 1000, implying microseconds. However,Network::timeForNewFrame()and the stall-check inNetwork::update()both convertedclock_gettime(CLOCK_MONOTONIC)timestamps to microseconds and compared them tom_nextFrameTime, which accumulatesm_perfCountFreq / m_frameRateper frame.The mismatch produced a
frameDelayof1000 / 30 = 33(units) while the actual elapsed time was in the nanosecond range, meaning the "time for a new frame" condition was met on virtually every call. Result: logic ticks ran ~1 000 000x too fast.The
FrameRateLimitused by singleplayer already usesm_freq = 1000000000with nanosecond timestamps, which is why singleplayer was unaffected.Fix
Three one-line changes in
Core/GameEngine/Source/GameNetwork/Network.cpp:m_perfCountFreq = 1000000000;— match CLOCK_MONOTONIC nanosecond domain.static_cast<int64_t>(ts.tv_sec) * 1000000000 + ts.tv_nsecWindows path (
QueryPerformanceCounter/QueryPerformanceFrequency) is untouched.Testing
macos-vulkanpreset) compiles successfully with no new errors.References
Closes #97