nanosleep being like 1ms out by just busy waiting for a certain percentage of the loop and sleeping for the restThread.Sleep is simply not accurate enough to be used as a timer like thisSpinWait, which i've found works well, although not at FPS values above 60 the last time I tested
const double loopsPerSecond = 500;nanosleepThread.SleepSpinWaitconst double loopsPerSecond = 500;const double loopsPerSecond = 10000;
Stopwatch loopStopwatch = Stopwatch.StartNew();
window.Initialize();
while (!window.IsClosing)
{
do
{
if (X86Base.IsSupported)
{
X86Base.Pause();
}
}
while (loopStopwatch.Elapsed.TotalSeconds < (1 / loopsPerSecond));
window.DoEvents();
if (!window.IsClosing)
{
window.DoUpdate();
}
if (!window.IsClosing)
{
window.DoRender();
}
+ loopStopwatch.Reset();
}
window.DoEvents();
window.Reset();