OpenTTD Source 20260721-master-g25ec12c62d
saveload_func.h File Reference

Functions related to saving and loading games. More...

#include "saveload_type.h"
#include "../fileio_type.h"
#include "../fios.h"

Go to the source code of this file.

Data Structures

struct  FileToSaveLoad
 Deals with the type of the savegame, independent of extension. More...

Functions

std::string GenerateDefaultSaveName ()
 Get the default name for a savegame or screenshot.
EncodedString GetSaveLoadErrorType ()
 Return the appropriate initial string for an error depending on whether we are saving or loading.
EncodedString GetSaveLoadErrorMessage ()
 Return the description of the error.
SaveLoadResult SaveOrLoad (std::string_view filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded=true)
 Main Save or Load function where the high-level saveload functions are handled.
void WaitTillSaved ()
void ProcessAsyncSaveFinish ()
 Handle async save finishes.
void DoExitSave ()
 Do a save when exiting the game (_settings_client.gui.autosave_on_exit).
void DoAutoOrNetsave (FiosNumberedSaveName &counter)
 Create an autosave or netsave.
SaveLoadResult SaveWithFilter (std::shared_ptr< struct SaveFilter > writer, bool threaded)
SaveLoadResult LoadWithFilter (std::shared_ptr< struct LoadFilter > reader)
bool SaveloadCrashWithMissingNewGRFs ()
 Did loading the savegame cause a crash?

Variables

FileToSaveLoad _file_to_saveload
 File to save or load in the openttd loop.
std::string _savegame_format
 how to compress savegames
bool _do_autosave
 are we doing an autosave at the moment?

Detailed Description

Functions related to saving and loading games.

Definition in file saveload_func.h.

Function Documentation

◆ DoAutoOrNetsave()

void DoAutoOrNetsave ( FiosNumberedSaveName & counter)

Create an autosave or netsave.

Parameters
counterA reference to the counter variable to be used for rotating the file name.

Definition at line 3417 of file saveload.cpp.

References _settings_client, Autosave, Debug, Error, FiosNumberedSaveName::Extension(), FiosNumberedSaveName::Filename(), GameFile, GenerateDefaultSaveName(), GetEncodedString(), Ok, Save, SaveOrLoad(), and ShowErrorMessage().

Referenced by ClientNetworkEmergencySave().

◆ DoExitSave()

void DoExitSave ( )

Do a save when exiting the game (_settings_client.gui.autosave_on_exit).

Definition at line 3435 of file saveload.cpp.

References Autosave, GameFile, Save, and SaveOrLoad().

Referenced by ConExit(), VideoDriver_Dedicated::MainLoop(), VideoDriver_Null::MainLoop(), and MainWindow::OnHotkey().

◆ GenerateDefaultSaveName()

std::string GenerateDefaultSaveName ( )

Get the default name for a savegame or screenshot.

Returns
The default name, i.e. company name and (play) time.

Definition at line 3444 of file saveload.cpp.

References _local_company, _settings_client, TimerGameTick::counter, TimerGameEconomy::date, GetStringWithArgs(), SanitizeFilename(), Ticks::TICKS_PER_SECOND, and TimerGameEconomy::UsingWallclockUnits().

Referenced by DoAutoOrNetsave(), SaveLoadWindow::GenerateFileName(), and MakeScreenshotName().

◆ GetSaveLoadErrorMessage()

EncodedString GetSaveLoadErrorMessage ( )

Return the description of the error.

Returns
The encoded string with the error message.

Definition at line 3036 of file saveload.cpp.

References _sl, and GetEncodedString().

Referenced by SaveFileError(), SaveFileToDisk(), and SaveOrLoad().

◆ GetSaveLoadErrorType()

EncodedString GetSaveLoadErrorType ( )

Return the appropriate initial string for an error depending on whether we are saving or loading.

Returns
The encoded string with the error type.

Definition at line 3027 of file saveload.cpp.

References _sl, GetEncodedString(), and Save.

Referenced by SaveFileError(), SaveFileToDisk(), and SaveOrLoad().

◆ ProcessAsyncSaveFinish()

void ProcessAsyncSaveFinish ( )

Handle async save finishes.

Definition at line 394 of file saveload.cpp.

References _async_save_finish, and _save_thread.

◆ SaveloadCrashWithMissingNewGRFs()

bool SaveloadCrashWithMissingNewGRFs ( )

Did loading the savegame cause a crash?

If so, were NewGRFs missing?

Returns
when the saveload crashed due to missing NewGRFs.

Definition at line 350 of file afterload.cpp.

References _saveload_crash_with_missing_newgrfs.

Referenced by HandleCrash(), and HandleCrash().

◆ SaveOrLoad()

SaveLoadResult SaveOrLoad ( std::string_view filename,
SaveLoadOperation fop,
DetailedFileType dft,
Subdirectory sb,
bool threaded )

Main Save or Load function where the high-level saveload functions are handled.

It opens the savegame, selects format and checks versions

Parameters
filenameThe name of the savegame being created/loaded
fopSave or load mode. Load can also be a TTD(Patch) game.
dftThe type of file to save or load.
sbThe sub directory to save the savegame in
threadedTrue when threaded saving is allowed
Returns
Return the result of the action. SaveLoadResult::Ok, SaveLoadResult::Error, or SaveLoadResult::ReInit ("unload" the game)

Definition at line 3328 of file saveload.cpp.

References _do_autosave, _gamelog, _grfconfig, _settings_client, _sl, _sl_minor_version, _sl_version, AfterLoadGame(), Base, Check, ClearGRFConfigList(), ClearSaveLoadState(), TimerGameEconomy::date, TimerGameEconomy::date_fract, Debug, DoLoad(), DoSave(), Error, FioFOpenFile(), GameFile, GetEncodedString(), GetSaveLoadErrorMessage(), GetSaveLoadErrorType(), Load, LoadCheck, MinVersion, Ok, OldGameFile, ReInit, ResetSaveloadData(), Save, Scenario, ShowErrorMessage(), and SlError().

Referenced by _GenerateWorld(), ConSave(), DoAutoOrNetsave(), DoExitSave(), LoadIntroGame(), SaveLoadWindow::OnClick(), openttd_main(), SafeLoad(), StateGameLoop(), and CrashLog::WriteSavegame().

◆ WaitTillSaved()

void WaitTillSaved ( )

Definition at line 3094 of file saveload.cpp.

Variable Documentation

◆ _do_autosave

bool _do_autosave
extern

are we doing an autosave at the moment?

Definition at line 84 of file saveload.cpp.

Referenced by StatusBarWindow::DrawWidget(), and SaveOrLoad().

◆ _file_to_saveload

◆ _savegame_format

std::string _savegame_format
extern

how to compress savegames

Definition at line 83 of file saveload.cpp.

Referenced by SaveFileToDisk().