@@ -628,6 +628,107 @@ } } + public void RunSimple(int targetFps) + { + RunSimple(targetFps, targetFps); + } + + public void RunSimple(int updatesPerSecond, int framesPerSecond) + { + if (disposed) throw new ObjectDisposedException("GameWindow"); + try + { + TargetUpdateFrequency = updatesPerSecond; + TargetRenderFrequency = framesPerSecond; + + UpdateFrameEventArgs updateArgs = new UpdateFrameEventArgs(); + RenderFrameEventArgs renderArgs = new RenderFrameEventArgs(); + + try + { + OnLoadInternal(EventArgs.Empty); + } + catch (Exception e) + { + Trace.WriteLine(String.Format("OnLoad failed: {0}", e.ToString())); + return; + } + + Debug.Print("Entering main loop."); + hasMainLoop = true; + + Stopwatch stopwatch = new Stopwatch(); + stopwatch.Reset(); + stopwatch.Start(); + int updates = 0; + int frames = 0; + double updateElapsedSeconds = 0; + double renderElapsedSeconds = 0; + + InterleavedScheduler scheduler = new InterleavedScheduler(updatesPerSecond, framesPerSecond); + while (!isExiting) + { + bool shouldUpdate, shouldRender; + double elapsedSeconds = scheduler.Update(out shouldUpdate, out shouldRender); + updateElapsedSeconds += elapsedSeconds; + renderElapsedSeconds += elapsedSeconds; + + ProcessEvents(); + + if (shouldUpdate) + { + updates++; + updateArgs.Time = updateElapsedSeconds; + OnUpdateFrameInternal(updateArgs); + updateElapsedSeconds = 0; + } + + if (shouldRender) + { + frames++; + renderArgs.Time = renderElapsedSeconds; + OnRenderFrameInternal(renderArgs); + renderElapsedSeconds = 0; + } + + double totalSeconds = stopwatch.Elapsed.TotalSeconds; + if (totalSeconds >= 5.0) + { + double ups = updates / totalSeconds; + double fps = frames / totalSeconds; + + Console.WriteLine("Actual UPS={0:0.00}, FPS={1:0.00}", ups, fps); + + updates = 0; + frames = 0; + stopwatch.Reset(); + stopwatch.Start(); + } + + scheduler.Sleep(); + } + } + catch (GameWindowExitException) + { + Debug.WriteLine("GameWindowExitException caught - exiting main loop."); + } + finally + { + Debug.Print("Restoring priority."); + Thread.CurrentThread.Priority = ThreadPriority.Normal; + + OnUnloadInternal(EventArgs.Empty); + + if (Exists) + { + glContext.Dispose(); + glContext = null; + glWindow.DestroyWindow(); + } + while (this.Exists) + this.ProcessEvents(); + } + } #endregion #region public void ProcessEvents()