From 58a6c01c3b6462b258e2bbf8504a460c0d5c288e Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sat, 26 Nov 2011 16:17:23 +1300 Subject: [PATCH] add framelimiter as per Joseph_Vissarion's patch --- OpenRA.Game/Game.cs | 12 ++++++++++++ OpenRA.Game/GameRules/Settings.cs | 2 ++ 2 files changed, 14 insertions(+) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index e96b7ed0f2..584ba8e0a1 100755 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -326,8 +326,20 @@ namespace OpenRA internal static void Run() { while (!quit) + { + var idealFrameTime = 1.0 / Settings.Graphics.MaxFramerate; + var sw = new Stopwatch(); + Tick( orderManager, viewport ); + if (Settings.Graphics.CapFramerate) + { + var waitTime = idealFrameTime - sw.ElapsedTime(); + if (waitTime > 0) + System.Threading.Thread.Sleep( TimeSpan.FromSeconds(waitTime) ); + } + } + OnQuit(); } diff --git a/OpenRA.Game/GameRules/Settings.cs b/OpenRA.Game/GameRules/Settings.cs index 96bf7c9990..cc16695d1d 100644 --- a/OpenRA.Game/GameRules/Settings.cs +++ b/OpenRA.Game/GameRules/Settings.cs @@ -60,6 +60,8 @@ namespace OpenRA.GameRules public int2 FullscreenSize = new int2(0,0); public int2 WindowedSize = new int2(1024, 768); public bool PixelDouble = false; + public bool CapFramerate = false; + public int MaxFramerate = 60; public int BatchSize = 8192; public int NumTempBuffers = 8;