/// <summary> /// Dispose resources /// </summary> /// <param name="disposing">Free managed resources</param> protected virtual void Dispose(bool disposing) { if (disposing) { //Remove scene reference this.nextScene = null; if (this.scenes != null) { for (int i = 0; i < this.scenes.Count; i++) { this.scenes[i]?.Dispose(); } this.scenes.Clear(); this.scenes = null; } DrawerPool.DisposeResources(); FontMap.ClearCache(); Input?.Dispose(); Input = null; Form?.Dispose(); Form = null; ResourceManager?.Dispose(); ResourceManager = null; Graphics?.Dispose(); Graphics = null; } }
/// <summary> /// Constructor /// </summary> /// <param name="name">Name, for the game form</param> /// <param name="screenWidth">Window width</param> /// <param name="screenHeight">Window height</param> /// <param name="fullScreen">Full screen window</param> /// <param name="refreshRate">Refresh rate</param> /// <param name="multiSampling">Enable multi-sampling</param> public Game(string name, bool fullScreen = true, int screenWidth = 0, int screenHeight = 0, bool vsyncEnabled = true, int refreshRate = 0, int multiSampling = 0) { this.Name = name; this.GameTime = new GameTime(); this.ResourceManager = new GameResourceManager(this); this.CPUStats = new PerformanceCounter("Processor", "% Processor Time", "_Total"); #region Form if (screenWidth == 0 || screenHeight == 0) { var mode = GetDesktopMode(); screenWidth = mode.DesktopCoordinates.Right - mode.DesktopCoordinates.Left; screenHeight = mode.DesktopCoordinates.Bottom - mode.DesktopCoordinates.Top; } this.Form = new EngineForm(name, screenWidth, screenHeight, fullScreen); this.Form.UserResized += (sender, eventArgs) => { if (this.Graphics != null) { this.Graphics.PrepareDevice(this.Form.RenderWidth, this.Form.RenderHeight, true); } }; #endregion this.Input = new Input(this.Form); this.Graphics = new Graphics(this.Form, vsyncEnabled, refreshRate, multiSampling); DrawerPool.Initialize(this.Graphics); }