예제 #1
0
파일: Main.cs 프로젝트: XZelnar/MicroWorld
        protected override void Draw(GameTime gameTime)
        {
            try//TODO rm?
            {
                if (globalFBO == null)
                {
                    return;
                }

                if (InputEngine.IsKeyPressed(Keys.F10) && !InputEngine.IsKeyDown(Keys.F11))
                {
                    goto PostDraw;
                }

                renderer.EnableFBO(globalFBO);
                if (curState == "GUIGlobalLoad")
                {
                    GraphicsDevice.Clear(new Color(45, 57, 107));
                    renderer.BeginUnscaled();
                    glbg.Draw(renderer);
                    renderer.End();
                    goto PostDraw;
                }

                var t1 = DateTime.Now;

                GraphicsDevice.Clear(new Color(45, 57, 107));
                renderer.Begin();

                Modding.ModdingLogics.PreDraw();

                Graphics.GraphicsEngine.Draw();
                Debug.DebugInfo.Draw();
                Debug.InputInfo.Draw();
                Debug.CollidersOverlay.Draw();
                Debug.VisMapOverlay.Draw();

                Modding.ModdingLogics.PostDraw();

                renderer.End();

                var t2 = DateTime.Now;
                var t  = t2.Subtract(t1);
                Debug.DebugInfo.DrawTime = (int)t.TotalMilliseconds;

                fps++;
                debugExcaprionsInRow = 0;

PostDraw:
                renderer.DisableFBO();
                if (InputEngine.curKeyboard.IsKeyDown(Keys.F11) && !InputEngine.lastKeyboard.IsKeyDown(Keys.F11))
                {
                    var fs = new System.IO.FileStream("screenshot.png", FileMode.Create);
                    globalFBO.SaveAsPng(fs, globalFBO.Width, globalFBO.Height);
                    fs.Close();
                }
                GraphicsDevice.Clear(new Color(45, 57, 107));
                updateStereoShader();
                renderer.BeginUnscaled(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearWrap, DepthStencilState.None, RasterizerState.CullNone,
                                       shader);
                renderer.Draw(globalFBO, new Vector2(), Color.White);
                renderer.End();
                //*
            }
            //catch (Exception e)
            catch (DivideByZeroException e) //TODO
            {
                throw e;                    //TODO rm in releases
                debugExcaprionsInRow++;
                IO.Log.Write(e, debugExcaprionsInRow, true, false);
                if (debugExcaprionsInRow >= 5)
                {
                    IO.Log.Write(IO.Log.State.SEVERE, "Maximum number of exceptions in row was reached in Draw. Terminating...");
                    Close();
                }
            }//*/

            base.Draw(gameTime);
        }
예제 #2
0
파일: Main.cs 프로젝트: XZelnar/MicroWorld
        protected override void Update(GameTime gameTime)
        {
            if (InputEngine.IsKeyPressed(Keys.F10) && !InputEngine.IsKeyDown(Keys.F11))
            {
                InputEngine.Update();
                return;
            }

            Debug.Initializer.Update();
            Debug.ChartDebug.Step();

            _ticks++;
            isActive = IsActive;

            try//TODO rm?
            {
                if (curState == "GUIGlobalLoad")
                {
                    glbg.Update();
                    if (LoadingThread.ThreadState == System.Threading.ThreadState.Stopped || !LoadingThread.IsAlive)
                    {
                        if (Settings.startAsEncEdit)
                        {
                            Main.curState = "GUIEncyclopediaEditor";
                            Graphics.GUI.GUIEngine.curScene = Graphics.GUI.GUIEngine.s_encyclopediaEditor;
                        }
                        else
                        {
                            glbg.OnContentLoaded();
                            //Graphics.GUI.GUIEngine.ChangeScene(Graphics.GUI.GUIEngine.s_mainMenu, "GUIMain");
                        }
                    }

                    base.Update(gameTime);
                    return;
                }

                this.IsMouseVisible = !this.IsActive;

                var tt1 = DateTime.Now;

                InputEngine.Update();

                Modding.ModdingLogics.PreUpdate();
                Logics.GameLogicsHelper.Update();

                Graphics.GraphicsEngine.Update();

                Logics.LevelEngine.Update();
                Graphics.GUI.ClickabilityOverlay.Update();

                Debug.DebugInfo.MatrixRecalculateTime = 0;
                Debug.DebugInfo.ComponentUpdateTime   = 0;
                if (curState.StartsWith("GAME"))
                {
                    MicroWorld.Components.ComponentsManager.NonGameUpdate();
                    if (Settings.GameState == Settings.GameStates.Running)
                    {
                        Logics.GameLogicsHelper.SimulationStep();
                    }
                }

                Sound.SoundManager.Update();
                Sound.SoundPlayer.Update();

                Modding.ModdingLogics.PostUpdate();

                var tt5 = DateTime.Now;
                var t2  = tt5.Subtract(tt1);
                Debug.DebugInfo.UpdateTime = (int)t2.TotalMilliseconds;

                //Window.Title = (Graphics.GUI.GUIEngine.s_mainMenu.background as Graphics.GUI.Background.MainMenu).seed.ToString();
                tps++;
                if (lastSecond != DateTime.Now.Second)
                {
                    lastSecond = DateTime.Now.Second;
                    Debug.DebugInfo.UpdatesPerSecond = tps;
                    Debug.DebugInfo.FramesPerSecond  = fps;
                    tps = 0;
                    fps = 0;
                }
                updateExcaprionsInRow = 0;
            }
            //catch (Exception e)
            catch (DivideByZeroException e) //TODO
            {
                throw e;                    //TODO rm in releases
                updateExcaprionsInRow++;
                IO.Log.Write(e, updateExcaprionsInRow, false, true);
                if (updateExcaprionsInRow >= 5)
                {
                    IO.Log.Write(IO.Log.State.SEVERE, "Maximum number of exceptions in row was reached in Update. Terminating...");
                    Close();
                }
            }

            //Window.Title = InputEngine.curMouse.X.ToString() + "  ;  " + InputEngine.curMouse.Y.ToString();

            base.Update(gameTime);
        }