* 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 */
| 3044 | * @return Return the result of the action. #SL_OK or #SL_ERROR |
| 3045 | */ |
| 3046 | static 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. |
no test coverage detected