/// <summary>Occurs when the form is disposing.</summary> /// <param name="disposing">Whether Dispose was invoked by managed code.</param> private void FormDisposing(bool disposing) { for(int i = 0; i < _dx9Resources.Count; i++) { try { _dx9Resources[i].Dispose(); } catch { } } _dx9Resources.Clear(); for(int i = 0; i < _disposableResources.Count; i++) { try { _disposableResources[i].Dispose(); } catch { } } _disposableResources.Clear(); _input = null; _direct3D = null; _device = null; }
/// <summary>Initialises the game.</summary> public void InitialiseGame() { _sys = new SlimDXSys(Program.CommandLineArguments); bool windowed = _sys.GameConfig.VideoWindowed; Screen screen = Screen.FromHandle(Handle); int width, height; StartPosition = FormStartPosition.Manual; WindowState = FormWindowState.Normal; if(windowed) { width = _sys.GameConfig.VideoWindowWidth(screen.Bounds.Width); height = _sys.GameConfig.VideoWindowHeight(screen.Bounds.Height); FormBorderStyle = FormBorderStyle.FixedSingle; } else { width = screen.Bounds.Width; height = screen.Bounds.Height; FormBorderStyle = FormBorderStyle.None; } ClientSize = new Size(width, height); if(windowed) { int left, top; if(_sys.GameConfig.VideoWindowCenter) { left = (screen.Bounds.Width - Size.Width) / 2; top = (screen.Bounds.Height - Size.Height) / 2; } else { left = _sys.GameConfig.VideoWindowLeft(screen.Bounds.Right - 32); top = _sys.GameConfig.VideoWindowTop(screen.Bounds.Bottom - 32); } Location = new Point(left, top); } bool vsync = _sys.GameConfig.VideoVSync; InitialiseDirect3D(windowed, vsync); _renderer = new DX9SoftwareRenderer(); _renderer.Initialise(_device, 320, 200); _renderer.UseLinearFiltering = _sys.GameConfig.VideoFilter; AddResource(_renderer); _stopwatch = new Stopwatch(); _hovertank = new Hovertank(_sys); _hovertank.StateInitialise(); _disposableResources.Add(_sys); SoundSystem soundSystem = new SlimDXSoundSystem(this); _sys.InitialiseSound(soundSystem); _disposableResources.Add(soundSystem); // Note: The sound system needs to be disposed after sys _input = new SlimDXInputSystem(this); _sys.InitialiseInput(_input); _disposableResources.Add(_input); _stopwatch.Start(); }