From 3eccb898212ba0c254b8c7fcd8420f89e09a8d2b Mon Sep 17 00:00:00 2001 From: "Stefanos A." Date: Mon, 13 Jan 2014 11:36:56 +0100 Subject: [PATCH] [OpenTK] Remove Thread.Sleep() from loop timing --- Source/OpenTK/GameWindow.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Source/OpenTK/GameWindow.cs b/Source/OpenTK/GameWindow.cs index 4a9cb092..cc1e3e7c 100644 --- a/Source/OpenTK/GameWindow.cs +++ b/Source/OpenTK/GameWindow.cs @@ -431,10 +431,15 @@ namespace OpenTK } } + double ClampElapsed(double elapsed) + { + return MathHelper.Clamp(elapsed, 0.0, 1.0); + } + void DispatchUpdateAndRenderFrame(object sender, EventArgs e) { double timestamp = watch.Elapsed.TotalSeconds; - double elapsed = MathHelper.Clamp(timestamp - update_timestamp, 0.0, 1.0); + double elapsed = ClampElapsed(timestamp - update_timestamp); // Calculate how many update events we need to execute in order to reach // our desired TargetUpdateFrequency @@ -450,17 +455,15 @@ namespace OpenTK RaiseUpdateFrame(elapsed, ref timestamp); --update_count; } - elapsed = MathHelper.Clamp(timestamp - update_timestamp, 0.0, 1.0); + elapsed = ClampElapsed(timestamp - update_timestamp); } //timestamp = watch.Elapsed.TotalSeconds; - elapsed = MathHelper.Clamp(timestamp - render_timestamp, 0.0, 1.0); + elapsed = ClampElapsed(timestamp - render_timestamp); if (elapsed > 0 && elapsed >= TargetRenderPeriod) { RaiseRenderFrame(elapsed, ref timestamp); } - - Thread.Sleep(1); } void RaiseUpdateFrame(double elapsed, ref double timestamp)