0

So in monogame, in your Game1 class you can write something like this:

public Game1()
{
    IsFixedTimeStep = true;
    TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 16);
}

That sets the target time to 16 ms which means the frame rate will try to be 62.5 fps. (1000/16 = 62.5)

However, now I'm using C++ with raylib and there are various options that are rather complicated. But the gist of it is, you have three options. 1, use vsync. 2, use sleep. 3, the worst thing imaginable...spinlock your CPU to 100% because it's in an infinite loop that constantly checks the time to see if it's been 16 ms since the last update or draw.

The problem with sleep is, it's not that accurate. The OS gets to decide when to context switch processes and it will not wake up the process at the right time, so you could overshoot your sleep by a lot.

The problem with vsync is, different ppl have different monitor refresh rates. And some hardware does not support it at all.

The problem with spinlock CPU...constantly using 100% is dumb and wasteful.

Anyway, I am not aware of any general 4th option, so I would like to ask here, how does Monogame do it?

DrZ214
  • 348
  • 2
  • 12
  • 1
    Have you considered using VSYNC/conservative sleeps in conjunction with a fixed timestep to ensure consistent game behaviour regardless of rendering framerate? – DMGregory Jul 14 '23 at 02:12
  • Yes, tho i've never heard vsync described as a "conservative sleep". Ideally what i want to do is have a constant update rate of 60 fps, but the draw rate can be whatever it wants. My default is to use vsync but let the user choose a different graphics mode. I thought i might have to use 2 threads to achieve this, until i found https://gamesfromwithin.com/casey-and-the-clearly-deterministic-contraptions which explains it perfectly. However my Q still stands as is, i'd really like to know what method Monogame uses under the hood. – DrZ214 Jul 14 '23 at 03:59
  • Simply look at the source code for MonoGame. And the actual timing is 16.666667 ms. And is vsync'd by default. – agone Jul 16 '23 at 03:42

0 Answers0