mirror of https://github.com/OpenTTD/OpenTTD
Fix #12391: Fixed console save message timings and altered when they appear.
parent
5442b0dd2d
commit
b4ad8c1bb6
|
@ -402,13 +402,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../stdafx.h"
|
#include "../stdafx.h"
|
||||||
|
#include "../console_func.h"
|
||||||
#include "../debug.h"
|
#include "../debug.h"
|
||||||
#include "../station_base.h"
|
#include "../station_base.h"
|
||||||
#include "../thread.h"
|
#include "../thread.h"
|
||||||
|
@ -2814,7 +2815,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 {
|
||||||
uint8_t compression;
|
uint8_t compression;
|
||||||
|
@ -2831,6 +2832,8 @@ static SaveOrLoadResult SaveFileToDisk(bool threaded)
|
||||||
|
|
||||||
if (threaded) SetAsyncSaveFinish(SaveFileDone);
|
if (threaded) SetAsyncSaveFinish(SaveFileDone);
|
||||||
|
|
||||||
|
IConsolePrint(CC_INFO, "Saved successfully as '{}'.", filename);
|
||||||
|
|
||||||
return SL_OK;
|
return SL_OK;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ClearSaveLoadState();
|
ClearSaveLoadState();
|
||||||
|
@ -2850,6 +2853,8 @@ static SaveOrLoadResult SaveFileToDisk(bool threaded)
|
||||||
} else {
|
} else {
|
||||||
asfp();
|
asfp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IConsolePrint(CC_ERROR, "Saving map failed.");
|
||||||
return SL_ERROR;
|
return SL_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2870,9 +2875,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);
|
||||||
|
|
||||||
|
@ -2886,10 +2892,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;
|
||||||
|
@ -3148,10 +3154,11 @@ SaveOrLoadResult SaveOrLoad(const std::string &filename, SaveLoadOperation fop,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fop == SLO_SAVE) { // SAVE game
|
if (fop == SLO_SAVE) { // SAVE game
|
||||||
|
IConsolePrint(CC_DEFAULT, "Saving map...");
|
||||||
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 */
|
||||||
|
|
Loading…
Reference in New Issue