we're working on an official mechanism in #1599 in response to your feedback (thank you!), but you c
we're working on an official mechanism in #1599 in response to your feedback (thank you!), but you could try:
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();
}
}
window.DoEvents();
window.Reset();nanosleep is just a busy loop with a pause instruction. we had tried to make our own cross-platform high-resolution sleep in the past, but it only worked on windows, so the pause method seemed good enough for me seeing as macOS uses it and their IO seems to be pretty CPU friendlynanosleep
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;nanosleepnanosleepnanosleeppausepauseThread.SleepSpinWaitconst double loopsPerSecond = 500;