Пример #1
0
        protected virtual void Dispose(bool disposing)
        {
            // Unlock the mouse cursor
            Cursor.Clip = new Rectangle();

            if (disposing)
            { // This block will only be executed on manual disposal, not by Garbage Collection
                Engine?.Dispose();
                Form?.Dispose();
                _debugConsole?.Dispose();

                // Stop tracking input
                KeyboardInputProvider?.Dispose();
                MouseInputProvider?.Dispose();
                TouchInputProvider?.Dispose();

                // Assume this is the only usage of SlimDX in the entire process (true for games, not for editors)
                if (ObjectTable.Objects.Count > 0)
                {
                    string leaks = ObjectTable.ReportLeaks();
                    Log.Error(leaks);
#if DEBUG
                    throw new InvalidOperationException(leaks);
#endif
                }
            }
            else
            { // This block will only be executed on Garbage Collection, not by manual disposal
                Log.Error("Forgot to call Dispose on " + this);
#if DEBUG
                throw new InvalidOperationException("Forgot to call Dispose on " + this);
#endif
            }
        }
Пример #2
0
        /// <summary>
        /// Sets up the <see cref="Form"/>.
        /// Call <see cref="ToWindowed"/> or <see cref="ToFullscreen"/> and <see cref="Run"/> afterwards.
        /// </summary>
        /// <param name="name">The name of the application for the title bar</param>
        /// <param name="icon">The icon of the application for the title bar</param>
        /// <param name="background">A background image for the window while loading</param>
        /// <param name="stretch">Stretch <paramref name="background"/> to fit the screen? (<c>false</c> will center it instead)</param>
        protected GameBase(string name, Icon icon = null, Image background = null, bool stretch = false)
        {
            // Setup render-target form
            Form = new GameForm
            {
                Text            = name, Icon = icon,
                BackgroundImage = background, BackgroundImageLayout = stretch ? ImageLayout.Stretch : ImageLayout.Center, BackColor = Color.Black,
                MinimumSize     = new Size(800, 600), Size = new Size(800, 600), MaximizeBox = false
            };

            // Setup event hooks
            Form.Shown   += Form_Shown;
            Form.KeyDown += delegate(object sender, KeyEventArgs e)
            {
                // Ctrl + Shift + Alt + D = Debug console
                if (e.Control && e.Alt && e.Shift && e.KeyCode == Keys.D)
                {
                    Debug();
                }
            };

            // Start tracking input
            KeyboardInputProvider = new KeyboardInputProvider(Form);
            MouseInputProvider    = new MouseInputProvider(Form);
            TouchInputProvider    = new TouchInputProvider(Form);
        }
Пример #3
0
        //--------------------//

        #region Setup
        /// <summary>
        /// Initializes the <see cref="OmegaEngine.Engine"/> for rendering on this <see cref="Panel"/>.
        /// </summary>
        /// <returns>The newly initialized <see cref="Engine"/>.</returns>
        /// <exception cref="NotSupportedException">The graphics card does not meet the engine's minimum requirements.</exception>
        /// <exception cref="Direct3D9NotFoundException">Throw if required DirectX version is missing.</exception>
        /// <exception cref="Direct3DX9NotFoundException">Throw if required DirectX version is missing.</exception>
        /// <exception cref="Direct3D9Exception">internal errors occurred while intiliazing the graphics card.</exception>
        /// <exception cref="SlimDX.DirectSound.DirectSoundException">internal errors occurred while intiliazing the sound card.</exception>
        /// <remarks>Calling this multiple times will always return the same <see cref="OmegaEngine.Engine"/> instance.</remarks>
        public Engine Setup()
        {
            if (Engine == null)
            {
                Engine = new Engine(this, new EngineConfig {
                    TargetSize = ClientSize
                });
                KeyboardInputProvider = new KeyboardInputProvider(this);
                MouseInputProvider    = new MouseInputProvider(this);
                TouchInputProvider    = new TouchInputProvider(this);
            }

            return(Engine);
        }
Пример #4
0
        //--------------------//

        #region Dispose
        protected override void Dispose(bool disposing)
        {
            try
            {
                _renderTimer.Dispose();

                Engine?.Dispose();
                TouchInputProvider?.Dispose();
                MouseInputProvider?.Dispose();
                KeyboardInputProvider?.Dispose();
            }
            finally
            {
                base.Dispose(disposing);
            }
        }
Пример #5
0
 /// <summary>
 /// Calls <see cref="InputProvider.RemoveReceiver"/> for all default <see cref="InputProvider"/>s.
 /// </summary>
 /// <param name="receiver">The object to no longer receive the commands.</param>
 public void RemoveInputReceiver(IInputReceiver receiver)
 {
     KeyboardInputProvider.RemoveReceiver(receiver);
     MouseInputProvider.RemoveReceiver(receiver);
     TouchInputProvider.RemoveReceiver(receiver);
 }
Пример #6
0
 /// <summary>
 /// Calls <see cref="InputProvider.AddReceiver"/> for all default <see cref="InputProvider"/>s.
 /// </summary>
 /// <param name="receiver">The object to receive the commands.</param>
 public void AddInputReceiver(IInputReceiver receiver)
 {
     KeyboardInputProvider.AddReceiver(receiver);
     MouseInputProvider.AddReceiver(receiver);
     TouchInputProvider.AddReceiver(receiver);
 }