ClassiCube icon indicating copy to clipboard operation
ClassiCube copied to clipboard

Inconsistent frame times on capped FPS

Open CornerPin opened this issue 1 year ago • 2 comments

When setting FPS mode to something other than LimitNone and LimitVSync, frame times become inconsistent, resulting in noticeable stutter as if I'm playing at lower FPS. Same thing happens when I set my monitor's refresh rate to 60 Hz, although it's less noticeable. I tried this with D3D9, D3D11, and OpenGL backends on Windows 10 and the results are the same.

  • LimitVSync vsync
  • Limit144FPS 144
  • Limit60FPS 60
  • Limit30FPS 30

It's especially noticeable with Limit144FPS as most of the time frame times are way lower than they are supposed to be. My theory is that the game tries to render as much frames as it can until it hits the cap and waits until it can render more, although I haven't looked at how frame cap is implemented and this might be incorrect.

CornerPin avatar Oct 23 '24 00:10 CornerPin

The handling of explicit FPS modes is done in LimitFPS in Game.c

Essentially, at the end of each frame it checks to see if the elapsed time is less than the target frame time. (I.e. if the game is running too fast) If so, it sleeps the game thread to consume the difference

However, sleep duration is usually inaccurate and so the game can sleep for longer than requested - the game does try to compensate for this though. But the individual frame pacing probably isn't great.

UnknownShadow200 avatar Oct 23 '24 08:10 UnknownShadow200

Especially on Windows where other apps can affect the global timer resolution - see https://github.com/ClassiCube/ClassiCube/issues/726#issuecomment-703948409

ClassiCube doesn't try to alter the global timer resolution

UnknownShadow200 avatar Oct 23 '24 08:10 UnknownShadow200