public void DrawUi() { Render.StandardRenderSetup(); if (GameClass.Game.UnitDisplayEnabled && MyPlayerValue != 0) { DrawSelectedInfo(); } DrawMouseUi(AfterUi: true); if (MyPlayerNumber == 0) { return; } Render.StartText(); DrawUiText(); //MapEditorUiText(); Render.EndText(); }
public void Draw() { ProcessInbox(); DrawCount++; Render.StandardRenderSetup(); double PreviousSecondsSinceLastUpdate = SecondsSinceLastUpdate; if (!DesyncPause) { CheckIfShouldPause(); CheckIfShouldShowWaiting(); } if (GameClass.GameActive && !ServerPaused && !DesyncPause) { if (NotPaused_SimulationUpdate) { double Elapsed = GameClass.DeltaT; //GameClass.ElapsedSeconds; if (SimStep + SecondsSinceLastUpdate / DelayBetweenUpdates < ServerSimStep - .25f) { Elapsed *= 1.15f; if (Log.SpeedMods) { Console.WriteLine(" -- Speed up please, Elasped = {3} # {0}/{1} :{2}", Elapsed, SimStep, ServerSimStep, SecondsSinceLastUpdate / DelayBetweenUpdates); } } SecondsSinceLastUpdate += Elapsed; T += (float)Elapsed; } else { DataGroup.PausedSimulationUpdate(); if (MapEditorActive) { SecondsSinceLastUpdate += DelayBetweenUpdates; T += (float)DelayBetweenUpdates; } } if (GameClass.HasFocus) { switch (CurUserMode) { case UserMode.PlaceBuilding: if (UnselectAll) { SelectionUpdate(SelectSize); UnselectAll = false; } Update_BuildingPlacing(); break; case UserMode.Painting: if (UnselectAll || MapEditorActive) { SelectionUpdate(SelectSize); UnselectAll = false; } Update_Painting(); break; case UserMode.Select: SelectionUpdate(SelectSize, LineSelect: LineSelect); break; case UserMode.CastSpell: if (LeftMousePressed && MyPlayerInfo != null) { if (!MyPlayerInfo.DragonLordAlive) { Message_NoDragonLordMagic(); } else if (MyPlayerInfo.CanAffordSpell(CurSpell)) { CastSpell(CurSpell); } else { Message_InsufficientJade(); } } break; } } SkipNextSelectionUpdate = false; if (Program.Server) { if (SecondsSinceLastUpdate / DelayBetweenUpdates > .75f && SimStep == ServerSimStep && !SentBookend) { if (Log.UpdateSim) { Console.WriteLine("Ready for bookend. {0}/{1} : {2}", SimStep, ServerSimStep, SecondsSinceLastUpdate / DelayBetweenUpdates); } SentBookend = true; AckSimStep = ServerSimStep + 2; Networking.ToClients(new MessageBookend(ServerSimStep + 1)); } } // Check if post-upate calculation still need to be done if (!PostUpdateFinished) { PostSimulationUpdate(); } // Check if we need to do a simulation update //if (true) //Console.WriteLine(ServerSimStep); if (GameClass.UnlimitedSpeed || SecondsSinceLastUpdate > DelayBetweenUpdates || SimStep + 2 < ServerSimStep) { if (SimStep < ServerSimStep && !(Program.Server && MinClientSimStep + 2 < ServerSimStep)) { WaitingTime = 0; if (!PostUpdateFinished) { PostSimulationUpdate(); // If we are behind do another post-sim update to help catchup. } else { SecondsSinceLastUpdate -= DelayBetweenUpdates; if (SecondsSinceLastUpdate < 0) { SecondsSinceLastUpdate = 0; } HashCheck(); DeququeActions(SimStep + 1); HashCheck(); SimulationUpdate(); if (!Program.Spectate || Program.Spectate && SimStep % 15 == 0) { HashCheck(Send: true); } SentBookend = false; Networking.ToServer(new MessageStartingStep(SimStep)); if (Log.UpdateSim) { Console.WriteLine("Just updated sim # {0}/{1} : {2} min={3}", SimStep, ServerSimStep, SecondsSinceLastUpdate / DelayBetweenUpdates, MinClientSimStep); } } } else { WaitingTime += GameClass.ElapsedSeconds; if (Log.Delays) { Console.WriteLine("-Reverting from # {0}/{1} : {2}", SimStep, ServerSimStep, SecondsSinceLastUpdate / DelayBetweenUpdates); } SecondsSinceLastUpdate = DelayBetweenUpdates; T -= (float)GameClass.ElapsedSeconds; if (Log.Delays) { Console.WriteLine("-Reverting to # {0}/{1} : {2}", SimStep, ServerSimStep, SecondsSinceLastUpdate / DelayBetweenUpdates); } } } else { if (Program.Server) { if (Log.Draws) { Console.WriteLine("Draw step {0}, {1}", DrawCount, SecondsSinceLastUpdate / DelayBetweenUpdates); } } } } BenchmarkTests.Run(DataGroup.CurrentData, DataGroup.PreviousData); if (!Program.Headless) { try { DrawWorld(); } catch (Exception e) { } } else { GridHelper.GraphicsDevice.SetRenderTarget(null); } }
void GameLogic(GameTime gameTime) { //Send("setMode", "in-game"); //Send("setScreen", "in-game-ui"); switch (State) { case GameState.ToEditor: NewWorldEditor(); State = GameState.Game; Send("setMode", "in-game"); Send("setScreen", "editor-ui"); break; case GameState.ToMap: Render.StandardRenderSetup(); DrawFullScreen(Assets.ScreenLoading); if (Program.StartupMap == null) { Program.StartupMap = "Beset.m3n"; } SetScenarioToLoad(Program.StartupMap); break; case GameState.TitleScreen: StartMenuMusicIfNeeded(); AmbientSounds.EndAll(); // No mouse input to web browser. SteamWrapper.SteamHtml.AllowMouseEvents = false; Render.StandardRenderSetup(); DrawFullScreen(Assets.ScreenTitle); if (gameTime.TotalGameTime.Seconds < .005f) { break; } if (MouseMovedSome) { World.DrawArrowCursor(); } else { if (Input.DeltaMousPos.Length() > 40) { MouseMovedSome = true; } } if (InputHelper.SomethingPressed()) { State = GameState.MainMenu; Send("setMode", "main-menu"); Send("setScreen", "game-menu"); } break; case GameState.MainMenu: StartMenuMusicIfNeeded(); AmbientSounds.EndAll(); if (!InputHelper.SomethingDown()) { SteamWrapper.SteamHtml.AllowMouseEvents = true; } if (_MapLoading != MapLoading) { _MapLoading = MapLoading; SetMapLoading(); } if (MapLoading && NewMap != null) { World = NewMap; MapLoading = false; SetMapLoading(); } Render.StandardRenderSetup(); if (DrawMapPreview && World != null && World.DataGroup != null) { Render.UnsetDevice(); try { World.DataGroup.UpdateGradient_ToPlayers(); World.DataGroup.UpdateGradient_ToBuildings(); World.DataGroup.UpdateGradient_ToPlayers(); World.DataGroup.UpdateGradient_ToBuildings(); } catch { } World.UpdateMinimap(); GridHelper.GraphicsDevice.SetRenderTarget(null); } Render.StandardRenderSetup(); DrawFullScreen(Assets.ScreenDark); DrawWebView(); if (DrawMapPreview && World != null && World.DataGroup != null) { MapPreviewPos = new vec2(0.76f, 0.32f); MapPreviewSize = new vec2(.4f, .4f); bool UseSolidColor = MapLoading || World == BlankWorld; World.DrawMinimap(MapPreviewPos, MapPreviewSize, ShowCameraBox: false, SolidColor: UseSolidColor); } World.DrawArrowCursor(); break; case GameState.Loading: FadeOutMenuMusicIfNeeded(); PreGame(); Render.StandardRenderSetup(); DrawFullScreen(Assets.ScreenLoading); if (ScenarioToLoad != null) { Send("setMode", "in-game"); Send("setScreen", "in-game-ui"); World = new World( GameParams: Program.StartupGameParams, RemoveComputerDragonLords: Program.RemoveComputerDragonLords); TimeLoading = 0; World.LoadPlayerInfo = false; World.Load(Path.Combine(MapDirectory, ScenarioToLoad)); Program.WorldLoaded = true; Networking.ToServer(new Message(MessageType.DoneLoading)); ScenarioToLoad = null; TimeSinceLoad = 0; DrawFullScreen(Assets.ScreenLoading); GetNames(); //World.SaveCurrentStateInBuffer(); ////var m = new MessageGameState(World.SimStep, World.WorldBytes); //var m = new Message(MessageType.DoneLoading); //var s = m.Encode(); //Networking.SendString(new SteamPlayer(SteamCore.PlayerId()), s); //var t = Networking.ReceiveString(); //var _s = t.Item2; //Console.WriteLine("!"); } if (Program.GameStarted) { if (Program.Spectate) { State = GameState.Game; } } else { TimeLoading += DeltaT; if (TimeLoading > 25) { OnFailedToJoinGame(); } TimeSinceLoad = 0; break; } FadeOutLoading(); break; case GameState.Game: StartGameMusicIfNeeded(); CalculateMouseDownOverUi(); DrawGame(gameTime); if (Program.Spectate && ShouldDrawFading()) { Render.StandardRenderSetup(); DrawFullScreen(Assets.ScreenLoading); FadeOutLoading(); } else { DrawWebView(); World.DrawUi(); if (TimeSinceLoad < 1.5f) { BlackOverlay(1f - (float)(TimeSinceLoad - 1.3f) / .2f); } } break; } }