示例#1
0
        public void RunLoop()
        {
            RunLoopCreated = true;
            mRunThread = new System.Threading.Thread(() =>
                {
                    ParentForm.Visible = true;
                    ParentForm.Visible = false;

                    var ctrl = mRenderWindow;
                    mDriver = new Direct3D();
                    mDevice = new Device(mDriver, 0, DeviceType.Hardware, ctrl.Handle, CreateFlags.HardwareVertexProcessing
                        | CreateFlags.Multithreaded,
                        new PresentParameters()
                        {
                            Windowed = true,
                            BackBufferFormat = Format.A8R8G8B8,
                            BackBufferHeight = ctrl.ClientSize.Height,
                            BackBufferWidth = ctrl.ClientSize.Width,
                            EnableAutoDepthStencil = true,
                            AutoDepthStencilFormat = Format.D24S8,
                            SwapEffect = SwapEffect.Discard,
                            DeviceWindowHandle = ctrl.Handle,
                        }
                        );

                    mDevice.SetTransform(TransformState.Projection, Matrix.PerspectiveFovLH((45.0f * (float)Math.PI) / 180.0f, ctrl.ClientSize.Width / (float)ctrl.ClientSize.Height, 0.1f, 100000.0f));
                    mDevice.SetRenderState(RenderState.Lighting, false);
                    mDevice.SetRenderState(RenderState.ZEnable, true);
                    mDevice.SetRenderState(RenderState.CullMode, Cull.None);
                    mDevice.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Linear);
                    mDevice.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear);
                    mDevice.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Linear);

                    InputManager = new Video.Input.InputManager();
                    InputManager.InputWindow = ctrl;
                    Camera = new ModelCamera(ctrl, this);
                    TextureManager = new Video.TextureManager(mDevice);

                    Application.Idle += (sender, args) =>
                        {
                            if (ParentForm.Visible == false)
                                return;

                            MSG msg = new MSG();
                            while (!PeekMessage(ref msg, IntPtr.Zero, 0, 0, 0))
                                RenderFrame();
                        };

                    if (LoadDone != null)
                        LoadDone();

                    LoadEvent.Set();

                    ParentForm.Visible = true;
                    Application.Run(ParentForm);
                }
            );

            mRunThread.Start();
            Game.GameManager.GameTerminated += () =>
                {
                    if (ParentForm.IsDisposed == false)
                        ParentForm.Invoke(new Action(ParentForm.Dispose));
                };
        }
示例#2
0
        public void RunLoop()
        {
            RunLoopCreated = true;
            mRunThread     = new System.Threading.Thread(() =>
            {
                ParentForm.Visible = true;
                ParentForm.Visible = false;

                var ctrl = mRenderWindow;
                mDriver  = new Direct3D();
                mDevice  = new Device(mDriver, 0, DeviceType.Hardware, ctrl.Handle, CreateFlags.HardwareVertexProcessing
                                      | CreateFlags.Multithreaded,
                                      new PresentParameters()
                {
                    Windowed               = true,
                    BackBufferFormat       = Format.A8R8G8B8,
                    BackBufferHeight       = ctrl.ClientSize.Height,
                    BackBufferWidth        = ctrl.ClientSize.Width,
                    EnableAutoDepthStencil = true,
                    AutoDepthStencilFormat = Format.D24S8,
                    SwapEffect             = SwapEffect.Discard,
                    DeviceWindowHandle     = ctrl.Handle,
                }
                                      );

                mDevice.SetTransform(TransformState.Projection, Matrix.PerspectiveFovLH((45.0f * (float)Math.PI) / 180.0f, ctrl.ClientSize.Width / (float)ctrl.ClientSize.Height, 0.1f, 100000.0f));
                mDevice.SetRenderState(RenderState.Lighting, false);
                mDevice.SetRenderState(RenderState.ZEnable, true);
                mDevice.SetRenderState(RenderState.CullMode, Cull.None);
                mDevice.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Linear);
                mDevice.SetSamplerState(0, SamplerState.MagFilter, TextureFilter.Linear);
                mDevice.SetSamplerState(0, SamplerState.MipFilter, TextureFilter.Linear);

                InputManager             = new Video.Input.InputManager();
                InputManager.InputWindow = ctrl;
                Camera         = new ModelCamera(ctrl, this);
                TextureManager = new Video.TextureManager(mDevice);

                Application.Idle += (sender, args) =>
                {
                    if (ParentForm.Visible == false)
                    {
                        return;
                    }

                    MSG msg = new MSG();
                    while (!PeekMessage(ref msg, IntPtr.Zero, 0, 0, 0))
                    {
                        RenderFrame();
                    }
                };

                if (LoadDone != null)
                {
                    LoadDone();
                }

                LoadEvent.Set();

                ParentForm.Visible = true;
                Application.Run(ParentForm);
            }
                                                         );

            mRunThread.Start();
            Game.GameManager.GameTerminated += () =>
            {
                if (ParentForm.IsDisposed == false)
                {
                    ParentForm.Invoke(new Action(ParentForm.Dispose));
                }
            };
        }