Skip to content

Commit

Permalink
Automatic best-sleep time for rendering thread
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Settimi committed Jun 11, 2024
1 parent 04fb4c5 commit 0b4fe1e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion LaserGRBL/UserControls/GrblPanel3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ private void DrawScene()
}
}
RenderTime.EnqueueNewSample(crono.ElapsedTime.TotalMilliseconds);


TH.SleepTime = BestSleep(RenderTime.Avg, 10, 100, 10, 50);
// call control invalidate
Invalidate();

Expand All @@ -329,6 +330,10 @@ private void DrawScene()
}
}

private static int BestSleep(double renderTime, double minRender, double maxRender, double minSleep, double maxSleep)
{
return (int) Math.Max(minSleep, Math.Min(maxSleep, (renderTime - minRender) * (maxSleep - minSleep) / (maxRender - minRender) + minSleep));
}

private void SetWorldPosition(double left, double right, double bottom, double top)
{
Expand Down

0 comments on commit 0b4fe1e

Please sign in to comment.