1
0
Fork 0

Fix #12391: Fixed console save message timings and altered when they appear.

pull/12707/head
Trevor Shelton 2024-05-20 18:12:20 -07:00
parent 5442b0dd2d
commit b4ad8c1bb6
2 changed files with 13 additions and 12 deletions

View File

@ -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;
}

View File

@ -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<SaveFilter> writer, bool threaded)
static SaveOrLoadResult DoSave(std::shared_ptr<SaveFilter> writer, bool threaded, const std::string &filename = "")
{
assert(!_sl.saveinprogress);
@ -2886,10 +2892,10 @@ static SaveOrLoadResult DoSave(std::shared_ptr<SaveFilter> 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<FileWriter>(fh), threaded);
return DoSave(std::make_shared<FileWriter>(fh), threaded, filename);
}
/* LOAD game */