Commits

André Schnabel committed abc7c93

Tweaked loop

Comments (0)

Files changed (2)

Platforms/Desktop/DesktopBasecode.cs

 		private long oldTicks;
 		private long oldTicks2;
 		private State state;
+		private readonly bool onWindows;
+		private readonly bool onMac;
+		private readonly bool onLinux;
 
 		#region Video performance modifiers
-		private const double MaxFps = 90.0;
+		private const double MaxFps = 60.0;
 		private const bool LimitFps = true;
 		private const bool ShowFps = true;
 		private const bool VerticalSync = false;
 			Title = config.Caption;
 
 			MouseLeave += OnMouseLeave;
+
+			onWindows = Environment.OSVersion.Platform == PlatformID.Win32NT;
+			onLinux = Environment.OSVersion.Platform == PlatformID.Unix && !Utils.IsRunningOnMac();
+			onMac = Environment.OSVersion.Platform == PlatformID.Unix && Utils.IsRunningOnMac();
 		}
 
 		private void OnMouseLeave(object sender, EventArgs eventArgs) {
 				state = (State) constructor.Invoke(new object[] {this});
 			}
 
-			if(Environment.OSVersion.Platform != PlatformID.Unix || Utils.IsRunningOnMac())
+			if(onWindows || onMac)
 				RegisterMouseHandlers();
 		}
 
 				OnMouseLeave(null);
 			}
 
-			// Linux case
-			if(Environment.OSVersion.Platform == PlatformID.Unix && !Utils.IsRunningOnMac()) {
+			if(onLinux) {
 				MouseState mstate = OpenTK.Input.Mouse.GetState();
 				mouseX = Mouse.X;
 				mouseY = Mouse.Y;
 				fpsCounter.Tick();
 
 			// Enforce maximum frames per second envelope
-			if(LimitFps) {
+			if(!onWindows && LimitFps) {
 				delta = Utils.GetTicks() - lastTicks;
 				const long targetDelta = (long) (1000.0f/MaxFps);
 				if(delta < targetDelta)
 		/// Starts main game loop.
 		/// </summary>
 		public void GameLoop() {
-			/*if(LimitFps) { // Unfortunately this seems buggy on OS X and Linux
-				Run (MaxFps, MaxFps);
-			} else {*/
-
-			Run();
+			// Unfortunately this seems buggy on OS X and Linux
+			if(onWindows && LimitFps) {
+				Run(MaxFps, MaxFps);
+			}
+			else {
+				Run();
+			}
 		}
 	}
 }

Utilities/Utils.cs

 using System.Diagnostics;
 using System.Globalization;
 using System.Runtime.InteropServices;
-
-
 #if !MOBILE
 using System.Runtime.InteropServices;
 using OpenTK.Graphics.OpenGL;
 			}
 			return false;
 		}
+
+		#region Measure CPU/Memory
+#if WINDOWS
+		private static readonly PerformanceCounter CpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
+		private static readonly PerformanceCounter MemCounter = new PerformanceCounter("Memory", "Available MBytes");
+
+		public static float GetCpuUsage() {
+			return CpuCounter.NextValue();
+		}
+
+		public static float GetAvailableMemory() {
+			return MemCounter.NextValue();
+		}
+#endif
+		#endregion
 	}
 }