Patch v0.8.5g
Howdy everyone,
Over the last couple days I've been looking into why Metropolis 1998 utilizes my CPU at 100% despite the game using only a fraction of a frame in the CPU profiler.
Turns out it's:
- An NVIDIA graphics driver bug when Thread Optimization is active (which it is by default) and the game is windowed (not full screen).
- An NVIDIA graphics driver bug when the game is running full screen (whether or not Thread Optimization is active)
Note that VSYNC is active in both scenarios
Thread optimization is good for larger, 3D games; but it causes issues for smaller games and older version of OpenGL (double whammy for Metropolis 1998)
What's happening behind the scenes is that when there's leftover time before the next frame can begin executing, the CPU (thread) is instructed to wait. There's two types of waiting: sleep and busy-wait. The trade off between the two is:
- Sleep wait does not utilize the CPU thread. The fan stay silent. However, it is slower to grab/reactivate.
- Busy wait utilizes 100% of the CPU thread. The fans stay on full power. It's faster to reactivate.
I managed to figure out a way around both issues.
For window mode: I downloaded the NVIDIA SDK and now Metropolis 1998 will automatically create a NVIDIA profile that explicitly disables Thread Optimization just for my game. If you don't have an NVIDIA GPU, nothing will happen.
For full screen mode: Since Threaded Optimization on or off made no difference, instead what I'm doing is calculating how much time there is before the next frame can fire off and explicitly calling sleep() on the active CPU thread, right before everything is drawn to the screen. I subtract 2 milliseconds from sleep period so there's some buffer. I tried subtracting just 1 millisecond but that causes occasional and barely perceptible issues.
[Just be sure to reset the timer after display() is called, and dont call sleep() if the frame falls below refreshRate - buffer]
My CPU fans being at full power annoyed the heck out of me, and Im so glad I figured out a way to play my game in peace.
Also, it looks like I accidentally uploaded an experimental feature where the outdoor lighting and breeze animations are set to 12 FPS. Oops! I'll fix it in the next patch.
