/// <summary> /// Called every frame /// </summary> /// <param name="gameTime">The current time</param> public void Update(DwarfTime gameTime) { foreach (var func in LazyActions) { if (func != null) { func.Invoke(); } } LazyActions.Clear(); if (FastForwardToDay) { if (Time.IsDay()) { FastForwardToDay = false; foreach (CreatureAI minion in Master.Faction.Minions) { minion.Status.Energy.CurrentValue = minion.Status.Energy.MaxValue; } //Master.ToolBar.SpeedButton.SetSpeed(1); Time.Speed = 100; } else { //Master.ToolBar.SpeedButton.SetSpecialSpeed(3); Time.Speed = 1000; } } //ParticleManager.Trigger("dice", CursorLightPos + Vector3.Up, Color.White, 1); FillClosestLights(gameTime); IndicatorManager.Update(gameTime); AspectRatio = GraphicsDevice.Viewport.AspectRatio; Camera.AspectRatio = AspectRatio; Camera.Update(gameTime, ChunkManager); HandleAmbientSound(); Master.Update(Game, gameTime); GoalManager.Update(this); Time.Update(gameTime); if (LastWorldPopup != null) { List <uint> removals = new List <uint>(); foreach (var popup in LastWorldPopup) { popup.Value.Update(gameTime, Camera, GraphicsDevice.Viewport); if (popup.Value.Widget == null || !Gui.RootItem.Children.Contains(popup.Value.Widget) || popup.Value.BodyToTrack == null || popup.Value.BodyToTrack.IsDead) { removals.Add(popup.Key); } } foreach (var removal in removals) { if (LastWorldPopup[removal].Widget != null && Gui.RootItem.Children.Contains(LastWorldPopup[removal].Widget)) { Gui.DestroyWidget(LastWorldPopup[removal].Widget); } LastWorldPopup.Remove(removal); } } if (Paused) { ComponentManager.UpdatePaused(gameTime, ChunkManager, Camera); TutorialManager.Update(Gui); } // If not paused, we want to just update the rest of the game. else { ParticleManager.Update(gameTime, this); TutorialManager.Update(Gui); Diplomacy.Update(gameTime, Time.CurrentDate, this); Factions.Update(gameTime); ComponentManager.Update(gameTime, ChunkManager, Camera); Sky.TimeOfDay = Time.GetSkyLightness(); Sky.CosTime = (float)(Time.GetTotalHours() * 2 * Math.PI / 24.0f); DefaultShader.TimeOfDay = Sky.TimeOfDay; MonsterSpawner.Update(gameTime); bool allAsleep = Master.AreAllEmployeesAsleep(); #if !UPTIME_TEST if (SleepPrompt == null && allAsleep && !FastForwardToDay && Time.IsNight()) { SleepPrompt = new QueuedAnnouncement() { Text = "All your employees are asleep. Click here to skip to day.", ClickAction = (sender, args) => { FastForwardToDay = true; SleepPrompt = null; }, ShouldKeep = () => { return(FastForwardToDay == false && Time.IsNight() && Master.AreAllEmployeesAsleep()); } }; MakeAnnouncement(SleepPrompt); } else if (!allAsleep) { Time.Speed = 100; FastForwardToDay = false; SleepPrompt = null; } #endif } // These things are updated even when the game is paused Splasher.Splash(gameTime, ChunkManager.Water.GetSplashQueue()); ChunkManager.Update(gameTime, Camera, GraphicsDevice); ChunkRenderer.Update(gameTime, Camera, GraphicsDevice); SoundManager.Update(gameTime, Camera, Time); Weather.Update(this.Time.CurrentDate, this); if (gameFile != null) { // Cleanup game file. gameFile = null; } #if DEBUG KeyboardState k = Keyboard.GetState(); if (k.IsKeyDown(Keys.Home)) { try { GameState.Game.GraphicsDevice.Reset(); } catch (Exception exception) { } } #endif }
/// <summary> /// Called every frame /// </summary> /// <param name="gameTime">The current time</param> public void Update(DwarfTime gameTime) { EntityFactory.DoLazyActions(); if (FastForwardToDay) { if (Time.IsDay()) { FastForwardToDay = false; foreach (CreatureAI minion in Master.Faction.Minions) { minion.Status.Energy.CurrentValue = minion.Status.Energy.MaxValue; } //Master.ToolBar.SpeedButton.SetSpeed(1); Time.Speed = 100; } else { //Master.ToolBar.SpeedButton.SetSpecialSpeed(3); Time.Speed = 1000; } } //Drawer3D.DrawPlane(0, Camera.Position.X - 1500, Camera.Position.Z - 1500, Camera.Position.X + 1500, Camera.Position.Z + 1500, Color.Black); FillClosestLights(gameTime); IndicatorManager.Update(gameTime); AspectRatio = GraphicsDevice.Viewport.AspectRatio; Camera.AspectRatio = AspectRatio; Camera.Update(gameTime, ChunkManager); HandleAmbientSound(); Master.Update(Game, gameTime); GoalManager.Update(this); Time.Update(gameTime); if (Paused) { ComponentManager.UpdatePaused(); } // If not paused, we want to just update the rest of the game. else { TutorialManager.Update(Gui); GamePerformance.Instance.StartTrackPerformance("Diplomacy"); Diplomacy.Update(gameTime, Time.CurrentDate, this); GamePerformance.Instance.StopTrackPerformance("Diplomacy"); GamePerformance.Instance.StartTrackPerformance("Factions"); Factions.Update(gameTime); GamePerformance.Instance.StopTrackPerformance("Factions"); GamePerformance.Instance.StartTrackPerformance("Components"); ComponentManager.Update(gameTime, ChunkManager, Camera); GamePerformance.Instance.StopTrackPerformance("Components"); Sky.TimeOfDay = Time.GetSkyLightness(); Sky.CosTime = (float)(Time.GetTotalHours() * 2 * Math.PI / 24.0f); DefaultShader.TimeOfDay = Sky.TimeOfDay; GamePerformance.Instance.StartTrackPerformance("Monster Spawner"); MonsterSpawner.Update(gameTime); GamePerformance.Instance.StopTrackPerformance("Monster Spawner"); GamePerformance.Instance.StartTrackPerformance("All Asleep"); bool allAsleep = Master.AreAllEmployeesAsleep(); #if !UPTIME_TEST if (SleepPrompt == null && allAsleep && !FastForwardToDay && Time.IsNight()) { SleepPrompt = Gui.ConstructWidget(new Gui.Widgets.Confirm { Text = "All of your employees are asleep. Skip to daytime?", OkayText = "Skip to Daytime", CancelText = "Don't Skip", OnClose = (sender) => { if ((sender as Confirm).DialogResult == Confirm.Result.OKAY) { FastForwardToDay = true; } } }); Gui.ShowModalPopup(SleepPrompt); } else if (!allAsleep) { if (SleepPrompt != null) { SleepPrompt.Close(); } Time.Speed = 100; FastForwardToDay = false; SleepPrompt = null; } #endif GamePerformance.Instance.StopTrackPerformance("All Asleep"); } // These things are updated even when the game is paused GamePerformance.Instance.StartTrackPerformance("Chunk Manager"); ChunkManager.Update(gameTime, Camera, GraphicsDevice); ChunkRenderer.Update(gameTime, Camera, GraphicsDevice); GamePerformance.Instance.StopTrackPerformance("Chunk Manager"); GamePerformance.Instance.StartTrackPerformance("Sound Manager"); SoundManager.Update(gameTime, Camera, Time); GamePerformance.Instance.StopTrackPerformance("Sound Manager"); GamePerformance.Instance.StartTrackPerformance("Weather"); Weather.Update(this.Time.CurrentDate, this); GamePerformance.Instance.StopTrackPerformance("Weather"); if (gameFile != null) { // Cleanup game file. gameFile = null; } }