Example #1
0
        public void RunMainLoop(Panel Panel)
        {
            RenderLoop.Run(Panel, () =>
            {
                //Resizing
                if (device.MustResize)
                {
                    device.Resize();
                    Camera.AspectRatio = (float)Panel.Width / Panel.Height;
                }

                Program.MainForm.KeyboardController();

                sharpFPS.Update();

                device.Clear(backgroundColor);

                if (ArchiveEditorFunctions.allowRender)
                {
                    if (isDrawingUI)
                    {
                        viewProjection = Matrix.OrthoOffCenterRH(0, 640, -480, 0, -Camera.FarPlane, Camera.FarPlane);

                        device.SetFillModeDefault();
                        device.SetCullModeDefault();
                        device.ApplyRasterState();
                        device.SetBlendStateAlphaBlend();
                        device.SetDefaultDepthState();
                        device.UpdateAllStates();

                        foreach (IRenderableAsset a in
                                 (from IRenderableAsset asset in ArchiveEditorFunctions.renderableAssets
                                  where (asset is AssetUI || asset is AssetUIFT) && asset.ShouldDraw(this)
                                  select(IClickableAsset) asset).OrderBy(f => - f.PositionZ))
                        {
                            a.Draw(this);
                        }
                    }
                    else
                    {
                        if (playingFly)
                        {
                            flyToPlay.Play();
                        }

                        Program.MainForm.SetToolStripStatusLabel(Camera.ToString() + " FPS: " + $"{sharpFPS.FPS:0.0000}");

                        Matrix view    = Camera.ViewMatrix;
                        viewProjection = view * Camera.ProjectionMatrix;
                        frustum        = new BoundingFrustum(view * Camera.BiggerFovProjectionMatrix);

                        device.SetFillModeDefault();
                        device.SetCullModeDefault();
                        device.ApplyRasterState();
                        device.SetDefaultDepthState();
                        device.UpdateAllStates();

                        foreach (var a in ArchiveEditorFunctions.renderableJSPs)
                        {
                            if (a.ShouldDraw(this))
                            {
                                a.Draw(this);
                            }
                        }

                        foreach (IRenderableAsset a in ArchiveEditorFunctions.renderableAssets)
                        {
                            if (a.ShouldDraw(this))
                            {
                                renderableAssets.Add(a);
                            }
                            else
                            {
                                renderableAssets.Remove(a);
                            }
                        }

                        //foreach (IRenderableAsset a in renderableAssets.OrderByDescending(a => a.GetDistanceFrom(Camera.Position)))
                        //    a.Draw(this);

                        HashSet <IRenderableAsset> renderableAssetsTrans = new HashSet <IRenderableAsset>();

                        foreach (IRenderableAsset a in renderableAssets)
                        {
                            if (a.SpecialBlendMode)
                            {
                                renderableAssetsTrans.Add(a);
                            }
                            else
                            {
                                a.Draw(this);
                            }
                        }

                        foreach (IRenderableAsset a in renderableAssetsTrans.OrderByDescending(a => a.GetDistanceFrom(Camera.Position)))
                        {
                            a.Draw(this);
                        }
                    }
                }

                device.SetCullModeNone();
                device.ApplyRasterState();
                device.SetBlendStateAlphaBlend();
                device.UpdateAllStates();

                ArchiveEditorFunctions.RenderGizmos(this);

                device.Present();
            });

            //release resources
            whiteDefault.Dispose();
            TextureManager.DisposeTextures();

            Cube.Dispose();
            Pyramid.Dispose();
            Cylinder.Dispose();
            Sphere.Dispose();
            Plane.Dispose();

            basicBuffer.Dispose();
            basicShader.Dispose();

            defaultBuffer.Dispose();
            defaultShader.Dispose();

            tintedBuffer.Dispose();
            tintedShader.Dispose();

            foreach (SharpMesh mesh in RenderWareModelFile.completeMeshList)
            {
                if (mesh != null)
                {
                    mesh.Dispose();
                }
            }

            foreach (var bf in completeVertexBufferList)
            {
                if (bf != null)
                {
                    bf.Dispose();
                }
            }

            device.Dispose();
        }
