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

Function DoSave

src/saveload/saveload.cpp:3046–3070  ·  view source on GitHub ↗

* Actually perform the saving of the savegame. * General tactics 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 asynchronously. * @return Return the result of the action. #SL_OK or #SL_ERROR */

Source from the content-addressed store, hash-verified

3044 * @return Return the result of the action. #SL_OK or #SL_ERROR
3045 */
3046static SaveOrLoadResult DoSave(std::shared_ptr<SaveFilter> writer, bool threaded)
3047{
3048 assert(!_sl.saveinprogress);
3049
3050 _sl.dumper = std::make_unique<MemoryDumper>();
3051 _sl.sf = std::move(writer);
3052
3053 _sl_version = SAVEGAME_VERSION;
3054
3055 SaveViewportBeforeSaveGame();
3056 SlSaveChunks();
3057
3058 SaveFileStart();
3059
3060 if (!threaded || !StartNewThread(&_save_thread, "ottd:savegame", &SaveFileToDisk, true)) {
3061 if (threaded) Debug(sl, 1, "Cannot create savegame thread, reverting to single-threaded mode...");
3062
3063 SaveOrLoadResult result = SaveFileToDisk(false);
3064 SaveFileDone();
3065
3066 return result;
3067 }
3068
3069 return SL_OK;
3070}
3071
3072/**
3073 * Save the game using a (writer) filter.

Callers 2

SaveWithFilterFunction · 0.85
SaveOrLoadFunction · 0.85

Calls 6

SlSaveChunksFunction · 0.85
SaveFileStartFunction · 0.85
StartNewThreadFunction · 0.85
SaveFileToDiskFunction · 0.85
SaveFileDoneFunction · 0.85

Tested by

no test coverage detected