diff --git a/LaserGRBL/UserControls/GrblPanel3D.cs b/LaserGRBL/UserControls/GrblPanel3D.cs index 08101877..d720df02 100644 --- a/LaserGRBL/UserControls/GrblPanel3D.cs +++ b/LaserGRBL/UserControls/GrblPanel3D.cs @@ -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(); @@ -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) {