Ejemplo n.º 1
0
        public void DrawScene()
        {
            if (m_ready)
            {
                m_FPS.BeginFrame();

                if (MdxRender.DeviceInfo.bDeviceLost)
                {
                    AttemptRecovery();
                }
                else
                {
                    try
                    {
                        MdxRender.Dev.Clear(ClearFlags.ZBuffer | ClearFlags.Target, ClearColor, 1.0f, 0);
                        MdxRender.Dev.Transform.View  = Camera.GetViewMatrix();
                        MdxRender.Dev.Transform.World = Matrix.Identity;

                        //todo: preview vs bsp mode
                        if (PreviewManager.Mode != PreviewMode.ProjectMode)
                        {
                            MdxRender.SetZbufRange(0.01f, 300.0f);
                            UpdateViewTransform();
                        }
                        else
                        {
                            SetZbufRange(30.0f, 100000.0f);
                            UpdateViewTransform();
                        }

                        MdxRender.Dev.BeginScene();

                        if (!m_isPaused)
                        {
                            MdxRender.Dev.Material = whiteMaterial;
                            //The beef of the matter
                            if (PreviewManager.Mode != PreviewMode.ProjectMode)
                            {
                                PreviewManager.RenderActivePreview();
                                //mapViewButton.DrawButton(true);
                            }
                            else
                            {
                                #region DrawProject
                                MdxRender.Dev.Material = whiteMaterial;
                                MdxRender.Dev.RenderState.DiffuseMaterialSource  = ColorSource.Material;
                                MdxRender.Dev.RenderState.SpecularMaterialSource = ColorSource.Material;
                                MdxRender.Dev.RenderState.SpecularEnable         = false;

                                //Render the skybox if we are in map view mode
                                if (MdxRender.SkyBox != null)
                                {
                                    //turn lighting off for skybox
                                    //MdxRender.Dev.RenderState.Lighting = false;

                                    //turn off fog or you won't be able to see the skybox through it
                                    if (MdxRender.FogEnabled)
                                    {
                                        MdxRender.Dev.SetRenderState(RenderStates.FogEnable, false);
                                    }

                                    //disable z-writing for the skybox since it is behind everything
                                    //and to get rid of that stupid clipping artifact
                                    MdxRender.Dev.RenderState.ZBufferWriteEnable = false;
                                    SkyBox.Render();
                                    MdxRender.Dev.RenderState.ZBufferWriteEnable = true;

                                    //turn fog back on
                                    if (MdxRender.FogEnabled)
                                    {
                                        MdxRender.Dev.SetRenderState(RenderStates.FogEnable, true);
                                    }
                                }
                                else
                                {
                                    //turn off fog when we are in model preview mode
                                    MdxRender.Dev.SetRenderState(RenderStates.FogEnable, false);
                                }

                                //draw the map BSP
                                if (Halo1_Bsp != null)
                                {
                                    MdxRender.Dev.RenderState.Lighting = true;
                                    Halo1_Bsp.DrawBsp();
                                    TagBsp.Debug_RenderNearestNeighborVerts();
                                    MdxRender.lightmapDebugger.Render();
                                    //Halo1_Bsp.DrawWireframeBsp();
                                    //MdxRender.Dev.RenderState.FillMode = FillMode.Solid;
                                }

                                //turn on lighting for scenery
                                MdxRender.Dev.RenderState.Lighting = true;
                                MdxRender.SM.DisableBlend(); //this necessary?

                                //draw all ye map objects
                                //MdxRender.Dev.RenderState.DiffuseMaterialSource = ColorSource.Material;
                                //MdxRender.Dev.RenderState.SpecularMaterialSource = ColorSource.Material;
                                //MdxRender.Dev.RenderState.SpecularEnable = true;
                                ProjectManager.MapSpawns.Render();
                                #endregion


                                if (m_showFPS)
                                {
                                    DrawFPS();
                                }
                            }
                        }
                        else
                        {
                            m_fontFPS.DrawText(null, "Rendering Paused", 3, 3, Color.White);
                            Thread.Sleep(250);
                        }
                    }
                    catch (Exception e)
                    {
                        Trace.WriteLine("Error during DrawScene(): " + e.Message);
                    }
                    finally
                    {
                        try
                        {
                            MdxRender.Dev.EndScene();
                            MdxRender.Dev.Present();
                            //SwapChain sc = MdxRender.Dev.GetSwapChain(0);
                            //sc.Present(Present.LinearContent);
                        }
                        catch (DeviceLostException)
                        {
                            MdxRender.DeviceInfo.bDeviceLost = true;
                            Trace.WriteLine("Device was lost.");
                        }
                        catch (Exception e)
                        {
                            Trace.WriteLine("Error during Device.Present(): " + e.Message);
                        }
                    }
                }
                m_FPS.EndFrame();
            }
        }