Loading

Paste #p8bxr0ans

  1. /**
  2.  * State controlling game loop.
  3.  * The state must not be changed from anywhere but here.
  4.  * That check is enforced in DoCommand.
  5.  */
  6. void StateGameLoop()
  7. {
  8.     /* don't execute the state loop during pause */
  9.     if (_pause_mode != PM_UNPAUSED) {
  10.         PerformanceMeasurer::Paused(PFE_GAMELOOP);
  11.         PerformanceMeasurer::Paused(PFE_GL_ECONOMY);
  12.         PerformanceMeasurer::Paused(PFE_GL_TRAINS);
  13.         PerformanceMeasurer::Paused(PFE_GL_ROADVEHS);
  14.         PerformanceMeasurer::Paused(PFE_GL_SHIPS);
  15.         PerformanceMeasurer::Paused(PFE_GL_AIRCRAFT);
  16.         PerformanceMeasurer::Paused(PFE_GL_LANDSCAPE);
  17.  
  18.         UpdateLandscapingLimits();
  19. #ifndef DEBUG_DUMP_COMMANDS
  20.         Game::GameLoop();
  21. #endif
  22.         return;
  23.     }
  24.  
  25.     PerformanceMeasurer framerate(PFE_GAMELOOP);
  26.     PerformanceAccumulator::Reset(PFE_GL_LANDSCAPE);
  27.     if (HasModalProgress()) return;
  28.  
  29.     Layouter::ReduceLineCache();
  30.  
  31.     bool valid_local_company = Company::IsValidID(_local_company);
  32.     if (_game_mode == GM_EDITOR) {
  33.         BasePersistentStorageArray::SwitchMode(PSM_ENTER_GAMELOOP);
  34.         RunTileLoop();
  35.         CallVehicleTicks();
  36.         CallLandscapeTick();
  37.         BasePersistentStorageArray::SwitchMode(PSM_LEAVE_GAMELOOP);
  38.         UpdateLandscapingLimits();
  39.  
  40.         CallWindowGameTickEvent();
  41.         NewsLoop();
  42.     } else {
  43.         if (_debug_desync_level > 2 && _date_fract == 0 && (_date & 0x1F) == 0) {
  44.             /* Save the desync savegame if needed. */
  45.             char name[MAX_PATH];
  46.             seprintf(name, lastof(name), "dmp_cmds_%08x_%08x.sav", _settings_game.game_creation.generation_seed, _date);
  47.             SaveOrLoad(name, SLO_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR, false);
  48.         }
  49.  
  50.         CheckCaches();
  51.  
  52.         /* All these actions has to be done from OWNER_NONE
  53.          *  for multiplayer compatibility */
  54.         Backup<CompanyByte> cur_company(_current_company, OWNER_NONE, FILE_LINE);
  55.  
  56.         BasePersistentStorageArray::SwitchMode(PSM_ENTER_GAMELOOP);
  57.         AnimateAnimatedTiles();
  58.         IncreaseDate();
  59.         RunTileLoop();
  60.         CallVehicleTicks();
  61.         CallLandscapeTick();
  62.         BasePersistentStorageArray::SwitchMode(PSM_LEAVE_GAMELOOP);
  63.  
  64. #ifndef DEBUG_DUMP_COMMANDS
  65.         AI::GameLoop();
  66.         Game::GameLoop();
  67. #endif
  68.         UpdateLandscapingLimits();
  69.  
  70.         CallWindowGameTickEvent();
  71.         NewsLoop();
  72.         cur_company.Restore();
  73.     }
  74.  
  75.     assert(IsLocalCompany());
  76.     if (valid_local_company && !Company::IsValidID(_local_company)) {
  77.         SetLocalCompany(COMPANY_SPECTATOR);
  78.     }
  79. }

Comments