mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2026-07-25 08:22:17 +00:00
Codechange: make DetailedFileType a scoped enum
This commit is contained in:
committed by
Peter Nelson
parent
74b0b080e7
commit
04f7adb7b7
@@ -425,7 +425,7 @@ static bool ConSave(std::span<std::string_view> argv)
|
||||
std::string filename = fmt::format("{}.sav", argv[1]);
|
||||
IConsolePrint(CC_DEFAULT, "Saving map...");
|
||||
|
||||
if (SaveOrLoad(filename, SLO_SAVE, DFT_GAME_FILE, SAVE_DIR) != SL_OK) {
|
||||
if (SaveOrLoad(filename, SLO_SAVE, DetailedFileType::GameFile, SAVE_DIR) != SL_OK) {
|
||||
IConsolePrint(CC_ERROR, "Saving map failed.");
|
||||
} else {
|
||||
IConsolePrint(CC_INFO, "Map successfully saved to '{}'.", filename);
|
||||
@@ -627,9 +627,9 @@ static bool ConChangeDirectory(std::span<std::string_view> argv)
|
||||
const FiosItem *item = _console_file_list_savegame.FindItem(file);
|
||||
if (item != nullptr) {
|
||||
switch (item->type.detailed) {
|
||||
case DFT_FIOS_DIR:
|
||||
case DFT_FIOS_DRIVE:
|
||||
case DFT_FIOS_PARENT:
|
||||
case DetailedFileType::FiosDirectory:
|
||||
case DetailedFileType::FiosDrive:
|
||||
case DetailedFileType::FiosParent:
|
||||
FiosBrowseTo(item);
|
||||
break;
|
||||
default: IConsolePrint(CC_ERROR, "{}: Not a directory.", file);
|
||||
|
||||
+1
-1
@@ -232,7 +232,7 @@ bool CrashLog::WriteSavegame()
|
||||
this->savegame_filename = this->CreateFileName(".sav");
|
||||
|
||||
/* Don't do a threaded saveload. */
|
||||
return SaveOrLoad(this->savegame_filename, SLO_SAVE, DFT_GAME_FILE, NO_DIRECTORY, false) == SL_OK;
|
||||
return SaveOrLoad(this->savegame_filename, SLO_SAVE, DetailedFileType::GameFile, NO_DIRECTORY, false) == SL_OK;
|
||||
} catch (...) {
|
||||
return false;
|
||||
}
|
||||
|
||||
+24
-24
@@ -25,27 +25,27 @@ enum class AbstractFileType : uint8_t {
|
||||
};
|
||||
|
||||
/** Kinds of files in each #AbstractFileType. */
|
||||
enum DetailedFileType : uint8_t {
|
||||
enum class DetailedFileType : uint8_t {
|
||||
/* Save game and scenario files. */
|
||||
DFT_OLD_GAME_FILE, ///< Old save game or scenario file.
|
||||
DFT_GAME_FILE, ///< Save game or scenario file.
|
||||
OldGameFile, ///< Old save game or scenario file.
|
||||
GameFile, ///< Save game or scenario file.
|
||||
|
||||
/* Heightmap files. */
|
||||
DFT_HEIGHTMAP_BMP, ///< BMP file.
|
||||
DFT_HEIGHTMAP_PNG, ///< PNG file.
|
||||
HeightmapBmp, ///< BMP file.
|
||||
HeightmapPng, ///< PNG file.
|
||||
|
||||
/* Town data files. */
|
||||
DFT_TOWN_DATA_JSON, ///< JSON file.
|
||||
TownDataJson, ///< JSON file.
|
||||
|
||||
/* fios 'files' */
|
||||
DFT_FIOS_DRIVE, ///< A drive (letter) entry.
|
||||
DFT_FIOS_PARENT, ///< A parent directory entry.
|
||||
DFT_FIOS_DIR, ///< A directory entry.
|
||||
DFT_FIOS_DIRECT, ///< Direct filename.
|
||||
FiosDrive, ///< A drive (letter) entry.
|
||||
FiosParent, ///< A parent directory entry.
|
||||
FiosDirectory, ///< A directory entry.
|
||||
FiosDirect, ///< Direct filename.
|
||||
|
||||
DFT_END, ///< End of this enum. Supports a compile time size check against _fios_colours in fios_gui.cpp
|
||||
End, ///< End marker.
|
||||
|
||||
DFT_INVALID = 255, ///< Unknown or invalid file.
|
||||
Invalid = 255, ///< Unknown or invalid file.
|
||||
};
|
||||
|
||||
/** Operation performed on the file. */
|
||||
@@ -67,20 +67,20 @@ struct FiosType {
|
||||
constexpr bool operator==(const FiosType &) const noexcept = default;
|
||||
};
|
||||
|
||||
constexpr FiosType FIOS_TYPE_DRIVE{AbstractFileType::None, DFT_FIOS_DRIVE};
|
||||
constexpr FiosType FIOS_TYPE_PARENT{AbstractFileType::None, DFT_FIOS_PARENT};
|
||||
constexpr FiosType FIOS_TYPE_DIR{AbstractFileType::None, DFT_FIOS_DIR};
|
||||
constexpr FiosType FIOS_TYPE_DIRECT{AbstractFileType::None, DFT_FIOS_DIRECT};
|
||||
constexpr FiosType FIOS_TYPE_DRIVE{AbstractFileType::None, DetailedFileType::FiosDrive};
|
||||
constexpr FiosType FIOS_TYPE_PARENT{AbstractFileType::None, DetailedFileType::FiosParent};
|
||||
constexpr FiosType FIOS_TYPE_DIR{AbstractFileType::None, DetailedFileType::FiosDirectory};
|
||||
constexpr FiosType FIOS_TYPE_DIRECT{AbstractFileType::None, DetailedFileType::FiosDirect};
|
||||
|
||||
constexpr FiosType FIOS_TYPE_FILE{AbstractFileType::Savegame, DFT_GAME_FILE};
|
||||
constexpr FiosType FIOS_TYPE_OLDFILE{AbstractFileType::Savegame, DFT_OLD_GAME_FILE};
|
||||
constexpr FiosType FIOS_TYPE_SCENARIO{AbstractFileType::Scenario, DFT_GAME_FILE};
|
||||
constexpr FiosType FIOS_TYPE_OLD_SCENARIO{AbstractFileType::Scenario, DFT_OLD_GAME_FILE};
|
||||
constexpr FiosType FIOS_TYPE_PNG{AbstractFileType::Heightmap, DFT_HEIGHTMAP_PNG};
|
||||
constexpr FiosType FIOS_TYPE_BMP{AbstractFileType::Heightmap, DFT_HEIGHTMAP_BMP};
|
||||
constexpr FiosType FIOS_TYPE_JSON{AbstractFileType::TownData, DFT_TOWN_DATA_JSON};
|
||||
constexpr FiosType FIOS_TYPE_FILE{AbstractFileType::Savegame, DetailedFileType::GameFile};
|
||||
constexpr FiosType FIOS_TYPE_OLDFILE{AbstractFileType::Savegame, DetailedFileType::OldGameFile};
|
||||
constexpr FiosType FIOS_TYPE_SCENARIO{AbstractFileType::Scenario, DetailedFileType::GameFile};
|
||||
constexpr FiosType FIOS_TYPE_OLD_SCENARIO{AbstractFileType::Scenario, DetailedFileType::OldGameFile};
|
||||
constexpr FiosType FIOS_TYPE_PNG{AbstractFileType::Heightmap, DetailedFileType::HeightmapPng};
|
||||
constexpr FiosType FIOS_TYPE_BMP{AbstractFileType::Heightmap, DetailedFileType::HeightmapBmp};
|
||||
constexpr FiosType FIOS_TYPE_JSON{AbstractFileType::TownData, DetailedFileType::TownDataJson};
|
||||
|
||||
constexpr FiosType FIOS_TYPE_INVALID{AbstractFileType::Invalid, DFT_INVALID};
|
||||
constexpr FiosType FIOS_TYPE_INVALID{AbstractFileType::Invalid, DetailedFileType::Invalid};
|
||||
|
||||
/**
|
||||
* The different kinds of subdirectories OpenTTD uses
|
||||
|
||||
+5
-5
@@ -133,17 +133,17 @@ std::string FiosGetCurrentPath()
|
||||
bool FiosBrowseTo(const FiosItem *item)
|
||||
{
|
||||
switch (item->type.detailed) {
|
||||
case DFT_FIOS_DRIVE:
|
||||
case DetailedFileType::FiosDrive:
|
||||
#if defined(_WIN32)
|
||||
assert(_fios_path != nullptr);
|
||||
*_fios_path = std::string{ item->name, 0, 1 } + ":" PATHSEP;
|
||||
#endif
|
||||
break;
|
||||
|
||||
case DFT_INVALID:
|
||||
case DetailedFileType::Invalid:
|
||||
break;
|
||||
|
||||
case DFT_FIOS_PARENT: {
|
||||
case DetailedFileType::FiosParent: {
|
||||
assert(_fios_path != nullptr);
|
||||
auto s = _fios_path->find_last_of(PATHSEPCHAR);
|
||||
if (s != std::string::npos && s != 0) {
|
||||
@@ -157,13 +157,13 @@ bool FiosBrowseTo(const FiosItem *item)
|
||||
break;
|
||||
}
|
||||
|
||||
case DFT_FIOS_DIR:
|
||||
case DetailedFileType::FiosDirectory:
|
||||
assert(_fios_path != nullptr);
|
||||
*_fios_path += item->name;
|
||||
*_fios_path += PATHSEP;
|
||||
break;
|
||||
|
||||
case DFT_FIOS_DIRECT:
|
||||
case DetailedFileType::FiosDirect:
|
||||
assert(_fios_path != nullptr);
|
||||
*_fios_path = item->name;
|
||||
break;
|
||||
|
||||
+15
-17
@@ -303,19 +303,17 @@ static constexpr std::initializer_list<NWidgetPart> _nested_save_dialog_widgets
|
||||
};
|
||||
|
||||
/** Text colours of #DetailedFileType fios entries in the window. */
|
||||
static const TextColour _fios_colours[] = {
|
||||
TC_LIGHT_BROWN, // DFT_OLD_GAME_FILE
|
||||
TC_ORANGE, // DFT_GAME_FILE
|
||||
TC_YELLOW, // DFT_HEIGHTMAP_BMP
|
||||
TC_ORANGE, // DFT_HEIGHTMAP_PNG
|
||||
TC_LIGHT_BROWN, // DFT_TOWN_DATA_JSON
|
||||
TC_LIGHT_BLUE, // DFT_FIOS_DRIVE
|
||||
TC_DARK_GREEN, // DFT_FIOS_PARENT
|
||||
TC_DARK_GREEN, // DFT_FIOS_DIR
|
||||
TC_ORANGE, // DFT_FIOS_DIRECT
|
||||
static const EnumClassIndexContainer<std::array<TextColour, to_underlying(DetailedFileType::End)>, DetailedFileType> _fios_colours = {
|
||||
TC_LIGHT_BROWN, // DetailedFileType::OldGameFile
|
||||
TC_ORANGE, // DetailedFileType::GameFile
|
||||
TC_YELLOW, // DetailedFileType::HeightmapBmp
|
||||
TC_ORANGE, // DetailedFileType::HeightmapPng
|
||||
TC_LIGHT_BROWN, // DetailedFileType::TownDataJson
|
||||
TC_LIGHT_BLUE, // DetailedFileType::FiosDrive
|
||||
TC_DARK_GREEN, // DetailedFileType::FiosParent
|
||||
TC_DARK_GREEN, // DetailedFileType::FiosDirectory
|
||||
TC_ORANGE, // DetailedFileType::FiosDirect
|
||||
};
|
||||
/* This should align with the DetailedFileType enum defined in fileio_type.h */
|
||||
static_assert(std::size(_fios_colours) == DFT_END);
|
||||
|
||||
/**
|
||||
* Sort the collected list save games prior to displaying it in the save/load gui.
|
||||
@@ -332,9 +330,9 @@ static void SortSaveGameList(FileList &file_list)
|
||||
*/
|
||||
for (const auto &item : file_list) {
|
||||
switch (item.type.detailed) {
|
||||
case DFT_FIOS_DIR: sort_start++; break;
|
||||
case DFT_FIOS_PARENT: sort_start++; break;
|
||||
case DFT_FIOS_DRIVE: sort_end++; break;
|
||||
case DetailedFileType::FiosDirectory: sort_start++; break;
|
||||
case DetailedFileType::FiosParent: sort_start++; break;
|
||||
case DetailedFileType::FiosDrive: sort_end++; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
@@ -759,9 +757,9 @@ public:
|
||||
this->selected = file;
|
||||
_load_check_data.Clear();
|
||||
|
||||
if (file->type.detailed == DFT_GAME_FILE) {
|
||||
if (file->type.detailed == DetailedFileType::GameFile) {
|
||||
/* Other detailed file types cannot be checked before. */
|
||||
SaveOrLoad(file->name, SLO_CHECK, DFT_GAME_FILE, NO_DIRECTORY, false);
|
||||
SaveOrLoad(file->name, SLO_CHECK, DetailedFileType::GameFile, NO_DIRECTORY, false);
|
||||
}
|
||||
|
||||
this->InvalidateData(SLIWD_SELECTION_CHANGES);
|
||||
|
||||
+1
-1
@@ -217,7 +217,7 @@ static void _GenerateWorld()
|
||||
|
||||
if (_debug_desync_level > 0) {
|
||||
std::string name = fmt::format("dmp_cmds_{:08x}_{:08x}.sav", _settings_game.game_creation.generation_seed, TimerGameEconomy::date);
|
||||
SaveOrLoad(name, SLO_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR, false);
|
||||
SaveOrLoad(name, SLO_SAVE, DetailedFileType::GameFile, AUTOSAVE_DIR, false);
|
||||
}
|
||||
} catch (AbortGenerateWorldSignal&) {
|
||||
CleanupGeneration();
|
||||
|
||||
+2
-2
@@ -505,11 +505,11 @@ static bool ReadHeightMap(DetailedFileType dft, std::string_view filename, uint
|
||||
NOT_REACHED();
|
||||
|
||||
#ifdef WITH_PNG
|
||||
case DFT_HEIGHTMAP_PNG:
|
||||
case DetailedFileType::HeightmapPng:
|
||||
return ReadHeightmapPNG(filename, x, y, map);
|
||||
#endif /* WITH_PNG */
|
||||
|
||||
case DFT_HEIGHTMAP_BMP:
|
||||
case DetailedFileType::HeightmapBmp:
|
||||
return ReadHeightmapBMP(filename, x, y, map);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -863,7 +863,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet
|
||||
/* Set the abstract filetype. This is read during savegame load. */
|
||||
_file_to_saveload.SetMode(FIOS_TYPE_FILE, SLO_LOAD);
|
||||
|
||||
bool load_success = SafeLoad({}, SLO_LOAD, DFT_GAME_FILE, GM_NORMAL, NO_DIRECTORY, this->savegame);
|
||||
bool load_success = SafeLoad({}, SLO_LOAD, DetailedFileType::GameFile, GM_NORMAL, NO_DIRECTORY, this->savegame);
|
||||
this->savegame = nullptr;
|
||||
|
||||
/* Long savegame loads shouldn't affect the lag calculation! */
|
||||
|
||||
+5
-5
@@ -329,7 +329,7 @@ static void LoadIntroGame(bool load_newgrfs = true)
|
||||
SetupColoursAndInitialWindow();
|
||||
|
||||
/* Load the default opening screen savegame */
|
||||
if (SaveOrLoad("opntitle.dat", SLO_LOAD, DFT_GAME_FILE, BASESET_DIR) != SL_OK) {
|
||||
if (SaveOrLoad("opntitle.dat", SLO_LOAD, DetailedFileType::GameFile, BASESET_DIR) != SL_OK) {
|
||||
GenerateWorld(GWM_EMPTY, 64, 64); // if failed loading, make empty world.
|
||||
SetLocalCompany(COMPANY_SPECTATOR);
|
||||
} else {
|
||||
@@ -612,7 +612,7 @@ int openttd_main(std::span<std::string_view> arguments)
|
||||
auto [_, title] = FiosGetSavegameListCallback(SLO_LOAD, mgo.opt, extension);
|
||||
|
||||
_load_check_data.Clear();
|
||||
SaveOrLoadResult res = SaveOrLoad(mgo.opt, SLO_CHECK, DFT_GAME_FILE, SAVE_DIR, false);
|
||||
SaveOrLoadResult res = SaveOrLoad(mgo.opt, SLO_CHECK, DetailedFileType::GameFile, SAVE_DIR, false);
|
||||
if (res != SL_OK || _load_check_data.HasErrors()) {
|
||||
fmt::print(stderr, "Failed to open savegame\n");
|
||||
if (_load_check_data.HasErrors()) {
|
||||
@@ -939,7 +939,7 @@ static void MakeNewEditorWorld()
|
||||
bool SafeLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, std::shared_ptr<LoadFilter> lf = nullptr)
|
||||
{
|
||||
assert(fop == SLO_LOAD);
|
||||
assert(dft == DFT_GAME_FILE || (lf == nullptr && dft == DFT_OLD_GAME_FILE));
|
||||
assert(dft == DetailedFileType::GameFile || (lf == nullptr && dft == DetailedFileType::OldGameFile));
|
||||
GameMode ogm = _game_mode;
|
||||
|
||||
_game_mode = newgm;
|
||||
@@ -1175,7 +1175,7 @@ void SwitchToMode(SwitchMode new_mode)
|
||||
|
||||
case SM_SAVE_GAME: // Save game.
|
||||
/* Make network saved games on pause compatible to singleplayer mode */
|
||||
if (SaveOrLoad(_file_to_saveload.name, SLO_SAVE, DFT_GAME_FILE, NO_DIRECTORY) != SL_OK) {
|
||||
if (SaveOrLoad(_file_to_saveload.name, SLO_SAVE, DetailedFileType::GameFile, NO_DIRECTORY) != SL_OK) {
|
||||
ShowErrorMessage(GetSaveLoadErrorType(), GetSaveLoadErrorMessage(), WL_ERROR);
|
||||
} else {
|
||||
CloseWindowById(WC_SAVELOAD, 0);
|
||||
@@ -1245,7 +1245,7 @@ void StateGameLoop()
|
||||
if (_debug_desync_level > 2 && TimerGameEconomy::date_fract == 0 && (TimerGameEconomy::date.base() & 0x1F) == 0) {
|
||||
/* Save the desync savegame if needed. */
|
||||
std::string name = fmt::format("dmp_cmds_{:08x}_{:08x}.sav", _settings_game.game_creation.generation_seed, TimerGameEconomy::date);
|
||||
SaveOrLoad(name, SLO_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR, false);
|
||||
SaveOrLoad(name, SLO_SAVE, DetailedFileType::GameFile, AUTOSAVE_DIR, false);
|
||||
}
|
||||
|
||||
CheckCaches();
|
||||
|
||||
@@ -3293,7 +3293,7 @@ SaveOrLoadResult LoadWithFilter(std::shared_ptr<LoadFilter> reader)
|
||||
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) {
|
||||
if (_sl.saveinprogress && fop == SLO_SAVE && dft == DetailedFileType::GameFile && threaded) {
|
||||
/* if not an autosave, but a user action, show error message */
|
||||
if (!_do_autosave) ShowErrorMessage(GetEncodedString(STR_ERROR_SAVE_STILL_IN_PROGRESS), {}, WL_ERROR);
|
||||
return SL_OK;
|
||||
@@ -3302,7 +3302,7 @@ SaveOrLoadResult SaveOrLoad(std::string_view filename, SaveLoadOperation fop, De
|
||||
|
||||
try {
|
||||
/* Load a TTDLX or TTDPatch game */
|
||||
if (fop == SLO_LOAD && dft == DFT_OLD_GAME_FILE) {
|
||||
if (fop == SLO_LOAD && dft == DetailedFileType::OldGameFile) {
|
||||
ResetSaveloadData();
|
||||
|
||||
InitializeGame(256, 256, true, true); // set a mapsize of 256x256 for TTDPatch games or it might get confused
|
||||
@@ -3325,7 +3325,7 @@ SaveOrLoadResult SaveOrLoad(std::string_view filename, SaveLoadOperation fop, De
|
||||
return SL_OK;
|
||||
}
|
||||
|
||||
assert(dft == DFT_GAME_FILE);
|
||||
assert(dft == DetailedFileType::GameFile);
|
||||
switch (fop) {
|
||||
case SLO_CHECK:
|
||||
_sl.action = SLA_LOAD_CHECK;
|
||||
@@ -3391,7 +3391,7 @@ void DoAutoOrNetsave(FiosNumberedSaveName &counter)
|
||||
}
|
||||
|
||||
Debug(sl, 2, "Autosaving to '{}'", filename);
|
||||
if (SaveOrLoad(filename, SLO_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR) != SL_OK) {
|
||||
if (SaveOrLoad(filename, SLO_SAVE, DetailedFileType::GameFile, AUTOSAVE_DIR) != SL_OK) {
|
||||
ShowErrorMessage(GetEncodedString(STR_ERROR_AUTOSAVE_FAILED), {}, WL_ERROR);
|
||||
}
|
||||
}
|
||||
@@ -3400,7 +3400,7 @@ void DoAutoOrNetsave(FiosNumberedSaveName &counter)
|
||||
/** Do a save when exiting the game (_settings_client.gui.autosave_on_exit) */
|
||||
void DoExitSave()
|
||||
{
|
||||
SaveOrLoad("exit.sav", SLO_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR);
|
||||
SaveOrLoad("exit.sav", SLO_SAVE, DetailedFileType::GameFile, AUTOSAVE_DIR);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user