Пример #1
0
        private void InitializeLater()
        {
            Window.AllowUserResizing  = true;
            Window.ClientSizeChanged += new System.EventHandler <System.EventArgs>(Window_ClientSizeChanged);

            renderTarget = new RenderTarget2D(GraphicsDevice, 1920, 1080);

            windowResX = renderTarget.Width / 2;
            windowResY = renderTarget.Height / 2;

            ContentLoader.Initialize(Content, GraphicsDevice, new Random());
            DrawM.Initialize(GraphicsDevice);
            spriteBatch = new SpriteBatch(GraphicsDevice);
            G.batch     = spriteBatch;
            Drawer.Initialize(spriteBatch);
            Input.Initialize();
            Rules.Initialize();
            Save.Initialize();
            RunningContent.LoadAll(GraphicsDevice);


            G.Initialize(new Int2(renderTarget.Width / samplingZoom, renderTarget.Height / samplingZoom), GraphicsDevice);


            //InitPatcher();

            inputRecorderManager = new InputRecorderManager();

            Restart(null);

            ToggleFullscreen();
        }
Пример #2
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);
        }