I'm a little bit confused about the way game engines handle frame rate. Correct me if I'm wrong:
By my assumptions, usually we have a frame rate which graphical API runs by it and a frame rate called fixed frame rate which other parties like physics, network etc. run by it.
I know with v-sync on, the frame rate for graphical API would be the display device refresh rate which is usually 60hz in nowadays monitors, and with v-sync off graphical API wouldn't wait for display device to draw previous frame completely and it constantly sends the new frame. So, if I turn v-sync on and change refresh rate to something I like, then frame rate for graphical API would be locked by that rate and if I turn v-sync off, then frame rate for graphical API would be as fast as possible.
If my previous assumptions are correct, then why have we for example a
Time.captureFramerate
which locks the render frame rate and aResolution.refreshRate
with the same intention in an engine like Unity3D?And, what does it mean when game developers say we locked the frame rate at 30 or 60 frames per second? Does this mean they leave v-sync on and set refresh rate to 30 or 60 and user is not able to alter v-sync at runtime?
If we are to limit the main loop which render operation runs under it, is this the way?
while (main_loop)
{
while (fixed_loop)
{
// Stuff
}
// Lock main loop to 30 fps
if (render_time >= 1 / 30)
{
render_time -= delta;
Sleep(1);
continue;
}
render();
}
if
to lock render rate in main loop? Is this the proper way? \$\endgroup\$