Example #2
0
        public void RunMainLoop(Panel Panel)
        {
            RenderLoop.Run(Panel, () =>
            {
                //Resizing
                if (device.MustResize)
                {
                    device.Resize();
                    Camera.AspectRatio = (float)Panel.Width / Panel.Height;
                }

                Program.MainForm.KeyboardController();

                sharpFPS.Update();

                device.Clear(backgroundColor);

                if (ArchiveEditorFunctions.allowRender)
                {
                    if (isDrawingUI)
                    {
                        viewProjection = Matrix.OrthoOffCenterRH(0, 640, -480, 0, -Camera.FarPlane, Camera.FarPlane);

                        device.SetFillModeDefault();
                        device.SetCullModeDefault();
                        device.ApplyRasterState();
                        device.SetBlendStateAlphaBlend();
                        device.SetDefaultDepthState();
                        device.UpdateAllStates();

                        List <AssetUI> renderCommon = new List <AssetUI>(ArchiveEditorFunctions.renderableAssetSetCommon.Count);

                        foreach (IRenderableAsset a in ArchiveEditorFunctions.renderableAssetSetCommon)
                        {
                            if (a is AssetUI ui)
                            {
                                renderCommon.Add(ui);
                            }
                            else if (a is AssetUIFT uift)
                            {
                                renderCommon.Add(uift);
                            }
                        }

                        renderCommon = renderCommon.OrderBy(f => - f.PositionZ).ToList();

                        foreach (IRenderableAsset a in renderCommon)
                        {
                            a.Draw(this);
                        }
                    }
                    else
                    {
                        if (playingFly)
                        {
                            flyToPlay.Play();
                        }

                        Program.MainForm.SetToolStripStatusLabel(Camera.ToString() + " FPS: " + $"{sharpFPS.FPS:0.0000}");

                        Matrix view    = Camera.ViewMatrix;
                        viewProjection = view * Camera.ProjectionMatrix;
                        frustum        = new BoundingFrustum(view * Camera.BiggerFovProjectionMatrix);

                        device.SetFillModeDefault();
                        device.SetCullModeDefault();
                        device.ApplyRasterState();
                        device.SetBlendStateAlphaBlend();
                        device.SetDefaultDepthState();
                        device.UpdateAllStates();

                        List <IRenderableAsset> renderJSP    = new List <IRenderableAsset>(ArchiveEditorFunctions.renderableAssetSetJSP.Count);
                        List <IRenderableAsset> renderCommon = new List <IRenderableAsset>(ArchiveEditorFunctions.renderableAssetSetCommon.Count);
                        List <IRenderableAsset> renderTrans  = new List <IRenderableAsset>(ArchiveEditorFunctions.renderableAssetSetTrans.Count);
                        List <IRenderableAsset> renderLarge  = new List <IRenderableAsset>();

                        renderJSP.AddRange(ArchiveEditorFunctions.renderableAssetSetJSP);
                        renderCommon.AddRange(ArchiveEditorFunctions.renderableAssetSetCommon);
                        renderTrans.AddRange(ArchiveEditorFunctions.renderableAssetSetTrans);

                        renderCommon = renderCommon.OrderBy(f => f.GetDistance(Camera.Position)).Reverse().ToList();
                        renderTrans  = renderTrans.OrderBy(f => f.GetDistance(Camera.Position)).Reverse().ToList();

                        foreach (IRenderableAsset a in renderJSP)
                        {
                            a.Draw(this);
                        }

                        foreach (IRenderableAsset a in renderCommon)
                        {
                            BoundingBox bb = a.GetBoundingBox();
                            if (bb.Width > 100)
                            {
                                renderLarge.Add(a);
                            }
                            else if (a is AssetPKUP assetPKUP && AssetPICK.pickEntries.Count == 0)
                            {
                                renderTrans.Add(a);
                            }
Example #3
0
        private void MainLoop(System.Drawing.Size controlSize)
        {
            //Resizing
            if (device.MustResize)
            {
                device.Resize();
                Camera.AspectRatio = (float)controlSize.Width / controlSize.Height;
            }

            Program.MainForm.KeyboardController();

            sharpFPS.Update();

            device.Clear(backgroundColor);

            if (allowRender)
            {
                lock (renderableAssets)
                    if (isDrawingUI)
                    {
                        viewProjection = Matrix.OrthoOffCenterRH(0, 640, -480, 0, -Camera.FarPlane, Camera.FarPlane);

                        device.SetFillModeDefault();
                        device.SetCullModeDefault();
                        device.ApplyRasterState();
                        device.SetBlendStateAlphaBlend();
                        device.SetDefaultDepthState();
                        device.UpdateAllStates();

                        lock (ArchiveEditorFunctions.renderableAssets)
                            foreach (IRenderableAsset a in
                                     (from IRenderableAsset asset in ArchiveEditorFunctions.renderableAssets
                                      where (asset is AssetUI || asset is AssetUIFT) && asset.ShouldDraw(this)
                                      select(IClickableAsset) asset).OrderBy(f => - f.PositionZ))
                            {
                                a.Draw(this);
                            }
                    }
                    else
                    {
                        if (recordingFly)
                        {
                            flyToPlay.Record();
                        }
                        else if (playingFly)
                        {
                            flyToPlay.Play();
                        }

                        Program.MainForm.SetToolStripStatusLabel(Camera.ToString() + " FPS: " + $"{sharpFPS.FPS:0.0000}");

                        Matrix view = Camera.ViewMatrix;
                        viewProjection = view * Camera.ProjectionMatrix;
                        frustum        = new BoundingFrustum(view * Camera.BiggerFovProjectionMatrix);

                        device.SetFillModeDefault();
                        device.SetCullModeDefault();
                        device.ApplyRasterState();
                        device.SetDefaultDepthState();
                        device.UpdateAllStates();

                        lock (ArchiveEditorFunctions.renderableJSPs)
                            foreach (var a in ArchiveEditorFunctions.renderableJSPs)
                            {
                                if (a.ShouldDraw(this))
                                {
                                    a.Draw(this);
                                }
                            }

                        lock (ArchiveEditorFunctions.renderableAssets)
                            foreach (IRenderableAsset a in ArchiveEditorFunctions.renderableAssets)
                            {
                                if (a.ShouldDraw(this))
                                {
                                    renderableAssets.Add(a);
                                }
                                else
                                {
                                    renderableAssets.Remove(a);
                                }
                            }

                        //foreach (IRenderableAsset a in renderableAssets.OrderByDescending(a => a.GetDistanceFrom(Camera.Position)))
                        //    a.Draw(this);

                        var renderableAssetsTrans = new HashSet <IRenderableAsset>();

                        foreach (IRenderableAsset a in renderableAssets)
                        {
                            if (a.SpecialBlendMode)
                            {
                                renderableAssetsTrans.Add(a);
                            }
                            else
                            {
                                a.Draw(this);
                            }
                        }

                        foreach (IRenderableAsset a in renderableAssetsTrans.OrderByDescending(a => a.GetDistanceFrom(Camera.Position)))
                        {
                            a.Draw(this);
                        }
                    }
            }

            device.SetCullModeNone();
            device.ApplyRasterState();
            device.SetBlendStateAlphaBlend();
            device.UpdateAllStates();

            ArchiveEditorFunctions.RenderGizmos(this);

            device.Present();
        }