Example #1
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            Camera.Process();

            // camera moving
            float   dT    = (float)(gameTime.ElapsedGameTime.TotalMilliseconds / 1000);
            Vector3 delta = new Vector3();

            KeyboardState keyState = Keyboard.GetState();

            if (keyState.IsKeyDown(Keys.Right))
            {
                delta += new Vector3(3.0f * dT, 0, 0);
            }

            if (keyState.IsKeyDown(Keys.Left))
            {
                delta += new Vector3(-3.0f * dT, 0, 0);
            }

            if (keyState.IsKeyDown(Keys.Up))
            {
                delta += new Vector3(0, 3.0f * dT, 0);
            }

            if (keyState.IsKeyDown(Keys.Down))
            {
                delta += new Vector3(0, -3.0f * dT, 0);
            }

            if (keyState.IsKeyDown(Keys.PageUp))
            {
                delta += new Vector3(0, 0, -3.0f * dT);
            }

            if (keyState.IsKeyDown(Keys.PageDown))
            {
                delta += new Vector3(0, 0, 3.0f * dT);
            }

            Camera.MainCamera.Position += delta;

            if (Camera.MainCamera.Position.X > 255)
            {
                Camera.MainCamera.Position = new Vector3(4.0f, 40.0f, 12.0f);
            }

            Renderer2D.InitPerFrame();

            ConsoleRenderer.Process();

            base.Update(gameTime);
        }
Example #2
0
        public static void Process()
        {
            // limit FPS and handle events
            int  minMsec = (com_maxFPS.GetValue <int>() > 0) ? (1000 / com_maxFPS.GetValue <int>()) : 1;
            uint msec    = 0;

            do
            {
                _frameTime = EventSystem.HandleEvents();

                msec = _frameTime - _lastTime;
            } while (msec < minMsec);

            // handle time scaling
            var scale = timescale.GetValue <float>();

            msec = (uint)(msec * scale);

            if (msec < 1)
            {
                msec = 1;
            }
            else if (msec > 5000)
            {
                msec = 5000;
            }

            if (msec > 500)
            {
                Log.Write(LogLevel.Info, "Hitch warning: {0} msec frame time", msec);
            }

            DeltaTime = msec / 1000f;
            FrameMsec = msec;

            _lastTime = _frameTime;

            // process the command buffer
            Command.ExecuteBuffer();

            // handle network stuff
            NetManager.Process();

            // process game stuff
            Server.Process();

            // process client
            Client.Process();

            // more stuff (needs to be moved)
            Camera.Process();

            if (!sv_running.GetValue <bool>())
            {
                CellManager.Recenter(new[] { Camera.MainCamera.Position });
            }

            Renderer2D.InitPerFrame();
            FontManager.SetColor(Color.White);

            // camera moving
            DebugCamera.Process();

            ConsoleRenderer.Process();

            // render stuff
            if (Renderer.MakeDeviceAvailable())
            {
                Renderer.Clear();

                if (Client.State == Client.ClientState.Ingame)
                {
                    DeferredRenderer.Render3DStuff(Renderer.Device);
                }

                Renderer2D.Render(Renderer.Device);
                Renderer.Device.Present();
            }
        }