[Solved] Jittery, Choppy Frame Movement for 2D game

Yes this is caused by the timer resolution on different hardware or different os or different builds of a os even. Vertical Retrace timing just exacerbates the problem on some systems.

The mg timing and or timing resolution code is not as robust, i suppose as it should be, but this is a ongoing thing that people keep coming back to from time to time and taking a shot at.

Here is a huge discussion that had occured on the forum over some time with numerous people digging into it.

Physically vsync represents a hardware interrupt deep down (for a idealogical two way street read write signal design between the monitor and the video card), translated thru the OS (on Windows this is a IRQ in software and a pin physically). These calls typically pause threads including the game thread but this pretty fast usually 1 ms or less.

So your video card dumps the Backbuffer to the screen typically as fast as it can (when you get to base.draw) when not using vsync. The monitor itself has a set limit of how fast it can physically completely update the image on the screen, from top to bottom left to right.
When it completes a full draw there is a monitor refresh signal sent to the os and a very tiny pause typically about 4 milliseconds give or take were the monitor is preping for the next draw of its own video buffer. This is the vsync signal which a card can wait for to burst out another frame of data from its own back buffer to the monitors buffer before the monitor starts its next draw.
What this implicity means, is that the video card and in turn the base.draws render call, will try to time themselves to wait for this signal or line up with it, which can take a little extra time in a games draw loop.

However if a game timer misses this signal (say because it is oversleeping), it can throw off the timing.

Over time this can cause you to lose a frame or get a double drawn frame ect, thus triggering is running slowly or force extra wait time, which can look like a stutter, but as i said this is made harder to deal with because different systems can use or fallback to different resolutions timers.
Its (pretty hairy stuff) basically mostly controlled by the os between hardware and software.

So for now.

Turning off vsync speeds up the draws to maximum meaning more cpu load and allows a low probability of screen tearing (not sure this is really a thing at such high monitor refresh speeds anymore), At the same time this stabilizes the monogame timer a bit which is a little off which can be more important.

You can test what i mean (by a little off) by setting the fixed time step on and set your fixed target elapsed time to a very high number (try with a lower number too) then just count the updates and draws they should match but they probably wont by a considerable amount.

One other take away is that your updates if set for 120 per second may not actually be 120 in a second which could i suppose be a concern for network syncing.

4 Likes