Example #1
0
 public InputManager()
 {
     PrevInput    = new FrameInput();
     CurrentInput = new FrameInput();
 }
Example #2
0
 public void SetMetaInput(FrameInput input)
 {
     MetaInputManager.SetFrameInput(input);
 }
Example #3
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            //Updating completely ignores delta time and updates by-frames
            //It also waits until drawing ends (which is locked at 60FPS) to ensure that updating does not take *shorter* than 1/60 of a second
            //This is because the following needs to be achieved:
            //Perfect simulation whether the updates were fast or slow
            //And for the game to not frame skip if the updates were too slow (deltatime too high), even if it meant slowing down the game itself.
            if (!drawTurn)
            {
                if (!firstUpdate && CurrentPhase > LoadPhase.System)
                {
                    splashFrames++;
                    if (backgroundLoaded)
                    {
                        if (DiagManager.Instance.DevMode)
                        {
                            DiagManager.Instance.DevEditor.Load();
                            while (!DiagManager.Instance.DevEditor.Loaded)
                            {
                                Thread.Sleep(10);
                            }

                            CurrentPhase = LoadPhase.Ready;
                        }
                        else if (fadeFrames == 0)
                        {
                            if (Keyboard.GetState().GetPressedKeys().Length > 0 || GamePad.GetState(PlayerIndex.One).Buttons != new GamePadButtons())
                            {
                                fadeFrames++;
                            }
                        }
                        else
                        {
                            if (fadeFrames < SPLASH_FADE_FRAMES)
                            {
                                fadeFrames++;
                            }
                            else
                            {
                                CurrentPhase = LoadPhase.Ready;
                            }
                        }
                    }
                }

                if (CurrentPhase == LoadPhase.Ready)
                {
                    try
                    {
                        SoundManager.NewFrame();
                        GraphicsManager.Update();

                        FrameInput input = new FrameInput();
                        if (DiagManager.Instance.ActiveDebugReplay != null && DiagManager.Instance.DebugReplayIndex < DiagManager.Instance.ActiveDebugReplay.Count)
                        {
                            input = DiagManager.Instance.ActiveDebugReplay[DiagManager.Instance.DebugReplayIndex];
                            DiagManager.Instance.DebugReplayIndex++;
                            if (IsActive)
                            {
                                input.ReadDevInput(Keyboard.GetState(), Mouse.GetState());
                            }
                        }
                        else if (IsActive) //set this frame's input
                        {
                            input = new FrameInput(GamePad.GetState(PlayerIndex.One), Keyboard.GetState(), Mouse.GetState());
                        }

                        if (DiagManager.Instance.ActiveDebugReplay == null)
                        {
                            DiagManager.Instance.LogInput(input);
                        }
                        GameManager.Instance.SetMetaInput(input);
                        GameManager.Instance.UpdateMeta();
                        GameManager.Instance.SetFrameInput(input);
                        GameManager.Instance.Update();
                        LuaEngine.Instance.Update(gameTime);
                    }
                    catch (Exception ex)
                    {
                        DiagManager.Instance.LogError(ex);
                    }

                    firstUpdate = true;//allow drawing now
                }
                else if (CurrentPhase == LoadPhase.Unload)
                {
                    Exit();
                }
                drawTurn = true;
            }
            base.Update(gameTime);
        }