1
0
Fork 0

Codechange: Use EnumBitSet for Scanner::Modes. (#13471)

pull/13474/head
Peter Nelson 2025-02-05 20:08:12 +00:00 committed by GitHub
parent 11bbf0b6dd
commit fe31538a27
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 28 additions and 29 deletions

View File

@ -168,7 +168,7 @@
AI::frame_counter = 0; AI::frame_counter = 0;
if (AI::scanner_info == nullptr) { if (AI::scanner_info == nullptr) {
TarScanner::DoScan(TarScanner::AI); TarScanner::DoScan(TarScanner::Mode::AI);
AI::scanner_info = new AIScannerInfo(); AI::scanner_info = new AIScannerInfo();
AI::scanner_info->Initialize(); AI::scanner_info->Initialize();
AI::scanner_library = new AIScannerLibrary(); AI::scanner_library = new AIScannerLibrary();
@ -325,7 +325,7 @@
/* static */ void AI::Rescan() /* static */ void AI::Rescan()
{ {
TarScanner::DoScan(TarScanner::AI); TarScanner::DoScan(TarScanner::Mode::AI);
AI::scanner_info->RescanDir(); AI::scanner_info->RescanDir();
AI::scanner_library->RescanDir(); AI::scanner_library->RescanDir();

View File

@ -382,26 +382,26 @@ uint TarScanner::DoScan(Subdirectory sd)
return num; return num;
} }
/* static */ uint TarScanner::DoScan(TarScanner::Mode mode) /* static */ uint TarScanner::DoScan(TarScanner::Modes modes)
{ {
Debug(misc, 2, "Scanning for tars"); Debug(misc, 2, "Scanning for tars");
TarScanner fs; TarScanner fs;
uint num = 0; uint num = 0;
if (mode & TarScanner::BASESET) { if (modes.Test(TarScanner::Mode::Baseset)) {
num += fs.DoScan(BASESET_DIR); num += fs.DoScan(BASESET_DIR);
} }
if (mode & TarScanner::NEWGRF) { if (modes.Test(TarScanner::Mode::NewGRF)) {
num += fs.DoScan(NEWGRF_DIR); num += fs.DoScan(NEWGRF_DIR);
} }
if (mode & TarScanner::AI) { if (modes.Test(TarScanner::Mode::AI)) {
num += fs.DoScan(AI_DIR); num += fs.DoScan(AI_DIR);
num += fs.DoScan(AI_LIBRARY_DIR); num += fs.DoScan(AI_LIBRARY_DIR);
} }
if (mode & TarScanner::GAME) { if (modes.Test(TarScanner::Mode::Game)) {
num += fs.DoScan(GAME_DIR); num += fs.DoScan(GAME_DIR);
num += fs.DoScan(GAME_LIBRARY_DIR); num += fs.DoScan(GAME_LIBRARY_DIR);
} }
if (mode & TarScanner::SCENARIO) { if (modes.Test(TarScanner::Mode::Scenario)) {
num += fs.DoScan(SCENARIO_DIR); num += fs.DoScan(SCENARIO_DIR);
num += fs.DoScan(HEIGHTMAP_DIR); num += fs.DoScan(HEIGHTMAP_DIR);
} }

View File

@ -60,24 +60,23 @@ class TarScanner : FileScanner {
uint DoScan(Subdirectory sd); uint DoScan(Subdirectory sd);
public: public:
/** The mode of tar scanning. */ /** The mode of tar scanning. */
enum Mode : uint8_t { enum class Mode : uint8_t {
NONE = 0, ///< Scan nothing. Baseset, ///< Scan for base sets.
BASESET = 1 << 0, ///< Scan for base sets. NewGRF, ///< Scan for non-base sets.
NEWGRF = 1 << 1, ///< Scan for non-base sets. AI, ///< Scan for AIs and its libraries.
AI = 1 << 2, ///< Scan for AIs and its libraries. Scenario, ///< Scan for scenarios and heightmaps.
SCENARIO = 1 << 3, ///< Scan for scenarios and heightmaps. Game, ///< Scan for game scripts.
GAME = 1 << 4, ///< Scan for game scripts.
ALL = BASESET | NEWGRF | AI | SCENARIO | GAME, ///< Scan for everything.
}; };
using Modes = EnumBitSet<Mode, uint8_t>;
static constexpr Modes MODES_ALL = {Mode::Baseset, Mode::NewGRF, Mode::AI, Mode::Scenario, Mode::Game}; ///< Scan for everything.
bool AddFile(const std::string &filename, size_t basepath_length, const std::string &tar_filename = {}) override; bool AddFile(const std::string &filename, size_t basepath_length, const std::string &tar_filename = {}) override;
bool AddFile(Subdirectory sd, const std::string &filename); bool AddFile(Subdirectory sd, const std::string &filename);
/** Do the scan for Tars. */ /** Do the scan for Tars. */
static uint DoScan(TarScanner::Mode mode); static uint DoScan(TarScanner::Modes modes);
}; };
DECLARE_ENUM_AS_BIT_SET(TarScanner::Mode)
#endif /* FILEIO_FUNC_H */ #endif /* FILEIO_FUNC_H */

View File

@ -61,7 +61,7 @@
Game::frame_counter = 0; Game::frame_counter = 0;
if (Game::scanner_info == nullptr) { if (Game::scanner_info == nullptr) {
TarScanner::DoScan(TarScanner::GAME); TarScanner::DoScan(TarScanner::Mode::Game);
Game::scanner_info = new GameScannerInfo(); Game::scanner_info = new GameScannerInfo();
Game::scanner_info->Initialize(); Game::scanner_info->Initialize();
Game::scanner_library = new GameScannerLibrary(); Game::scanner_library = new GameScannerLibrary();
@ -190,7 +190,7 @@
/* static */ void Game::Rescan() /* static */ void Game::Rescan()
{ {
TarScanner::DoScan(TarScanner::GAME); TarScanner::DoScan(TarScanner::Mode::Game);
Game::scanner_info->RescanDir(); Game::scanner_info->RescanDir();
Game::scanner_library->RescanDir(); Game::scanner_library->RescanDir();

View File

@ -204,7 +204,7 @@ public:
void Close([[maybe_unused]] int data = 0) override void Close([[maybe_unused]] int data = 0) override
{ {
TarScanner::Mode mode = TarScanner::NONE; TarScanner::Modes modes{};
for (auto ctype : this->receivedTypes) { for (auto ctype : this->receivedTypes) {
switch (ctype) { switch (ctype) {
case CONTENT_TYPE_AI: case CONTENT_TYPE_AI:
@ -219,7 +219,7 @@ public:
case CONTENT_TYPE_BASE_GRAPHICS: case CONTENT_TYPE_BASE_GRAPHICS:
case CONTENT_TYPE_BASE_SOUNDS: case CONTENT_TYPE_BASE_SOUNDS:
case CONTENT_TYPE_BASE_MUSIC: case CONTENT_TYPE_BASE_MUSIC:
mode |= TarScanner::BASESET; modes.Set(TarScanner::Mode::Baseset);
break; break;
case CONTENT_TYPE_NEWGRF: case CONTENT_TYPE_NEWGRF:
@ -228,7 +228,7 @@ public:
case CONTENT_TYPE_SCENARIO: case CONTENT_TYPE_SCENARIO:
case CONTENT_TYPE_HEIGHTMAP: case CONTENT_TYPE_HEIGHTMAP:
mode |= TarScanner::SCENARIO; modes.Set(TarScanner::Mode::Scenario);
break; break;
default: default:
@ -236,7 +236,7 @@ public:
} }
} }
TarScanner::DoScan(mode); TarScanner::DoScan(modes);
/* Tell all the backends about what we've downloaded */ /* Tell all the backends about what we've downloaded */
for (auto ctype : this->receivedTypes) { for (auto ctype : this->receivedTypes) {

View File

@ -559,7 +559,7 @@ static bool GRFSorter(std::unique_ptr<GRFConfig> const &c1, std::unique_ptr<GRFC
void DoScanNewGRFFiles(NewGRFScanCallback *callback) void DoScanNewGRFFiles(NewGRFScanCallback *callback)
{ {
ClearGRFConfigList(_all_grfs); ClearGRFConfigList(_all_grfs);
TarScanner::DoScan(TarScanner::NEWGRF); TarScanner::DoScan(TarScanner::Mode::NewGRF);
Debug(grf, 1, "Scanning for NewGRFs"); Debug(grf, 1, "Scanning for NewGRFs");
uint num = GRFFileScanner::DoScan(); uint num = GRFFileScanner::DoScan();

View File

@ -399,7 +399,7 @@ struct AfterNewGRFScan : NewGRFScanCallback {
{ {
ResetGRFConfig(false); ResetGRFConfig(false);
TarScanner::DoScan(TarScanner::SCENARIO); TarScanner::DoScan(TarScanner::Mode::Scenario);
AI::Initialize(); AI::Initialize();
Game::Initialize(); Game::Initialize();
@ -654,7 +654,7 @@ int openttd_main(std::span<char * const> arguments)
* The next two functions are needed to list the graphics sets. We can't do them earlier * The next two functions are needed to list the graphics sets. We can't do them earlier
* because then we cannot show it on the debug console as that hasn't been configured yet. */ * because then we cannot show it on the debug console as that hasn't been configured yet. */
DeterminePaths(arguments[0], only_local_path); DeterminePaths(arguments[0], only_local_path);
TarScanner::DoScan(TarScanner::BASESET); TarScanner::DoScan(TarScanner::Mode::Baseset);
BaseGraphics::FindSets(); BaseGraphics::FindSets();
BaseSounds::FindSets(); BaseSounds::FindSets();
BaseMusic::FindSets(); BaseMusic::FindSets();
@ -663,7 +663,7 @@ int openttd_main(std::span<char * const> arguments)
} }
DeterminePaths(arguments[0], only_local_path); DeterminePaths(arguments[0], only_local_path);
TarScanner::DoScan(TarScanner::BASESET); TarScanner::DoScan(TarScanner::Mode::Baseset);
if (dedicated) Debug(net, 3, "Starting dedicated server, version {}", _openttd_revision); if (dedicated) Debug(net, 3, "Starting dedicated server, version {}", _openttd_revision);
if (_dedicated_forks && !dedicated) _dedicated_forks = false; if (_dedicated_forks && !dedicated) _dedicated_forks = false;