From b4ad8c1bb6ec133f61ddb1c8d1fffd127ce48599 Mon Sep 17 00:00:00 2001 From: Trevor Shelton Date: Mon, 20 May 2024 18:12:20 -0700 Subject: [PATCH 1/2] Fix #12391: Fixed console save message timings and altered when they appear. --- src/console_cmds.cpp | 8 +------- src/saveload/saveload.cpp | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index f4bbdc9d65..f7e3452c64 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -402,13 +402,7 @@ DEF_CONSOLE_CMD(ConSave) if (argc == 2) { std::string filename = argv[1]; filename += ".sav"; - IConsolePrint(CC_DEFAULT, "Saving map..."); - - 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); - } + SaveOrLoad(filename, SLO_SAVE, DFT_GAME_FILE, SAVE_DIR); return true; } diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index ded1a83467..d9ecb80f0f 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -21,6 +21,7 @@ */ #include "../stdafx.h" +#include "../console_func.h" #include "../debug.h" #include "../station_base.h" #include "../thread.h" @@ -2814,7 +2815,7 @@ static void SaveFileError() * We have written the whole game into memory, _memory_savegame, now find * and appropriate compressor and start writing to file. */ -static SaveOrLoadResult SaveFileToDisk(bool threaded) +static SaveOrLoadResult SaveFileToDisk(bool threaded, const std::string &filename) { try { uint8_t compression; @@ -2831,6 +2832,8 @@ static SaveOrLoadResult SaveFileToDisk(bool threaded) if (threaded) SetAsyncSaveFinish(SaveFileDone); + IConsolePrint(CC_INFO, "Saved successfully as '{}'.", filename); + return SL_OK; } catch (...) { ClearSaveLoadState(); @@ -2850,6 +2853,8 @@ static SaveOrLoadResult SaveFileToDisk(bool threaded) } else { asfp(); } + + IConsolePrint(CC_ERROR, "Saving map failed."); return SL_ERROR; } } @@ -2870,9 +2875,10 @@ void WaitTillSaved() * using the writer, either in threaded mode if possible, or single-threaded. * @param writer The filter to write the savegame to. * @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 */ -static SaveOrLoadResult DoSave(std::shared_ptr writer, bool threaded) +static SaveOrLoadResult DoSave(std::shared_ptr writer, bool threaded, const std::string &filename = "") { assert(!_sl.saveinprogress); @@ -2886,10 +2892,10 @@ static SaveOrLoadResult DoSave(std::shared_ptr writer, bool threaded 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..."); - SaveOrLoadResult result = SaveFileToDisk(false); + SaveOrLoadResult result = SaveFileToDisk(false, filename); SaveFileDone(); return result; @@ -3148,10 +3154,11 @@ SaveOrLoadResult SaveOrLoad(const std::string &filename, SaveLoadOperation fop, } if (fop == SLO_SAVE) { // SAVE game + IConsolePrint(CC_DEFAULT, "Saving map..."); Debug(desync, 1, "save: {:08x}; {:02x}; {}", TimerGameEconomy::date, TimerGameEconomy::date_fract, filename); if (!_settings_client.gui.threaded_saves) threaded = false; - return DoSave(std::make_shared(fh), threaded); + return DoSave(std::make_shared(fh), threaded, filename); } /* LOAD game */ From 8355fde6f5cd915ec50fff5d7f72868966f18d40 Mon Sep 17 00:00:00 2001 From: Trevor Shelton Date: Tue, 21 May 2024 08:20:24 -0700 Subject: [PATCH 2/2] Fix: Altered saving messages to go to debug, removing now unnecessary things and the "Saving Map" message. --- src/saveload/saveload.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index d9ecb80f0f..3a6e99ebf9 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -21,7 +21,6 @@ */ #include "../stdafx.h" -#include "../console_func.h" #include "../debug.h" #include "../station_base.h" #include "../thread.h" @@ -2832,7 +2831,7 @@ static SaveOrLoadResult SaveFileToDisk(bool threaded, const std::string &filenam if (threaded) SetAsyncSaveFinish(SaveFileDone); - IConsolePrint(CC_INFO, "Saved successfully as '{}'.", filename); + Debug(sl, 1, "Map saved as '{}'.", filename); return SL_OK; } catch (...) { @@ -2854,7 +2853,6 @@ static SaveOrLoadResult SaveFileToDisk(bool threaded, const std::string &filenam asfp(); } - IConsolePrint(CC_ERROR, "Saving map failed."); return SL_ERROR; } } @@ -3154,7 +3152,6 @@ SaveOrLoadResult SaveOrLoad(const std::string &filename, SaveLoadOperation fop, } if (fop == SLO_SAVE) { // SAVE game - IConsolePrint(CC_DEFAULT, "Saving map..."); Debug(desync, 1, "save: {:08x}; {:02x}; {}", TimerGameEconomy::date, TimerGameEconomy::date_fract, filename); if (!_settings_client.gui.threaded_saves) threaded = false;