MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / SaveFileToDisk

Function SaveFileToDisk

src/saveload/saveload.cpp:2989–3026  ·  view source on GitHub ↗

* We have written the whole game into memory, _memory_savegame, now find * and appropriate compressor and start writing to file. */

Source from the content-addressed store, hash-verified

2987 * and appropriate compressor and start writing to file.
2988 */
2989static SaveOrLoadResult SaveFileToDisk(bool threaded)
2990{
2991 try {
2992 auto [fmt, compression] = GetSavegameFormat(_savegame_format);
2993
2994 /* We have written our stuff to memory, now write it to file! */
2995 uint32_t hdr[2] = { fmt.tag, TO_BE32(SAVEGAME_VERSION << 16) };
2996 _sl.sf->Write((uint8_t*)hdr, sizeof(hdr));
2997
2998 _sl.sf = fmt.init_write(_sl.sf, compression);
2999 _sl.dumper->Flush(_sl.sf);
3000
3001 ClearSaveLoadState();
3002
3003 if (threaded) SetAsyncSaveFinish(SaveFileDone);
3004
3005 return SL_OK;
3006 } catch (...) {
3007 ClearSaveLoadState();
3008
3009 AsyncSaveFinishProc asfp = SaveFileDone;
3010
3011 /* We don't want to shout when saving is just
3012 * cancelled due to a client disconnecting. */
3013 if (_sl.error_str != STR_NETWORK_ERROR_LOSTCONNECTION) {
3014 /* Skip the "colour" character */
3015 Debug(sl, 0, "{}", GetSaveLoadErrorType().GetDecodedString().substr(3) + GetSaveLoadErrorMessage().GetDecodedString());
3016 asfp = SaveFileError;
3017 }
3018
3019 if (threaded) {
3020 SetAsyncSaveFinish(asfp);
3021 } else {
3022 asfp();
3023 }
3024 return SL_ERROR;
3025 }
3026}
3027
3028void WaitTillSaved()
3029{

Callers 1

DoSaveFunction · 0.85

Calls 10

GetSavegameFormatFunction · 0.85
TO_BE32Function · 0.85
ClearSaveLoadStateFunction · 0.85
SetAsyncSaveFinishFunction · 0.85
GetSaveLoadErrorTypeFunction · 0.85
GetSaveLoadErrorMessageFunction · 0.85
substrMethod · 0.80
GetDecodedStringMethod · 0.80
WriteMethod · 0.45
FlushMethod · 0.45

Tested by

no test coverage detected