1
0
Fork 0
pull/12707/merge
TrevorShelton 2024-08-28 20:58:01 -07:00 committed by GitHub
commit 8da84a3892
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 12 deletions

View File

@ -420,13 +420,7 @@ DEF_CONSOLE_CMD(ConSave)
if (argc == 2) { if (argc == 2) {
std::string filename = argv[1]; std::string filename = argv[1];
filename += ".sav"; filename += ".sav";
IConsolePrint(CC_DEFAULT, "Saving map..."); SaveOrLoad(filename, SLO_SAVE, DFT_GAME_FILE, SAVE_DIR);
if (SaveOrLoad(filename, SLO_SAVE, DFT_GAME_FILE, SAVE_DIR) != SL_OK) {
IConsolePrint(CC_ERROR, "Saving map failed.");
} else {
IConsolePrint(CC_INFO, "Map successfully saved to '{}'.", filename);
}
return true; return true;
} }

View File

@ -2799,7 +2799,7 @@ static void SaveFileError()
* We have written the whole game into memory, _memory_savegame, now find * We have written the whole game into memory, _memory_savegame, now find
* and appropriate compressor and start writing to file. * and appropriate compressor and start writing to file.
*/ */
static SaveOrLoadResult SaveFileToDisk(bool threaded) static SaveOrLoadResult SaveFileToDisk(bool threaded, const std::string &filename)
{ {
try { try {
auto [fmt, compression] = GetSavegameFormat(_savegame_format); auto [fmt, compression] = GetSavegameFormat(_savegame_format);
@ -2815,6 +2815,8 @@ static SaveOrLoadResult SaveFileToDisk(bool threaded)
if (threaded) SetAsyncSaveFinish(SaveFileDone); if (threaded) SetAsyncSaveFinish(SaveFileDone);
Debug(sl, 1, "Map saved as '{}'.", filename);
return SL_OK; return SL_OK;
} catch (...) { } catch (...) {
ClearSaveLoadState(); ClearSaveLoadState();
@ -2834,6 +2836,7 @@ static SaveOrLoadResult SaveFileToDisk(bool threaded)
} else { } else {
asfp(); asfp();
} }
return SL_ERROR; return SL_ERROR;
} }
} }
@ -2854,9 +2857,10 @@ void WaitTillSaved()
* using the writer, either in threaded mode if possible, or single-threaded. * using the writer, either in threaded mode if possible, or single-threaded.
* @param writer The filter to write the savegame to. * @param writer The filter to write the savegame to.
* @param threaded Whether to try to perform the saving asynchronously. * @param threaded Whether to try to perform the saving asynchronously.
* @param filename The name of the savegame (when applicable).
* @return Return the result of the action. #SL_OK or #SL_ERROR * @return Return the result of the action. #SL_OK or #SL_ERROR
*/ */
static SaveOrLoadResult DoSave(std::shared_ptr<SaveFilter> writer, bool threaded) static SaveOrLoadResult DoSave(std::shared_ptr<SaveFilter> writer, bool threaded, const std::string &filename = "")
{ {
assert(!_sl.saveinprogress); assert(!_sl.saveinprogress);
@ -2870,10 +2874,10 @@ static SaveOrLoadResult DoSave(std::shared_ptr<SaveFilter> writer, bool threaded
SaveFileStart(); SaveFileStart();
if (!threaded || !StartNewThread(&_save_thread, "ottd:savegame", &SaveFileToDisk, true)) { if (!threaded || !StartNewThread(&_save_thread, "ottd:savegame", &SaveFileToDisk, true, filename)) {
if (threaded) Debug(sl, 1, "Cannot create savegame thread, reverting to single-threaded mode..."); if (threaded) Debug(sl, 1, "Cannot create savegame thread, reverting to single-threaded mode...");
SaveOrLoadResult result = SaveFileToDisk(false); SaveOrLoadResult result = SaveFileToDisk(false, filename);
SaveFileDone(); SaveFileDone();
return result; return result;
@ -3135,7 +3139,7 @@ SaveOrLoadResult SaveOrLoad(const std::string &filename, SaveLoadOperation fop,
Debug(desync, 1, "save: {:08x}; {:02x}; {}", TimerGameEconomy::date, TimerGameEconomy::date_fract, filename); Debug(desync, 1, "save: {:08x}; {:02x}; {}", TimerGameEconomy::date, TimerGameEconomy::date_fract, filename);
if (!_settings_client.gui.threaded_saves) threaded = false; if (!_settings_client.gui.threaded_saves) threaded = false;
return DoSave(std::make_shared<FileWriter>(fh), threaded); return DoSave(std::make_shared<FileWriter>(fh), threaded, filename);
} }
/* LOAD game */ /* LOAD game */