/// <summary>Initialises the game.</summary>
        public void InitialiseGame()
        {
            _sys = new SharpDXSys(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 System.Drawing.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 SharpDXSoundSystem(this);
            _sys.InitialiseSound(soundSystem);
            _disposableResources.Add(soundSystem); // Note: The sound system needs to be disposed after sys

            _input = new SharpDXInputSystem(this);
            _sys.InitialiseInput(_input);
            _disposableResources.Add(_input);

            _stopwatch.Start();
        }
        /// <summary>Runs the game.</summary>
        public void Run()
        {
            string[] commandLineArguments = Environment.GetCommandLineArgs();

            _sys = new OpenTKSys(commandLineArguments);

            DisplayDevice displayDevice = DisplayDevice.Default;

            bool windowed = _sys.GameConfig.VideoWindowed;
            int width, height;
            if(windowed)
            {
                width = _sys.GameConfig.VideoWindowWidth(displayDevice.Width);
                height = _sys.GameConfig.VideoWindowHeight(displayDevice.Height);
            }
            else
            {
                width = displayDevice.Width;
                height = displayDevice.Height;
            }

            GameWindowFlags gameWindowFlags = (windowed ? GameWindowFlags.FixedWindow : GameWindowFlags.Fullscreen);
            using(_gameWindow = new GameWindow(width, height, GraphicsMode.Default, "Hovertank3DdotNet (OpenTK)", gameWindowFlags))
            {
                _gameWindow.VSync = (_sys.GameConfig.VideoVSync ? VSyncMode.On : VSyncMode.Off);

                if(windowed)
                {
                    int left, top;
                    if(_sys.GameConfig.VideoWindowCenter)
                    {
                        left = (displayDevice.Width - _gameWindow.Width) / 2;
                        top = (displayDevice.Height - _gameWindow.Height) / 2;
                    }
                    else
                    {
                        left = _sys.GameConfig.VideoWindowLeft(displayDevice.Width);
                        top = _sys.GameConfig.VideoWindowTop(displayDevice.Height);
                    }

                    _gameWindow.Location = new Point(left, top);
                }

                _viewportSize = new Size(_gameWindow.Width, _gameWindow.Height);

                _gameWindow.Load += gameWindow_Load;
                _gameWindow.Resize += gameWindow_Resize;
                _gameWindow.UpdateFrame += gameWindow_UpdateFrame;
                _gameWindow.RenderFrame += gameWindow_RenderFrame;
                _gameWindow.Unload += gameWindow_Unload;

                // This can fail if OpenAL isn't installed
                SoundSystem soundSystem = new OpenTKSoundSystem();
                _sys.InitialiseSound(soundSystem);

                _input = new OpenTKInputSystem(_gameWindow);
                _disposableObjects.Add(_input);
                _sys.InitialiseInput(_input);

                _hovertank = new Hovertank(_sys);
                _hovertank.StateInitialise();

                // Dispose sound system after sounds
                _disposableObjects.Add(soundSystem);

                _gameWindow.Run(70.0);
            }
        }
        /// <summary>Creates a new FormGame.</summary>
        public FormGame()
        {
            _sys = new WinFormsSys(Program.CommandLineArguments);

            if(_sys.GameConfig.VideoWindowed)
            {
                Screen screen = Screen.FromHandle(Handle);

                int width = _sys.GameConfig.VideoWindowWidth(screen.Bounds.Width);
                int height = _sys.GameConfig.VideoWindowHeight(screen.Bounds.Height);

                FormBorderStyle = FormBorderStyle.FixedSingle;
                StartPosition = FormStartPosition.Manual;
                WindowState = FormWindowState.Normal;

                ClientSize = new Size(width, height);

                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.Width);
                    top = _sys.GameConfig.VideoWindowTop(screen.Bounds.Height);
                }
                Location = new Point(left, top);
            }
            else
            {
                FormBorderStyle = FormBorderStyle.None;
                StartPosition = FormStartPosition.CenterScreen;
                WindowState = FormWindowState.Maximized;
                MaximizeBox = false;
            }

            InitializeComponent();

            _sys.InitialiseSound(new WinFormsSoundSystem());

            WinFormsInputSystem input = new WinFormsInputSystem(this);
            _sys.InitialiseInput(input);

            BackColor = Color.Black;

            _imageView = new ImageView();
            _imageView.Location = new Point();
            _imageView.Size = ClientSize;
            _imageView.LinearFilter = _sys.GameConfig.VideoFilter;
            Controls.Add(_imageView);

            _hovertank = new Hovertank(_sys);
            _hovertank.StateInitialise();

            backgroundWorker.DoWork += backgroundWorker_DoWork;
            backgroundWorker.ProgressChanged += backgroundWorker_ProgressChanged;
            backgroundWorker.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted;

            backgroundWorker.RunWorkerAsync();
        }