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); } }