private void Cleanup() { m_Graphics.Cleanup(); m_Graphics = null; m_Sound.Cleanup(); m_Sound = null; m_Window.Close(); m_Window.Dispose(); m_Window = null; }
/*------------------------------------- * NON-PUBLIC METHODS *-----------------------------------*/ private void Init(IGraphicsMgr graphics, ISoundMgr sound, string title, int width, int height) { m_Window = CreateWindow(title, width, height); graphics.Init(m_Window); sound.Init(); m_Graphics = graphics; m_Sound = sound; }
public void Run(IGraphicsMgr graphics, ISoundMgr sound, string title, int width, int height, Scene scene) { Thread.CurrentThread.Priority = ThreadPriority.AboveNormal; m_Done = false; Init(graphics, sound, title, width, height); EnterScene(scene); var t1 = 0.0; var t2 = 0.0; var stopwatch = Stopwatch.StartNew(); while (!m_Done) { Application.DoEvents(); var dt = stopwatch.Elapsed.TotalSeconds; stopwatch.Restart(); t1 += dt; var done = false; while (!done) { done = true; if (t1 >= INV_UPDATES_PER_SEC) { m_Scene.Update((float)INV_UPDATES_PER_SEC); t1 -= INV_UPDATES_PER_SEC; t2 += INV_UPDATES_PER_SEC; done = false; } if (t2 >= INV_DRAWS_PER_SEC) { Graphics.IsLagging = t1 >= INV_DRAWS_PER_SEC; m_Scene.Draw((float)INV_DRAWS_PER_SEC); t2 -= INV_DRAWS_PER_SEC; done = false; } DispatchMessages(); } if (m_Scene == null) { Exit(); } } while (m_Scene != null) { LeaveScene(); } Cleanup(); }