Beispiel #1
0
        protected override void Update(GameTime gameTime)
        {
            updateFps.NewFrame();

            if (inited < 0)
            {
                inited++;
                if (inited == 0)
                {
                    InitializeLater();
                }
                return;
            }

            Input.Update();

            bool newIsApplicationActive = ApplicationIsActivated();

            if (isApplicationActive != newIsApplicationActive)
            {
                isApplicationActive = newIsApplicationActive;
                if (isApplicationActive)
                {
                    frameFps.Continue();
                }
                else
                {
                    frameFps.Pause();
                }
            }


            if (updateGame)
            {
                bool doUpdate = true;
#if DEBUG
                if (Input.up.pressed)
                {
                    updatesPerFrame *= 2;
                }
                else if (Input.down.pressed)
                {
                    updatesPerFrame /= 2d;
                }
                if (updatesPerFrame > 0.75d && updatesPerFrame < 1.5d)
                {
                    updatesPerFrame = 1d;
                }

                double cUpdate = updatesPerFrame;
                if (Input.leftShift.down)
                {
                    cUpdate *= 10d;

                    if (Input.leftControl.down)
                    {
                        cUpdate *= 10d;
                    }
                }

                if (Input.rightControl.down)
                {
                    doUpdate = false;
                }

                if (Input.leftAlt.down)
                {
                    cUpdate *= 0.2d;

                    if (Input.leftControl.down)
                    {
                        cUpdate *= 0.2d;
                    }
                }

                InceptionUpdatesPerFrame = cUpdate;
#endif

                //if (iterations > 0 && inputRecorderManager.playing)
                //    iterations = 100;

                if (doUpdate)
                {
                    #region adapt mouse pos

                    float scale = CalculateRenderTargetScaling();

                    Vector2 rtPos = CalculateRenderTargetPos(scale);

                    Input.mbPos -= rtPos;

                    if (scale != 1)
                    {
                        Input.mbPos /= scale;
                    }

                    Input.mbPos /= samplingZoom;

                    #endregion



#if DEBUG
                    if (Input.r.released && !inputRecorderManager.playing)
                    {
                        restart = true;
                    }
                    if (Input.esc.pressed)
                    {
                        exit = true;
                    }
#endif

                    if (restart)
                    {
                        restart = false;
                        Restart(null);
                    }

                    if (exit)
                    {
                        exit = false;
                        ExitToSurvey();
                    }

#if DEBUG
                    if (Input.esc.pressed && Input.leftShift.down)
                    {
                        if (!inputRecorderManager.playing)
                        {
                            Exit();
                        }
                        return;
                    }
#endif
                    if (Input.f11.pressed)
                    {
                        ToggleFullscreen();
                    }

#if DEBUG
                    if (Input.right.pressed)
                    {
                        SwapScreen(true);
                    }
                    if (Input.left.pressed)
                    {
                        SwapScreen(false);
                    }
#endif

                    if (Input.leftControl.down && Input.p.pressed)
                    {
                        patcher.StartDownload();
                    }


                    //if (Input.tab.pressed)
                    //{
                    //    Program.ShowWindow(window.Handle, 6);
                    //}

                    if (cmds.Count > 0)
                    {
                        while (cmds.Count > 0)
                        {
                            string cmd = cmds[cmds.Count - 1];
                            cmds.RemoveAt(cmds.Count - 1);


                            // execute cmd
                            string[] cmdSplit = cmd.Split(new char[] { ' ' });
                            string   cmd0     = cmdSplit[0];
                            switch (cmd0)
                            {
                            case "exit":
                                Exit();
                                break;
                            }
                        }

                        //Program.ShowWindow(window.Handle, 9);
                    }

                    Action playRecord;
                    if ((playRecord = inputRecorderManager.Update()) != null)
                    {
                        Restart(playRecord);
                        return;
                    }

                    ingame.Update();

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


                    while (doInThisThread.Count > 0)
                    {
                        doInThisThread[0].Invoke(this);
                        if (doInThisThread.Count > 0)
                        {
                            doInThisThread.RemoveAt(0);
                        }
                    }
                }
            }


            if (isApplicationActive != updateGame)
            {
                if (isApplicationActive)
                {
                    if (Input.mbLeft.none || inputRecorderManager.playing)
                    {
                        updateGame = true;
                        if (UPDATERUNNINGCONTENT)
                        {
                            RunningContent.Update(GraphicsDevice);
                        }
                    }
                }
                else
                {
                    updateGame = false;
                }
            }

            updateFrame++;

            base.Update(gameTime);
        }