Reduce delays with company bankrupcty/sale processing at high day lengths

This commit is contained in:
Jonathan G Rennison
2022-09-02 18:14:35 +01:00
parent 23fa7cd239
commit 3d857333c8
3 changed files with 13 additions and 8 deletions

View File

@@ -737,14 +737,20 @@ static void HandleBankruptcyTakeover(Company *c)
} }
/** Called every tick for updating some company info. */ /** Called every tick for updating some company info. */
void OnTick_Companies() void OnTick_Companies(bool main_tick)
{ {
if (_game_mode == GM_EDITOR) return; if (_game_mode == GM_EDITOR) return;
Company *c = Company::GetIfValid(_cur_company_tick_index); if (main_tick) {
if (c != nullptr) { Company *c = Company::GetIfValid(_cur_company_tick_index);
if (c != nullptr) {
if (c->bankrupt_asked != 0) HandleBankruptcyTakeover(c);
}
_cur_company_tick_index = (_cur_company_tick_index + 1) % MAX_COMPANIES;
}
for (Company *c : Company::Iterate()) {
if (c->name_1 != 0) GenerateCompanyName(c); if (c->name_1 != 0) GenerateCompanyName(c);
if (c->bankrupt_asked != 0) HandleBankruptcyTakeover(c); if (c->bankrupt_asked != 0 && c->bankrupt_timeout == 0) HandleBankruptcyTakeover(c);
} }
if (_next_competitor_start == 0) { if (_next_competitor_start == 0) {
@@ -762,8 +768,6 @@ void OnTick_Companies()
if (_networking) break; if (_networking) break;
} while (AI::GetStartNextTime() == 0); } while (AI::GetStartNextTime() == 0);
} }
_cur_company_tick_index = (_cur_company_tick_index + 1) % MAX_COMPANIES;
} }
/** /**

View File

@@ -1660,7 +1660,6 @@ void OnTick_Trees();
void OnTick_Station(); void OnTick_Station();
void OnTick_Industry(); void OnTick_Industry();
void OnTick_Companies();
void OnTick_LinkGraph(); void OnTick_LinkGraph();
void CallLandscapeTick() void CallLandscapeTick()
@@ -1674,6 +1673,5 @@ void CallLandscapeTick()
OnTick_Industry(); OnTick_Industry();
} }
OnTick_Companies();
OnTick_LinkGraph(); OnTick_LinkGraph();
} }

View File

@@ -109,6 +109,7 @@ void MusicLoop();
void ResetMusic(); void ResetMusic();
void CallWindowGameTickEvent(); void CallWindowGameTickEvent();
bool HandleBootstrap(); bool HandleBootstrap();
void OnTick_Companies(bool main_tick);
extern void ShowOSErrorBox(const char *buf, bool system); extern void ShowOSErrorBox(const char *buf, bool system);
extern std::string _config_file; extern std::string _config_file;
@@ -1938,6 +1939,7 @@ void StateGameLoop()
if (_tick_skip_counter < _settings_game.economy.day_length_factor) { if (_tick_skip_counter < _settings_game.economy.day_length_factor) {
AnimateAnimatedTiles(); AnimateAnimatedTiles();
CallVehicleTicks(); CallVehicleTicks();
OnTick_Companies(false);
} else { } else {
_tick_skip_counter = 0; _tick_skip_counter = 0;
IncreaseDate(); IncreaseDate();
@@ -1945,6 +1947,7 @@ void StateGameLoop()
RunTileLoop(); RunTileLoop();
CallVehicleTicks(); CallVehicleTicks();
CallLandscapeTick(); CallLandscapeTick();
OnTick_Companies(true);
} }
BasePersistentStorageArray::SwitchMode(PSM_LEAVE_GAMELOOP); BasePersistentStorageArray::SwitchMode(PSM_LEAVE_GAMELOOP);