Merge branch 'master' into jgrpp

This commit is contained in:
Jonathan G Rennison
2021-04-05 17:50:39 +01:00
164 changed files with 3493 additions and 2443 deletions

View File

@@ -103,6 +103,8 @@ extern void ShowOSErrorBox(const char *buf, bool system);
extern std::string _config_file;
bool _save_config = false;
bool _request_newgrf_scan = false;
NewGRFScanCallback *_request_newgrf_scan_callback = nullptr;
GameEventFlags _game_events_since_load;
GameEventFlags _game_events_overall;
@@ -481,7 +483,6 @@ static void LoadIntroGame(bool load_newgrfs = true)
/* Load the default opening screen savegame */
if (SaveOrLoad("opntitle.dat", SLO_LOAD, DFT_GAME_FILE, BASESET_DIR) != SL_OK) {
GenerateWorld(GWM_EMPTY, 64, 64); // if failed loading, make empty world.
WaitTillGeneratedWorld();
SetLocalCompany(COMPANY_SPECTATOR);
} else {
SetLocalCompany(COMPANY_FIRST);
@@ -701,9 +702,6 @@ int openttd_main(int argc, char *argv[])
extern bool _dedicated_forks;
_dedicated_forks = false;
std::unique_lock<std::mutex> modal_work_lock(_modal_progress_work_mutex, std::defer_lock);
std::unique_lock<std::mutex> modal_paint_lock(_modal_progress_paint_mutex, std::defer_lock);
_game_mode = GM_MENU;
_switch_mode = SM_MENU;
@@ -983,34 +981,19 @@ int openttd_main(int argc, char *argv[])
if (musicdriver.empty() && !_ini_musicdriver.empty()) musicdriver = _ini_musicdriver;
DriverFactoryBase::SelectDriver(musicdriver, Driver::DT_MUSIC);
/* Take our initial lock on whatever we might want to do! */
try {
modal_work_lock.lock();
modal_paint_lock.lock();
} catch (const std::system_error&) {
/* If there is some error we assume that threads aren't usable on the system we run. */
extern bool _use_threaded_modal_progress; // From progress.cpp
_use_threaded_modal_progress = false;
}
GenerateWorld(GWM_EMPTY, 64, 64); // Make the viewport initialization happy
WaitTillGeneratedWorld();
LoadIntroGame(false);
CheckForMissingGlyphs();
/* ScanNewGRFFiles now has control over the scanner. */
ScanNewGRFFiles(scanner.release());
RequestNewGRFScan(scanner.release());
VideoDriver::GetInstance()->MainLoop();
CrashLog::MainThreadExitCheckPendingCrashlog();
AbortScanNewGRFFiles();
WaitTillSaved();
WaitTillGeneratedWorld(); // Make sure any generate world threads have been joined.
WaitUntilModalProgressCompleted();
/* only save config if we have to */
if (_save_config) {
@@ -1797,8 +1780,8 @@ void StateGameLoop()
StateGameLoop_LinkGraphPauseControl();
}
/* don't execute the state loop during pause */
if (_pause_mode != PM_UNPAUSED) {
/* Don't execute the state loop during pause or when modal windows are open. */
if (_pause_mode != PM_UNPAUSED || HasModalProgress()) {
PerformanceMeasurer::Paused(PFE_GAMELOOP);
PerformanceMeasurer::Paused(PFE_GL_ECONOMY);
PerformanceMeasurer::Paused(PFE_GL_TRAINS);
@@ -1807,7 +1790,7 @@ void StateGameLoop()
PerformanceMeasurer::Paused(PFE_GL_AIRCRAFT);
PerformanceMeasurer::Paused(PFE_GL_LANDSCAPE);
UpdateLandscapingLimits();
if (!HasModalProgress()) UpdateLandscapingLimits();
#ifndef DEBUG_DUMP_COMMANDS
Game::GameLoop();
#endif
@@ -1816,7 +1799,6 @@ void StateGameLoop()
PerformanceMeasurer framerate(PFE_GAMELOOP);
PerformanceAccumulator::Reset(PFE_GL_LANDSCAPE);
if (HasModalProgress()) return;
Layouter::ReduceLineCache();
@@ -1909,6 +1891,19 @@ static void DoAutosave()
}
}
/**
* Request a new NewGRF scan. This will be executed on the next game-tick.
* This is mostly needed to ensure NewGRF scans (which are blocking) are
* done in the game-thread, and not in the draw-thread (which most often
* triggers this request).
* @param callback Optional callback to call when NewGRF scan is completed.
*/
void RequestNewGRFScan(NewGRFScanCallback *callback)
{
_request_newgrf_scan = true;
_request_newgrf_scan_callback = callback;
}
void GameLoopSpecial()
{
/* autosave game? */
@@ -1939,6 +1934,14 @@ void GameLoop()
return;
}
if (_request_newgrf_scan) {
ScanNewGRFFiles(_request_newgrf_scan_callback);
_request_newgrf_scan = false;
_request_newgrf_scan_callback = nullptr;
/* In case someone closed the game during our scan, don't do anything else. */
if (_exit_game) return;
}
ProcessAsyncSaveFinish();
if (unlikely(_check_special_modes)) GameLoopSpecial();
@@ -1950,7 +1953,6 @@ void GameLoop()
}
IncreaseSpriteLRU();
InteractiveRandom();
/* Check for UDP stuff */
if (_network_available) NetworkBackgroundLoop();