Skip to content

fix(network): correct LAN frame pacing unit mismatch on Linux#113

Merged
fbraz3 merged 2 commits into
mainfrom
fix/issue-97-main-origin
Apr 28, 2026
Merged

fix(network): correct LAN frame pacing unit mismatch on Linux#113
fbraz3 merged 2 commits into
mainfrom
fix/issue-97-main-origin

Conversation

@fbraz3

@fbraz3 fbraz3 commented Apr 27, 2026

Copy link
Copy Markdown
Owner

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 set m_perfCountFreq = 1000, implying microseconds. However, Network::timeForNewFrame() and the stall-check in Network::update() both converted clock_gettime(CLOCK_MONOTONIC) timestamps to microseconds and compared them to m_nextFrameTime, which accumulates m_perfCountFreq / m_frameRate per frame.

The mismatch produced a frameDelay of 1000 / 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 FrameRateLimit used by singleplayer already uses m_freq = 1000000000 with nanosecond timestamps, which is why singleplayer was unaffected.

Fix

Three one-line changes in Core/GameEngine/Source/GameNetwork/Network.cpp:

  1. m_perfCountFreq = 1000000000; — match CLOCK_MONOTONIC nanosecond domain.
  2. Stall-check timestamp: static_cast<int64_t>(ts.tv_sec) * 1000000000 + ts.tv_nsec
  3. Frame-pacing timestamp: same conversion.

Windows path (QueryPerformanceCounter / QueryPerformanceFrequency) is untouched.

Testing

  • macOS build (macos-vulkan preset) compiles successfully with no new errors.
  • Linux LAN runtime validation required: start a LAN game with any number of AI players and confirm the game runs at normal speed (~30 FPS logic).

References

Closes #97

fbraz3 added 2 commits April 27, 2026 19:48
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)
@fbraz3 fbraz3 merged commit 8a46b9b into main Apr 28, 2026
10 checks passed
@fbraz3 fbraz3 deleted the fix/issue-97-main-origin branch April 28, 2026 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Linux] LAN game runs at absurb framerate

1 participant