mirror of https://github.com/OpenTTD/OpenTTD
Codechange: make some saveload functions work natively with std::string_view
parent
855377191e
commit
c1a287ad17
19
src/fios.cpp
19
src/fios.cpp
|
@ -38,7 +38,7 @@ extern bool FiosIsHiddenFile(const std::filesystem::path &path);
|
|||
extern void FiosGetDrives(FileList &file_list);
|
||||
|
||||
/* get the name of an oldstyle savegame */
|
||||
extern std::string GetOldSaveGameName(const std::string &file);
|
||||
extern std::string GetOldSaveGameName(std::string_view file);
|
||||
|
||||
/**
|
||||
* Compare two FiosItem's. Used with sort when sorting the file list.
|
||||
|
@ -240,7 +240,7 @@ bool FiosDelete(std::string_view name)
|
|||
return FioRemove(FiosMakeSavegameName(name));
|
||||
}
|
||||
|
||||
typedef std::tuple<FiosType, std::string> FiosGetTypeAndNameProc(SaveLoadOperation fop, const std::string &filename, std::string_view ext);
|
||||
typedef std::tuple<FiosType, std::string> FiosGetTypeAndNameProc(SaveLoadOperation fop, std::string_view filename, std::string_view ext);
|
||||
|
||||
/**
|
||||
* Scanner to scan for a particular type of FIOS file.
|
||||
|
@ -377,9 +377,10 @@ static void FiosGetFileList(SaveLoadOperation fop, bool show_dirs, FiosGetTypeAn
|
|||
* @param subdir the sub directory to search in
|
||||
* @return The file title.
|
||||
*/
|
||||
static std::string GetFileTitle(const std::string &file, Subdirectory subdir)
|
||||
static std::string GetFileTitle(std::string_view file, Subdirectory subdir)
|
||||
{
|
||||
auto f = FioFOpenFile(file + ".title", "r", subdir);
|
||||
std::string filename = fmt::format("{}.title", file);
|
||||
auto f = FioFOpenFile(filename, "r", subdir);
|
||||
if (!f.has_value()) return {};
|
||||
|
||||
char title[80];
|
||||
|
@ -398,7 +399,7 @@ static std::string GetFileTitle(const std::string &file, Subdirectory subdir)
|
|||
* @see FiosGetFileList
|
||||
* @see FiosGetSavegameList
|
||||
*/
|
||||
std::tuple<FiosType, std::string> FiosGetSavegameListCallback(SaveLoadOperation fop, const std::string &file, std::string_view ext)
|
||||
std::tuple<FiosType, std::string> FiosGetSavegameListCallback(SaveLoadOperation fop, std::string_view file, std::string_view ext)
|
||||
{
|
||||
/* Show savegame files
|
||||
* .SAV OpenTTD saved game
|
||||
|
@ -447,7 +448,7 @@ void FiosGetSavegameList(SaveLoadOperation fop, bool show_dirs, FileList &file_l
|
|||
* @see FiosGetFileList
|
||||
* @see FiosGetScenarioList
|
||||
*/
|
||||
std::tuple<FiosType, std::string> FiosGetScenarioListCallback(SaveLoadOperation fop, const std::string &file, std::string_view ext)
|
||||
std::tuple<FiosType, std::string> FiosGetScenarioListCallback(SaveLoadOperation fop, std::string_view file, std::string_view ext)
|
||||
{
|
||||
/* Show scenario files
|
||||
* .SCN OpenTTD style scenario file
|
||||
|
@ -488,7 +489,7 @@ void FiosGetScenarioList(SaveLoadOperation fop, bool show_dirs, FileList &file_l
|
|||
FiosGetFileList(fop, show_dirs, &FiosGetScenarioListCallback, subdir, file_list);
|
||||
}
|
||||
|
||||
std::tuple<FiosType, std::string> FiosGetHeightmapListCallback(SaveLoadOperation, const std::string &file, std::string_view ext)
|
||||
std::tuple<FiosType, std::string> FiosGetHeightmapListCallback(SaveLoadOperation, std::string_view file, std::string_view ext)
|
||||
{
|
||||
/* Show heightmap files
|
||||
* .PNG PNG Based heightmap files
|
||||
|
@ -553,7 +554,7 @@ void FiosGetHeightmapList(SaveLoadOperation fop, bool show_dirs, FileList &file_
|
|||
* @param file Name of the file to check.
|
||||
* @return a FIOS_TYPE_JSON type of the found file, FIOS_TYPE_INVALID if not a valid JSON file, and the title of the file (if any).
|
||||
*/
|
||||
static std::tuple<FiosType, std::string> FiosGetTownDataListCallback(SaveLoadOperation fop, const std::string &file, std::string_view ext)
|
||||
static std::tuple<FiosType, std::string> FiosGetTownDataListCallback(SaveLoadOperation fop, std::string_view file, std::string_view ext)
|
||||
{
|
||||
if (fop == SLO_LOAD) {
|
||||
if (StrEqualsIgnoreCase(ext, ".json")) {
|
||||
|
@ -715,7 +716,7 @@ FiosNumberedSaveName::FiosNumberedSaveName(const std::string &prefix) : prefix(p
|
|||
static std::string _prefix; ///< Static as the lambda needs access to it.
|
||||
|
||||
/* Callback for FiosFileScanner. */
|
||||
static FiosGetTypeAndNameProc *proc = [](SaveLoadOperation, const std::string &file, std::string_view ext) {
|
||||
static FiosGetTypeAndNameProc *proc = [](SaveLoadOperation, std::string_view file, std::string_view ext) {
|
||||
if (StrEqualsIgnoreCase(ext, ".sav") && file.starts_with(_prefix)) return std::tuple(FIOS_TYPE_FILE, std::string{});
|
||||
return std::tuple(FIOS_TYPE_INVALID, std::string{});
|
||||
};
|
||||
|
|
|
@ -116,9 +116,9 @@ bool FiosDelete(std::string_view name);
|
|||
std::string FiosMakeHeightmapName(std::string_view name);
|
||||
std::string FiosMakeSavegameName(std::string_view name);
|
||||
|
||||
std::tuple<FiosType, std::string> FiosGetSavegameListCallback(SaveLoadOperation fop, const std::string &file, std::string_view ext);
|
||||
std::tuple<FiosType, std::string> FiosGetScenarioListCallback(SaveLoadOperation fop, const std::string &file, std::string_view ext);
|
||||
std::tuple<FiosType, std::string> FiosGetHeightmapListCallback(SaveLoadOperation fop, const std::string &file, std::string_view ext);
|
||||
std::tuple<FiosType, std::string> FiosGetSavegameListCallback(SaveLoadOperation fop, std::string_view file, std::string_view ext);
|
||||
std::tuple<FiosType, std::string> FiosGetScenarioListCallback(SaveLoadOperation fop, std::string_view file, std::string_view ext);
|
||||
std::tuple<FiosType, std::string> FiosGetHeightmapListCallback(SaveLoadOperation fop, std::string_view file, std::string_view ext);
|
||||
|
||||
void ScanScenarios();
|
||||
std::optional<std::string_view> FindScenario(const ContentInfo &ci, bool md5sum);
|
||||
|
|
|
@ -231,7 +231,7 @@ static std::tuple<SavegameType, std::string> DetermineOldSavegameTypeAndName(Fil
|
|||
|
||||
typedef bool LoadOldMainProc(LoadgameState &ls);
|
||||
|
||||
bool LoadOldSaveGame(const std::string &file)
|
||||
bool LoadOldSaveGame(std::string_view file)
|
||||
{
|
||||
LoadgameState ls{};
|
||||
|
||||
|
@ -282,7 +282,7 @@ bool LoadOldSaveGame(const std::string &file)
|
|||
return true;
|
||||
}
|
||||
|
||||
std::string GetOldSaveGameName(const std::string &file)
|
||||
std::string GetOldSaveGameName(std::string_view file)
|
||||
{
|
||||
auto f = FioFOpenFile(file, "rb", NO_DIRECTORY);
|
||||
if (!f.has_value()) return {};
|
||||
|
|
|
@ -2889,7 +2889,7 @@ static std::pair<const SaveLoadFormat &, uint8_t> GetSavegameFormat(const std::s
|
|||
/* actual loader/saver function */
|
||||
void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settings);
|
||||
extern bool AfterLoadGame();
|
||||
extern bool LoadOldSaveGame(const std::string &file);
|
||||
extern bool LoadOldSaveGame(std::string_view file);
|
||||
|
||||
/**
|
||||
* Reset all settings to their default, so any settings missing in the savegame
|
||||
|
@ -3250,7 +3250,7 @@ SaveOrLoadResult LoadWithFilter(std::shared_ptr<LoadFilter> reader)
|
|||
* @param threaded True when threaded saving is allowed
|
||||
* @return Return the result of the action. #SL_OK, #SL_ERROR, or #SL_REINIT ("unload" the game)
|
||||
*/
|
||||
SaveOrLoadResult SaveOrLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded)
|
||||
SaveOrLoadResult SaveOrLoad(std::string_view filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded)
|
||||
{
|
||||
/* An instance of saving is already active, so don't go saving again */
|
||||
if (_sl.saveinprogress && fop == SLO_SAVE && dft == DFT_GAME_FILE && threaded) {
|
||||
|
|
|
@ -439,7 +439,7 @@ std::string GenerateDefaultSaveName();
|
|||
void SetSaveLoadError(StringID str);
|
||||
EncodedString GetSaveLoadErrorType();
|
||||
EncodedString GetSaveLoadErrorMessage();
|
||||
SaveOrLoadResult SaveOrLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded = true);
|
||||
SaveOrLoadResult SaveOrLoad(std::string_view filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded = true);
|
||||
void WaitTillSaved();
|
||||
void ProcessAsyncSaveFinish();
|
||||
void DoExitSave();
|
||||
|
|
|
@ -19,8 +19,8 @@ struct TarFileListEntry {
|
|||
size_t position;
|
||||
};
|
||||
|
||||
typedef std::map<std::string, std::string> TarList; ///< Map of tar file to tar directory.
|
||||
typedef std::map<std::string, TarFileListEntry> TarFileList;
|
||||
using TarList = std::map<std::string, std::string, std::less<>>; ///< Map of tar file to tar directory.
|
||||
using TarFileList = std::map<std::string, TarFileListEntry, std::less<>> ;
|
||||
extern std::array<TarList, NUM_SUBDIRS> _tar_list;
|
||||
extern TarFileList _tar_filelist[NUM_SUBDIRS];
|
||||
|
||||
|
|
Loading…
Reference in New Issue