mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-13 02:52:37 +00:00
(svn r21379) -Codechange: move the actual save code into a separate function
This commit is contained in:
parent
a7b9297d20
commit
bf7da9b3a8
@ -2470,6 +2470,38 @@ void WaitTillSaved()
|
|||||||
_save_thread = NULL;
|
_save_thread = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Actually perform the saving of the savegame.
|
||||||
|
* General tactic is to first save the game to memory, then write it to file
|
||||||
|
* 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 asynchroniously.
|
||||||
|
*/
|
||||||
|
static SaveOrLoadResult DoSave(SaveFilter *writer, bool threaded)
|
||||||
|
{
|
||||||
|
assert(!_ts.saveinprogress);
|
||||||
|
|
||||||
|
_sl.dumper = new MemoryDumper();
|
||||||
|
_sl.sf = writer;
|
||||||
|
|
||||||
|
_sl_version = SAVEGAME_VERSION;
|
||||||
|
|
||||||
|
SaveViewportBeforeSaveGame();
|
||||||
|
SlSaveChunks();
|
||||||
|
|
||||||
|
SaveFileStart();
|
||||||
|
if (!threaded || !ThreadObject::New(&SaveFileToDiskThread, NULL, &_save_thread)) {
|
||||||
|
if (threaded) DEBUG(sl, 1, "Cannot create savegame thread, reverting to single-threaded mode...");
|
||||||
|
|
||||||
|
SaveOrLoadResult result = SaveFileToDisk(false);
|
||||||
|
SaveFileDone();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SL_OK;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main Save or Load function where the high-level saveload functions are
|
* Main Save or Load function where the high-level saveload functions are
|
||||||
* handled. It opens the savegame, selects format and checks versions
|
* handled. It opens the savegame, selects format and checks versions
|
||||||
@ -2539,29 +2571,11 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb, boo
|
|||||||
SlError(mode == SL_SAVE ? STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE : STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE);
|
SlError(mode == SL_SAVE ? STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE : STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* General tactic is to first save the game to memory, then use an available writer
|
|
||||||
* to write it to file, either in threaded mode if possible, or single-threaded */
|
|
||||||
if (mode == SL_SAVE) { // SAVE game
|
if (mode == SL_SAVE) { // SAVE game
|
||||||
DEBUG(desync, 1, "save: %08x; %02x; %s", _date, _date_fract, filename);
|
DEBUG(desync, 1, "save: %08x; %02x; %s", _date, _date_fract, filename);
|
||||||
|
|
||||||
_sl.dumper = new MemoryDumper();
|
|
||||||
_sl.sf = new FileWriter(fh);
|
|
||||||
|
|
||||||
_sl_version = SAVEGAME_VERSION;
|
|
||||||
|
|
||||||
SaveViewportBeforeSaveGame();
|
|
||||||
SlSaveChunks();
|
|
||||||
|
|
||||||
SaveFileStart();
|
|
||||||
if (_network_server || !_settings_client.gui.threaded_saves) threaded = false;
|
if (_network_server || !_settings_client.gui.threaded_saves) threaded = false;
|
||||||
if (!threaded || !ThreadObject::New(&SaveFileToDiskThread, NULL, &_save_thread)) {
|
|
||||||
if (threaded) DEBUG(sl, 1, "Cannot create savegame thread, reverting to single-threaded mode...");
|
|
||||||
|
|
||||||
SaveOrLoadResult result = SaveFileToDisk(false);
|
return DoSave(new FileWriter(fh), threaded);
|
||||||
SaveFileDone();
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
} else { // LOAD game
|
} else { // LOAD game
|
||||||
assert(mode == SL_LOAD || mode == SL_LOAD_CHECK);
|
assert(mode == SL_LOAD || mode == SL_LOAD_CHECK);
|
||||||
DEBUG(desync, 1, "load: %s", filename);
|
DEBUG(desync, 1, "load: %s", filename);
|
||||||
|
Loading…
Reference in New Issue
Block a user