* State controlling game loop. * The state must not be changed from anywhere but here. * That check is enforced in DoCommand. */
| 1208 | * That check is enforced in DoCommand. |
| 1209 | */ |
| 1210 | void StateGameLoop() |
| 1211 | { |
| 1212 | if (!_networking || _network_server) { |
| 1213 | StateGameLoop_LinkGraphPauseControl(); |
| 1214 | } |
| 1215 | |
| 1216 | /* Don't execute the state loop during pause or when modal windows are open. */ |
| 1217 | if (_pause_mode.Any() || HasModalProgress()) { |
| 1218 | PerformanceMeasurer::Paused(PFE_GAMELOOP); |
| 1219 | PerformanceMeasurer::Paused(PFE_GL_ECONOMY); |
| 1220 | PerformanceMeasurer::Paused(PFE_GL_TRAINS); |
| 1221 | PerformanceMeasurer::Paused(PFE_GL_ROADVEHS); |
| 1222 | PerformanceMeasurer::Paused(PFE_GL_SHIPS); |
| 1223 | PerformanceMeasurer::Paused(PFE_GL_AIRCRAFT); |
| 1224 | PerformanceMeasurer::Paused(PFE_GL_LANDSCAPE); |
| 1225 | |
| 1226 | if (!HasModalProgress()) UpdateLandscapingLimits(); |
| 1227 | #ifndef DEBUG_DUMP_COMMANDS |
| 1228 | if (_game_mode == GM_NORMAL) Game::GameLoop(); |
| 1229 | #endif |
| 1230 | return; |
| 1231 | } |
| 1232 | |
| 1233 | PerformanceMeasurer framerate(PFE_GAMELOOP); |
| 1234 | PerformanceAccumulator::Reset(PFE_GL_LANDSCAPE); |
| 1235 | |
| 1236 | if (_game_mode == GM_EDITOR) { |
| 1237 | BasePersistentStorageArray::SwitchMode(PSM_ENTER_GAMELOOP); |
| 1238 | RunTileLoop(); |
| 1239 | CallVehicleTicks(); |
| 1240 | CallLandscapeTick(); |
| 1241 | BasePersistentStorageArray::SwitchMode(PSM_LEAVE_GAMELOOP); |
| 1242 | UpdateLandscapingLimits(); |
| 1243 | |
| 1244 | CallWindowGameTickEvent(); |
| 1245 | NewsLoop(); |
| 1246 | } else { |
| 1247 | if (_debug_desync_level > 2 && TimerGameEconomy::date_fract == 0 && (TimerGameEconomy::date.base() & 0x1F) == 0) { |
| 1248 | /* Save the desync savegame if needed. */ |
| 1249 | std::string name = fmt::format("dmp_cmds_{:08x}_{:08x}.sav", _settings_game.game_creation.generation_seed, TimerGameEconomy::date); |
| 1250 | SaveOrLoad(name, SLO_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR, false); |
| 1251 | } |
| 1252 | |
| 1253 | CheckCaches(); |
| 1254 | |
| 1255 | /* All these actions has to be done from OWNER_NONE |
| 1256 | * for multiplayer compatibility */ |
| 1257 | Backup<CompanyID> cur_company(_current_company, OWNER_NONE); |
| 1258 | |
| 1259 | BasePersistentStorageArray::SwitchMode(PSM_ENTER_GAMELOOP); |
| 1260 | AnimateAnimatedTiles(); |
| 1261 | if (TimerManager<TimerGameCalendar>::Elapsed(1)) { |
| 1262 | RunVehicleCalendarDayProc(); |
| 1263 | } |
| 1264 | TimerManager<TimerGameEconomy>::Elapsed(1); |
| 1265 | TimerManager<TimerGameTick>::Elapsed(1); |
| 1266 | RunTileLoop(); |
| 1267 | CallVehicleTicks(); |
no test coverage detected