public GameLoop(Game game, IFullscreenService fullscreenService, IMetricsService metricsHandler, IUpdateService updateChecker) { MetricsHandler = metricsHandler; UpdateChecker = updateChecker; #if WINDOWS || MONOMAC if (METRICS_ENABLED) { Global.metrics_allowed = true; } #endif if (Config.UPDATE_CHECK_ENABLED) { Global.update_check_allowed = true; } //@Yeti: make this work without Global later? GameSettings = new Settings(); Global.gameSettings = GameSettings; Game = game; Renderer = new GameRenderer(game, fullscreenService); IOHandler = new GameIOHandler(this, Renderer); #if !MONOGAME // Setup our OpenALSoundController to handle our SoundBuffer pools OpenALInterface.create_sound_controller(); #endif }
public IEnumerable <GameTime> Update(GameTime gameTime) { KeyboardState keyState = Keyboard.GetState(); GamePadState controllerState = GamePad.GetState(PlayerIndex.One); #if !MONOGAME OpenALInterface.update(); #endif #if DEBUG // Stereoscopy debugging if (Tactile.Global.Input.pressed(Inputs.Select)) { if (Global.Input.triggered(Inputs.Right)) { Global.gameSettings.Graphics.ConfirmSetting( Tactile.Options.GraphicsSetting.Stereoscopic, 0, Global.gameSettings.Graphics.StereoscopicLevel + 5); } if (Global.Input.triggered(Inputs.Left)) { Global.gameSettings.Graphics.ConfirmSetting( Tactile.Options.GraphicsSetting.Stereoscopic, 0, Global.gameSettings.Graphics.StereoscopicLevel - 5); } } #endif // If changing zoom or fullscreen, return if (UpdateZoom()) { PreviousKeyState = keyState; yield break; } int updateLoops = UpdateFramerate(gameTime, keyState, controllerState); UpdateInitialLoad(); int i; for (i = 0; ; i++) { if (!Paused) { Global.update_input(Game, gameTime, Game.IsActive, keyState, controllerState); Global.Rumble.Update(gameTime); Renderer.UpdateTouch(); } UpdatePause(keyState, controllerState); bool processNextFrame = (!Paused || FrameAdvanced); if (i > 0) { #if !MONOGAME OpenALInterface.update(); #endif } // Don't update audio handling when the game is paused, // to better debug fades etc if (processNextFrame) { Global.Audio.update(GameInactive); } Stereoscopic_Graphic_Object.update_stereoscopy(); UpdateIO(); UpdateSceneChange(); if (Global.scene != null) { // Suspend IOHandler.UpdateSuspend(); // Update Scene if (processNextFrame) { UpdateScene(gameTime, keyState, controllerState); } } yield return(gameTime); if (updateLoops > 1) { float updateLoopTime = (float)(HyperspeedStopWatch.ElapsedTicks / ((double)Stopwatch.Frequency)); // If a normal frame worth of time has passed, or if the fixed number of hyperspeed loops have occurred if (updateLoopTime > 1f / FRAME_RATE || i >= updateLoops - 1) { break; } #if DEBUG || GET_FPS else { FramerateFrames++; } #endif } else { break; } } UpdateOpenGameSite(); Global.Audio.post_update(); Renderer.UpdateScreenScale(); UpdateTextGlow(i + 1); HyperspeedStopWatch.Stop(); //@Debug PreviousKeyState = keyState; }