Example #1
0
        /// <summary>
        /// Runs the game.
        /// </summary>
        public void Run()
        {
            bool isFormClosed   = false;
            bool formIsResizing = false;

            Form = new RenderForm();

            currentFormWindowState = Form.WindowState;
            Form.Resize           += (o, args) =>
            {
                if (Form.WindowState != currentFormWindowState)
                {
                    if (togglingFullScreen == false)
                    {
                        HandleResize(o, args);
                    }
                }

                currentFormWindowState = Form.WindowState;
            };

            Form.ResizeBegin += (o, args) => { formIsResizing = true; };
            Form.ResizeEnd   += (o, args) =>
            {
                formIsResizing = false;
                HandleResize(o, args);
            };

            Form.Closed += (o, args) => { isFormClosed = true; };


            // initialize input
            SlimDX.RawInput.Device.RegisterDevice(UsagePage.Generic, UsageId.Keyboard, DeviceFlags.None);
            SlimDX.RawInput.Device.RegisterDevice(UsagePage.Generic, UsageId.Mouse, DeviceFlags.None);

            Input = new Input(Form);

            SlimDX.RawInput.Device.KeyboardInput += Input.Device_KeyboardInput;
            SlimDX.RawInput.Device.MouseInput    += Input.Device_MouseInput;


            Width            = 1024;
            Height           = 768;
            FullScreenWidth  = Screen.PrimaryScreen.Bounds.Width;
            FullScreenHeight = Screen.PrimaryScreen.Bounds.Height;
            NearPlane        = 0.1f;
            FarPlane         = 200f;
            FieldOfView      = (float)Math.PI / 4;
            Freelook         = new FreeLook(Input);
            Ambient          = Color.Gray.ToArgb();

            OnInitializeDevice();

            Fps         = new FpsDisplay(Device);
            MeshFactory = new GraphicObjectFactory(Device);

            OnInitialize();
            OnResetDevice();

            clock.Start();
            MessagePump.Run(Form, () =>
            {
                OnHandleInput();
                Update();
                Input.ClearKeyCache();

                if (isFormClosed)
                {
                    return;
                }

                if (!formIsResizing)
                {
                    Render();
                }
            });

            SlimDX.RawInput.Device.KeyboardInput -= Input.Device_KeyboardInput;
            SlimDX.RawInput.Device.MouseInput    -= Input.Device_MouseInput;

            OnLostDevice();
        }
Example #2
0
        /// <summary>
        /// Runs the game.
        /// </summary>
        public void Run()
        {
            bool isFormClosed = false;
            bool formIsResizing = false;

            Form = new RenderForm();

            currentFormWindowState = Form.WindowState;
            Form.Resize += (o, args) =>
            {
                if (Form.WindowState != currentFormWindowState)
                {
                    if (togglingFullScreen == false)
                        HandleResize(o, args);
                }

                currentFormWindowState = Form.WindowState;
            };

            Form.ResizeBegin += (o, args) => { formIsResizing = true; };
            Form.ResizeEnd += (o, args) =>
            {
                formIsResizing = false;
                HandleResize(o, args);
            };

            Form.Closed += (o, args) => { isFormClosed = true; };

            // initialize input
            SlimDX.RawInput.Device.RegisterDevice(UsagePage.Generic, UsageId.Keyboard, DeviceFlags.None);
            SlimDX.RawInput.Device.RegisterDevice(UsagePage.Generic, UsageId.Mouse, DeviceFlags.None);

            Input = new Input(Form);

            SlimDX.RawInput.Device.KeyboardInput += Input.Device_KeyboardInput;
            SlimDX.RawInput.Device.MouseInput += Input.Device_MouseInput;

            Width = 1024;
            Height = 768;
            FullScreenWidth = Screen.PrimaryScreen.Bounds.Width;
            FullScreenHeight = Screen.PrimaryScreen.Bounds.Height;
            NearPlane = 0.1f;
            FarPlane = 200f;
            FieldOfView = (float)Math.PI / 4;
            Freelook = new FreeLook(Input);
            Ambient = Color.Gray.ToArgb();

            OnInitializeDevice();

            Fps = new FpsDisplay(Device);
            MeshFactory = new GraphicObjectFactory(Device);

            OnInitialize();
            OnResetDevice();

            clock.Start();
            MessagePump.Run(Form, () =>
            {
                OnHandleInput();
                Update();
                Input.ClearKeyCache();

                if (isFormClosed)
                    return;

                if (!formIsResizing)
                    Render();
            });

            SlimDX.RawInput.Device.KeyboardInput -= Input.Device_KeyboardInput;
            SlimDX.RawInput.Device.MouseInput -= Input.Device_MouseInput;

            OnLostDevice();
        }