1
0
Fork 0

Codechange: Use EnumBitSet for GRFConfigFlags.

This is renamed from `GCF_Flag` didn't match convention.
pull/13442/head
Peter Nelson 2025-01-31 18:41:21 +00:00 committed by Peter Nelson
parent 877fa54f66
commit 6f52a977a8
15 changed files with 86 additions and 80 deletions

View File

@ -507,7 +507,7 @@ bool Gamelog::GRFBugReverse(uint32_t grfid, uint16_t internal_id)
*/
static inline bool IsLoggableGrfConfig(const GRFConfig &g)
{
return !HasBit(g.flags, GCF_STATIC) && g.status != GCS_NOT_FOUND;
return !g.flags.Test(GRFConfigFlag::Static) && g.status != GCS_NOT_FOUND;
}
/**

View File

@ -153,7 +153,7 @@ static std::unique_ptr<GRFConfig> GetDefaultExtraGRFConfig()
auto gc = std::make_unique<GRFConfig>("OPENTTD.GRF");
gc->palette |= GRFP_GRF_DOS;
FillGRFDetails(*gc, false, BASESET_DIR);
ClrBit(gc->flags, GCF_INIT_ONLY);
gc->flags.Reset(GRFConfigFlag::InitOnly);
return gc;
}
@ -165,7 +165,7 @@ static std::unique_ptr<GRFConfig> GetBasesetExtraGRFConfig()
{
auto gc = std::make_unique<GRFConfig>(BaseGraphics::GetUsedSet()->GetOrCreateExtraConfig());
if (gc->param.empty()) gc->SetParameterDefaults();
ClrBit(gc->flags, GCF_INIT_ONLY);
gc->flags.Reset(GRFConfigFlag::InitOnly);
return gc;
}
@ -272,7 +272,7 @@ static bool SwitchNewGRFBlitter()
uint depth_wanted_by_base = BaseGraphics::GetUsedSet()->blitter == BLT_32BPP ? 32 : 8;
uint depth_wanted_by_grf = _support8bpp != S8BPP_NONE ? 8 : 32;
for (const auto &c : _grfconfig) {
if (c->status == GCS_DISABLED || c->status == GCS_NOT_FOUND || HasBit(c->flags, GCF_INIT_ONLY)) continue;
if (c->status == GCS_DISABLED || c->status == GCS_NOT_FOUND || c->flags.Test(GRFConfigFlag::InitOnly)) continue;
if (c->palette & GRFP_BLT_32BPP) depth_wanted_by_grf = 32;
}
/* We need a 32bpp blitter for font anti-alias. */

View File

@ -193,7 +193,7 @@ static void HandleIncomingNetworkGameInfoGRFConfig(GRFConfig &config, std::strin
config.info = f->info;
config.url = f->url;
}
SetBit(config.flags, GCF_COPY);
config.flags.Set(GRFConfigFlag::Copy);
}
/**
@ -230,12 +230,12 @@ void SerializeNetworkGameInfo(Packet &p, const NetworkServerGameInfo &info, bool
* the GRFs that are needed, i.e. the ones that the server has
* selected in the NewGRF GUI and not the ones that are used due
* to the fact that they are in [newgrf-static] in openttd.cfg */
uint count = std::ranges::count_if(info.grfconfig, [](const auto &c) { return !HasBit(c->flags, GCF_STATIC); });
uint count = std::ranges::count_if(info.grfconfig, [](const auto &c) { return !c->flags.Test(GRFConfigFlag::Static); });
p.Send_uint8 (count); // Send number of GRFs
/* Send actual GRF Identifications */
for (const auto &c : info.grfconfig) {
if (HasBit(c->flags, GCF_STATIC)) continue;
if (c->flags.Test(GRFConfigFlag::Static)) continue;
SerializeGRFIdentifier(p, c->ident);
if (send_newgrf_names) p.Send_string(c->GetName());

View File

@ -118,7 +118,7 @@ void NetworkAfterNewGRFScan()
item->info.compatible = item->info.version_compatible;
for (auto &c : item->info.grfconfig) {
assert(HasBit(c->flags, GCF_COPY));
assert(c->flags.Test(GRFConfigFlag::Copy));
const GRFConfig *f = FindGRFConfig(c->ident.grfid, FGCM_EXACT, &c->ident.md5sum);
if (f == nullptr) {

View File

@ -418,11 +418,11 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendNewGRFCheck()
auto p = std::make_unique<Packet>(this, PACKET_SERVER_CHECK_NEWGRFS, TCP_MTU);
uint grf_count = std::ranges::count_if(_grfconfig, [](const auto &c){ return !HasBit(c->flags, GCF_STATIC); });
uint grf_count = std::ranges::count_if(_grfconfig, [](const auto &c){ return !c->flags.Test(GRFConfigFlag::Static); });
p->Send_uint8 (grf_count);
for (const auto &c : _grfconfig) {
if (!HasBit(c->flags, GCF_STATIC)) SerializeGRFIdentifier(*p, c->ident);
if (!c->flags.Test(GRFConfigFlag::Static)) SerializeGRFIdentifier(*p, c->ident);
}
this->SendPacket(std::move(p));

View File

@ -5063,7 +5063,7 @@ static void SafeChangeInfo(ByteReader &buf)
uint32_t s = buf.ReadDWord();
buf.ReadDWord(); // dest
const GRFConfig *grfconfig = GetGRFConfig(s);
if (grfconfig != nullptr && !HasBit(grfconfig->flags, GCF_STATIC)) {
if (grfconfig != nullptr && !grfconfig->flags.Test(GRFConfigFlag::Static)) {
is_safe = false;
break;
}
@ -5072,7 +5072,7 @@ static void SafeChangeInfo(ByteReader &buf)
}
}
SetBit(_cur.grfconfig->flags, GCF_UNSAFE);
_cur.grfconfig->flags.Set(GRFConfigFlag::Unsafe);
/* Skip remainder of GRF */
_cur.skip_sprites = -1;
@ -6376,7 +6376,7 @@ static void FeatureNewName(ByteReader &buf)
case GSF_SHIPS:
case GSF_AIRCRAFT:
if (!generic) {
Engine *e = GetNewEngine(_cur.grffile, (VehicleType)feature, id, HasBit(_cur.grfconfig->flags, GCF_STATIC));
Engine *e = GetNewEngine(_cur.grffile, (VehicleType)feature, id, _cur.grfconfig->flags.Test(GRFConfigFlag::Static));
if (e == nullptr) break;
StringID string = AddGRFString(_cur.grffile->grfid, GRFStringID{e->index}, lang, new_scheme, false, name, e->info.string_id);
e->info.string_id = string;
@ -6517,7 +6517,7 @@ static void GraphicsNew(ByteReader &buf)
uint16_t offset = HasBit(type, 7) ? buf.ReadExtendedByte() : 0;
ClrBit(type, 7); // Clear the high bit as that only indicates whether there is an offset.
if ((type == 0x0D) && (num == 10) && HasBit(_cur.grfconfig->flags, GCF_SYSTEM)) {
if ((type == 0x0D) && (num == 10) && _cur.grfconfig->flags.Test(GRFConfigFlag::System)) {
/* Special not-TTDP-compatible case used in openttd.grf
* Missing shore sprites and initialisation of SPR_SHORE_BASE */
GrfMsg(2, "GraphicsNew: Loading 10 missing shore sprites from extra grf.");
@ -6979,7 +6979,7 @@ static void SkipIf(ByteReader &buf)
GRFConfig *c = GetGRFConfig(cond_val, mask);
if (c != nullptr && HasBit(c->flags, GCF_STATIC) && !HasBit(_cur.grfconfig->flags, GCF_STATIC) && _networking) {
if (c != nullptr && c->flags.Test(GRFConfigFlag::Static) && !_cur.grfconfig->flags.Test(GRFConfigFlag::Static) && _networking) {
DisableStaticNewGRFInfluencingNonStaticNewGRFs(*c);
c = nullptr;
}
@ -7091,12 +7091,12 @@ static void ScanInfo(ByteReader &buf)
_cur.grfconfig->ident.grfid = grfid;
if (grf_version < 2 || grf_version > 8) {
SetBit(_cur.grfconfig->flags, GCF_INVALID);
_cur.grfconfig->flags.Set(GRFConfigFlag::Invalid);
Debug(grf, 0, "{}: NewGRF \"{}\" (GRFID {:08X}) uses GRF version {}, which is incompatible with this version of OpenTTD.", _cur.grfconfig->filename, StrMakeValid(name), std::byteswap(grfid), grf_version);
}
/* GRF IDs starting with 0xFF are reserved for internal TTDPatch use */
if (GB(grfid, 0, 8) == 0xFF) SetBit(_cur.grfconfig->flags, GCF_SYSTEM);
if (GB(grfid, 0, 8) == 0xFF) _cur.grfconfig->flags.Set(GRFConfigFlag::System);
AddGRFTextToList(_cur.grfconfig->name, 0x7F, grfid, false, name);
@ -7351,7 +7351,7 @@ static void SafeParamSet(ByteReader &buf)
* reserved, it would be marked unsafe anyway. GRM for (e.g. bridge)
* sprites is considered safe. */
SetBit(_cur.grfconfig->flags, GCF_UNSAFE);
_cur.grfconfig->flags.Set(GRFConfigFlag::Unsafe);
/* Skip remainder of GRF */
_cur.skip_sprites = -1;
@ -7620,7 +7620,7 @@ static void ParamSet(ByteReader &buf)
/* Read another GRF File's parameter */
const GRFFile *file = GetFileByGRFID(data);
GRFConfig *c = GetGRFConfig(data);
if (c != nullptr && HasBit(c->flags, GCF_STATIC) && !HasBit(_cur.grfconfig->flags, GCF_STATIC) && _networking) {
if (c != nullptr && c->flags.Test(GRFConfigFlag::Static) && !_cur.grfconfig->flags.Test(GRFConfigFlag::Static) && _networking) {
/* Disable the read GRF if it is a static NewGRF. */
DisableStaticNewGRFInfluencingNonStaticNewGRFs(*c);
src1 = 0;
@ -7759,7 +7759,7 @@ static void ParamSet(ByteReader &buf)
ClrBit(res, GMB_TRAIN_WIDTH_32_PIXELS);
/* Only copy safe bits for static grfs */
if (HasBit(_cur.grfconfig->flags, GCF_STATIC)) {
if (_cur.grfconfig->flags.Test(GRFConfigFlag::Static)) {
uint32_t safe_bits = 0;
SetBit(safe_bits, GMB_SECOND_ROCKY_TILE_SET);
@ -7800,7 +7800,7 @@ static void SafeGRFInhibit(ByteReader &buf)
/* GRF is unsafe it if tries to deactivate other GRFs */
if (grfid != _cur.grfconfig->ident.grfid) {
SetBit(_cur.grfconfig->flags, GCF_UNSAFE);
_cur.grfconfig->flags.Set(GRFConfigFlag::Unsafe);
/* Skip remainder of GRF */
_cur.skip_sprites = -1;
@ -8636,7 +8636,7 @@ static void StaticGRFInfo(ByteReader &buf)
*/
static void GRFUnsafe(ByteReader &)
{
SetBit(_cur.grfconfig->flags, GCF_UNSAFE);
_cur.grfconfig->flags.Set(GRFConfigFlag::Unsafe);
/* Skip remainder of GRF */
_cur.skip_sprites = -1;
@ -9757,7 +9757,7 @@ void LoadNewGRFFile(GRFConfig &config, GrfLoadingStage stage, Subdirectory subdi
_cur.grffile = GetFileByFilename(filename);
if (_cur.grffile == nullptr) UserError("File '{}' lost in cache.\n", filename);
if (stage == GLS_RESERVE && config.status != GCS_INITIALISED) return;
if (stage == GLS_ACTIVATION && !HasBit(config.flags, GCF_RESERVED)) return;
if (stage == GLS_ACTIVATION && !config.flags.Test(GRFConfigFlag::Reserved)) return;
}
bool needs_palette_remap = config.palette & GRFP_USE_MASK;
@ -10141,7 +10141,7 @@ void LoadNewGRF(SpriteID load_index, uint num_baseset)
_cur.stage = stage;
for (const auto &c : _grfconfig) {
if (c->status == GCS_DISABLED || c->status == GCS_NOT_FOUND) continue;
if (stage > GLS_INIT && HasBit(c->flags, GCF_INIT_ONLY)) continue;
if (stage > GLS_INIT && c->flags.Test(GRFConfigFlag::InitOnly)) continue;
Subdirectory subdir = num_grfs < num_baseset ? BASESET_DIR : NEWGRF_DIR;
if (!FioCheckFileExists(c->filename, subdir)) {
@ -10152,7 +10152,7 @@ void LoadNewGRF(SpriteID load_index, uint num_baseset)
if (stage == GLS_LABELSCAN) InitNewGRFFile(*c);
if (!HasBit(c->flags, GCF_STATIC) && !HasBit(c->flags, GCF_SYSTEM)) {
if (!c->flags.Test(GRFConfigFlag::Static) && !c->flags.Test(GRFConfigFlag::System)) {
if (num_non_static == NETWORK_MAX_GRF_COUNT) {
Debug(grf, 0, "'{}' is not loaded as the maximum number of non-static GRFs has been reached", c->filename);
c->status = GCS_DISABLED;
@ -10166,14 +10166,14 @@ void LoadNewGRF(SpriteID load_index, uint num_baseset)
LoadNewGRFFile(*c, stage, subdir, false);
if (stage == GLS_RESERVE) {
SetBit(c->flags, GCF_RESERVED);
c->flags.Set(GRFConfigFlag::Reserved);
} else if (stage == GLS_ACTIVATION) {
ClrBit(c->flags, GCF_RESERVED);
c->flags.Reset(GRFConfigFlag::Reserved);
assert(GetFileByGRFID(c->ident.grfid) == _cur.grffile);
ClearTemporaryNewGRFData(_cur.grffile);
BuildCargoTranslationMap();
Debug(sprite, 2, "LoadNewGRF: Currently {} sprites are loaded", _cur.spriteid);
} else if (stage == GLS_INIT && HasBit(c->flags, GCF_INIT_ONLY)) {
} else if (stage == GLS_INIT && c->flags.Test(GRFConfigFlag::InitOnly)) {
/* We're not going to activate this, so free whatever data we allocated */
ClearTemporaryNewGRFData(_cur.grffile);
}

View File

@ -43,7 +43,7 @@ GRFConfig::GRFConfig(const GRFConfig &config) :
error(config.error),
version(config.version),
min_loadable_version(config.min_loadable_version),
flags(config.flags & ~(1 << GCF_COPY)),
flags(config.flags),
status(config.status),
grf_bugs(config.grf_bugs),
num_valid_params(config.num_valid_params),
@ -52,6 +52,7 @@ GRFConfig::GRFConfig(const GRFConfig &config) :
param_info(config.param_info),
param(config.param)
{
this->flags.Reset(GRFConfigFlag::Copy);
}
void GRFConfig::SetParams(std::span<const uint32_t> pars)
@ -306,14 +307,14 @@ bool FillGRFDetails(GRFConfig &config, bool is_static, Subdirectory subdir)
config.FinalizeParameterInfo();
/* Skip if the grfid is 0 (not read) or if it is an internal GRF */
if (config.ident.grfid == 0 || HasBit(config.flags, GCF_SYSTEM)) return false;
if (config.ident.grfid == 0 || config.flags.Test(GRFConfigFlag::System)) return false;
if (is_static) {
/* Perform a 'safety scan' for static GRFs */
LoadNewGRFFile(config, GLS_SAFETYSCAN, subdir, true);
/* GCF_UNSAFE is set if GLS_SAFETYSCAN finds unsafe actions */
if (HasBit(config.flags, GCF_UNSAFE)) return false;
/* GRFConfigFlag::Unsafe is set if GLS_SAFETYSCAN finds unsafe actions */
if (config.flags.Test(GRFConfigFlag::Unsafe)) return false;
}
return CalcGRFMD5Sum(config, subdir);
@ -340,7 +341,11 @@ static void AppendGRFConfigList(GRFConfigList &dst, const GRFConfigList &src, bo
{
for (const auto &s : src) {
auto &c = dst.emplace_back(std::make_unique<GRFConfig>(*s));
AssignBit(c->flags, GCF_INIT_ONLY, init_only);
if (init_only) {
c->flags.Set(GRFConfigFlag::InitOnly);
} else {
c->flags.Reset(GRFConfigFlag::InitOnly);
}
}
}
@ -428,15 +433,15 @@ GRFListCompatibility IsGoodGRFConfigList(GRFConfigList &grfconfig)
for (auto &c : grfconfig) {
const GRFConfig *f = FindGRFConfig(c->ident.grfid, FGCM_EXACT, &c->ident.md5sum);
if (f == nullptr || HasBit(f->flags, GCF_INVALID)) {
if (f == nullptr || f->flags.Test(GRFConfigFlag::Invalid)) {
/* If we have not found the exactly matching GRF try to find one with the
* same grfid, as it most likely is compatible */
f = FindGRFConfig(c->ident.grfid, FGCM_COMPATIBLE, nullptr, c->version);
if (f != nullptr) {
Debug(grf, 1, "NewGRF {:08X} ({}) not found; checksum {}. Compatibility mode on", std::byteswap(c->ident.grfid), c->filename, FormatArrayAsHex(c->ident.md5sum));
if (!HasBit(c->flags, GCF_COMPATIBLE)) {
if (!c->flags.Test(GRFConfigFlag::Compatible)) {
/* Preserve original_md5sum after it has been assigned */
SetBit(c->flags, GCF_COMPATIBLE);
c->flags.Set(GRFConfigFlag::Compatible);
c->original_md5sum = c->ident.md5sum;
}
@ -456,9 +461,9 @@ compatible_grf:
/* The filename could be the filename as in the savegame. As we need
* to load the GRF here, we need the correct filename, so overwrite that
* in any case and set the name and info when it is not set already.
* When the GCF_COPY flag is set, it is certain that the filename is
* When the GRFConfigFlag::Copy flag is set, it is certain that the filename is
* already a local one, so there is no need to replace it. */
if (!HasBit(c->flags, GCF_COPY)) {
if (!c->flags.Test(GRFConfigFlag::Copy)) {
c->filename = f->filename;
c->ident.md5sum = f->ident.md5sum;
c->name = f->name;
@ -605,7 +610,7 @@ const GRFConfig *FindGRFConfig(uint32_t grfid, FindGRFConfigMode mode, const MD5
/* return it, if the exact same newgrf is found, or if we do not care about finding "the best" */
if (md5sum != nullptr || mode == FGCM_ANY) return c.get();
/* Skip incompatible stuff, unless explicitly allowed */
if (mode != FGCM_NEWEST && HasBit(c->flags, GCF_INVALID)) continue;
if (mode != FGCM_NEWEST && c->flags.Test(GRFConfigFlag::Invalid)) continue;
/* check version compatibility */
if (mode == FGCM_COMPATIBLE && !c->IsCompatible(desired_version)) continue;
/* remember the newest one as "the best" */

View File

@ -17,16 +17,17 @@
#include "3rdparty/md5/md5.h"
/** GRF config bit flags */
enum GCF_Flags : uint8_t {
GCF_SYSTEM, ///< GRF file is an openttd-internal system grf
GCF_UNSAFE, ///< GRF file is unsafe for static usage
GCF_STATIC, ///< GRF file is used statically (can be used in any MP game)
GCF_COMPATIBLE, ///< GRF file does not exactly match the requested GRF (different MD5SUM), but grfid matches)
GCF_COPY, ///< The data is copied from a grf in _all_grfs
GCF_INIT_ONLY, ///< GRF file is processed up to GLS_INIT
GCF_RESERVED, ///< GRF file passed GLS_RESERVE stage
GCF_INVALID, ///< GRF is unusable with this version of OpenTTD
enum GRFConfigFlag : uint8_t {
System, ///< GRF file is an openttd-internal system grf
Unsafe, ///< GRF file is unsafe for static usage
Static, ///< GRF file is used statically (can be used in any MP game)
Compatible, ///< GRF file does not exactly match the requested GRF (different MD5SUM), but grfid matches)
Copy, ///< The data is copied from a grf in _all_grfs
InitOnly, ///< GRF file is processed up to GLS_INIT
Reserved, ///< GRF file passed GLS_RESERVE stage
Invalid, ///< GRF is unusable with this version of OpenTTD
};
using GRFConfigFlags = EnumBitSet<GRFConfigFlag, uint8_t>;
/** Status of GRF */
enum GRFStatus : uint8_t {
@ -172,7 +173,7 @@ struct GRFConfig {
uint32_t version = 0; ///< NOSAVE: Version a NewGRF can set so only the newest NewGRF is shown
uint32_t min_loadable_version = 0; ///< NOSAVE: Minimum compatible version a NewGRF can define
uint8_t flags = 0; ///< NOSAVE: GCF_Flags, bitset
GRFConfigFlags flags = {}; ///< NOSAVE: GCF_Flags, bitset
GRFStatus status = GCS_UNKNOWN; ///< NOSAVE: GRFStatus, enum
GRFBugs grf_bugs = {}; ///< NOSAVE: bugs in this GRF in this run, @see enum GRFBugs
uint8_t num_valid_params = MAX_NUM_PARAMS; ///< NOSAVE: Number of valid parameters (action 0x14)
@ -205,7 +206,7 @@ enum FindGRFConfigMode : uint8_t {
FGCM_EXACT, ///< Only find Grfs matching md5sum
FGCM_COMPATIBLE, ///< Find best compatible Grf wrt. desired_version
FGCM_NEWEST, ///< Find newest Grf
FGCM_NEWEST_VALID,///< Find newest Grf, ignoring Grfs with GCF_INVALID set
FGCM_NEWEST_VALID,///< Find newest Grf, ignoring Grfs with GRFConfigFlag::Invalid set
FGCM_ANY, ///< Use first found
};

View File

@ -128,8 +128,8 @@ static void ShowNewGRFInfo(const GRFConfig &c, const Rect &r, bool show_params)
/* Show flags */
if (c.status == GCS_NOT_FOUND) tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_NOT_FOUND);
if (c.status == GCS_DISABLED) tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_DISABLED);
if (HasBit(c.flags, GCF_INVALID)) tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_INCOMPATIBLE);
if (HasBit(c.flags, GCF_COMPATIBLE)) tr.top = DrawStringMultiLine(tr, STR_NEWGRF_COMPATIBLE_LOADED);
if (c.flags.Test(GRFConfigFlag::Invalid)) tr.top = DrawStringMultiLine(tr, STR_NEWGRF_SETTINGS_INCOMPATIBLE);
if (c.flags.Test(GRFConfigFlag::Compatible)) tr.top = DrawStringMultiLine(tr, STR_NEWGRF_COMPATIBLE_LOADED);
/* Draw GRF info if it exists */
if (!StrEmpty(c.GetDescription())) {
@ -834,9 +834,9 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
/* Do not show a "not-failure" colour when it actually failed to load */
if (pal != PALETTE_TO_RED) {
if (HasBit(c.flags, GCF_STATIC)) {
if (c.flags.Test(GRFConfigFlag::Static)) {
pal = PALETTE_TO_GREY;
} else if (HasBit(c.flags, GCF_COMPATIBLE)) {
} else if (c.flags.Test(GRFConfigFlag::Compatible)) {
pal = PALETTE_TO_ORANGE;
}
}
@ -1081,7 +1081,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
}
this->InvalidateData();
if (click_count == 1) {
if (this->editable && this->avail_sel != nullptr && !HasBit(this->avail_sel->flags, GCF_INVALID)) SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
if (this->editable && this->avail_sel != nullptr && !this->avail_sel->flags.Test(GRFConfigFlag::Invalid)) SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this);
break;
}
/* With double click, continue */
@ -1089,7 +1089,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
}
case WID_NS_ADD:
if (this->avail_sel == nullptr || !this->editable || HasBit(this->avail_sel->flags, GCF_INVALID)) break;
if (this->avail_sel == nullptr || !this->editable || this->avail_sel->flags.Test(GRFConfigFlag::Invalid)) break;
this->AddGRFToActive();
break;
@ -1221,11 +1221,11 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
case GOID_NEWGRF_RESCANNED:
/* Search the list for items that are now found and mark them as such. */
for (auto &c : this->actives) {
bool compatible = HasBit(c->flags, GCF_COMPATIBLE);
bool compatible = c->flags.Test(GRFConfigFlag::Compatible);
if (c->status != GCS_NOT_FOUND && !compatible) continue;
const GRFConfig *f = FindGRFConfig(c->ident.grfid, FGCM_EXACT, compatible ? &c->original_md5sum : &c->ident.md5sum);
if (f == nullptr || HasBit(f->flags, GCF_INVALID)) continue;
if (f == nullptr || f->flags.Test(GRFConfigFlag::Invalid)) continue;
c = std::make_unique<GRFConfig>(*f);
}
@ -1263,7 +1263,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
WID_NS_PRESET_LIST,
WID_NS_TOGGLE_PALETTE
);
this->SetWidgetDisabledState(WID_NS_ADD, !this->editable || this->avail_sel == nullptr || HasBit(this->avail_sel->flags, GCF_INVALID));
this->SetWidgetDisabledState(WID_NS_ADD, !this->editable || this->avail_sel == nullptr || this->avail_sel->flags.Test(GRFConfigFlag::Invalid));
this->SetWidgetDisabledState(WID_NS_UPGRADE, !this->editable || this->actives.empty() || !this->CanUpgradeCurrent());
bool disable_all = this->active_sel == nullptr || !this->editable;
@ -1296,7 +1296,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback {
bool has_compatible = false;
for (const auto &c : this->actives) {
has_missing |= c->status == GCS_NOT_FOUND;
has_compatible |= HasBit(c->flags, GCF_COMPATIBLE);
has_compatible |= c->flags.Test(GRFConfigFlag::Compatible);
}
StringID text;
StringID tool_tip;
@ -1443,7 +1443,7 @@ private:
if (_settings_client.gui.newgrf_show_old_versions) {
this->avails.push_back(c.get());
} else {
const GRFConfig *best = FindGRFConfig(c->ident.grfid, HasBit(c->flags, GCF_INVALID) ? FGCM_NEWEST : FGCM_NEWEST_VALID);
const GRFConfig *best = FindGRFConfig(c->ident.grfid, c->flags.Test(GRFConfigFlag::Invalid) ? FGCM_NEWEST : FGCM_NEWEST_VALID);
/* Never triggers; FindGRFConfig returns either c, or a newer version of c. */
assert(best != nullptr);
@ -1481,12 +1481,12 @@ private:
*/
bool AddGRFToActive(int ins_pos = -1)
{
if (this->avail_sel == nullptr || !this->editable || HasBit(this->avail_sel->flags, GCF_INVALID)) return false;
if (this->avail_sel == nullptr || !this->editable || this->avail_sel->flags.Test(GRFConfigFlag::Invalid)) return false;
CloseWindowByClass(WC_TEXTFILE);
/* Get number of non-static NewGRFs. */
size_t count = std::ranges::count_if(this->actives, [](const auto &gc) { return !HasBit(gc->flags, GCF_STATIC); });
size_t count = std::ranges::count_if(this->actives, [](const auto &gc) { return !gc->flags.Test(GRFConfigFlag::Static); });
if (count >= NETWORK_MAX_GRF_COUNT) {
ShowErrorMessage(STR_NEWGRF_TOO_MANY_NEWGRFS, INVALID_STRING_ID, WL_INFO);
return false;
@ -1527,14 +1527,14 @@ void ShowMissingContentWindow(const GRFConfigList &list)
/* Only show the things in the current list, or everything when nothing's selected */
ContentVector cv;
for (const auto &c : list) {
if (c->status != GCS_NOT_FOUND && !HasBit(c->flags, GCF_COMPATIBLE)) continue;
if (c->status != GCS_NOT_FOUND && !c->flags.Test(GRFConfigFlag::Compatible)) continue;
ContentInfo *ci = new ContentInfo();
ci->type = CONTENT_TYPE_NEWGRF;
ci->state = ContentInfo::DOES_NOT_EXIST;
ci->name = c->GetName();
ci->unique_id = std::byteswap(c->ident.grfid);
ci->md5sum = HasBit(c->flags, GCF_COMPATIBLE) ? c->original_md5sum : c->ident.md5sum;
ci->md5sum = c->flags.Test(GRFConfigFlag::Compatible) ? c->original_md5sum : c->ident.md5sum;
cv.push_back(ci);
}
ShowNetworkContentListWindow(cv.empty() ? nullptr : &cv, CONTENT_TYPE_NEWGRF);

View File

@ -244,7 +244,7 @@ static void WriteSavegameInfo(const std::string &name)
if (_load_check_data.HasNewGrfs()) {
for (const auto &c : _load_check_data.grfconfig) {
fmt::format_to(std::back_inserter(message), "{:08X} {} {}\n", std::byteswap(c->ident.grfid),
FormatArrayAsHex(HasBit(c->flags, GCF_COMPATIBLE) ? c->original_md5sum : c->ident.md5sum), c->filename);
FormatArrayAsHex(c->flags.Test(GRFConfigFlag::Compatible) ? c->original_md5sum : c->ident.md5sum), c->filename);
}
}

View File

@ -369,7 +369,7 @@ static void CDECL HandleSavegameLoadCrash(int signum)
message.reserve(1024);
message += "Loading your savegame caused OpenTTD to crash.\n";
_saveload_crash_with_missing_newgrfs = std::ranges::any_of(_grfconfig, [](const auto &c) { return HasBit(c->flags, GCF_COMPATIBLE) || c->status == GCS_NOT_FOUND; });
_saveload_crash_with_missing_newgrfs = std::ranges::any_of(_grfconfig, [](const auto &c) { return c->flags.Test(GRFConfigFlag::Compatible) || c->status == GCS_NOT_FOUND; });
if (_saveload_crash_with_missing_newgrfs) {
message +=
@ -386,7 +386,7 @@ static void CDECL HandleSavegameLoadCrash(int signum)
"The missing/compatible NewGRFs are:\n";
for (const auto &c : _grfconfig) {
if (HasBit(c->flags, GCF_COMPATIBLE)) {
if (c->flags.Test(GRFConfigFlag::Compatible)) {
const GRFIdentifier &replaced = _gamelog.GetOverriddenIdentifier(*c);
fmt::format_to(std::back_inserter(message), "NewGRF {:08X} (checksum {}) not found.\n Loaded NewGRF \"{}\" (checksum {}) with same GRF ID instead.\n",
std::byteswap(c->ident.grfid), FormatArrayAsHex(c->original_md5sum), c->filename, FormatArrayAsHex(replaced.md5sum));
@ -708,7 +708,7 @@ bool AfterLoadGame()
for (const auto &c : _grfconfig) {
if (c->status == GCS_NOT_FOUND) {
_gamelog.GRFRemove(c->ident.grfid);
} else if (HasBit(c->flags, GCF_COMPATIBLE)) {
} else if (c->flags.Test(GRFConfigFlag::Compatible)) {
_gamelog.GRFCompatible(c->ident);
}
}

View File

@ -92,7 +92,7 @@ struct NGRFChunkHandler : ChunkHandler {
int index = 0;
for (const auto &c : _grfconfig) {
if (HasBit(c->flags, GCF_STATIC) || HasBit(c->flags, GCF_INIT_ONLY)) continue;
if (c->flags.Any({GRFConfigFlag::Static, GRFConfigFlag::InitOnly})) continue;
this->SaveParameters(*c);
SlSetArrayIndex(index++);
SlObject(c.get(), description);

View File

@ -18,7 +18,7 @@
ScriptNewGRFList::ScriptNewGRFList()
{
for (const auto &c : _grfconfig) {
if (!HasBit(c->flags, GCF_STATIC)) {
if (!c->flags.Test(GRFConfigFlag::Static)) {
this->AddItem(std::byteswap(c->ident.grfid));
}
}
@ -28,14 +28,14 @@ ScriptNewGRFList::ScriptNewGRFList()
{
grfid = std::byteswap(GB(grfid, 0, 32)); // Match people's expectations.
return std::ranges::any_of(_grfconfig, [grfid](const auto &c) { return !HasBit(c->flags, GCF_STATIC) && c->ident.grfid == grfid; });
return std::ranges::any_of(_grfconfig, [grfid](const auto &c) { return !c->flags.Test(GRFConfigFlag::Static) && c->ident.grfid == grfid; });
}
/* static */ SQInteger ScriptNewGRF::GetVersion(SQInteger grfid)
{
grfid = std::byteswap(GB(grfid, 0, 32)); // Match people's expectations.
auto it = std::ranges::find_if(_grfconfig, [grfid](const auto &c) { return !HasBit(c->flags, GCF_STATIC) && c->ident.grfid == grfid; });
auto it = std::ranges::find_if(_grfconfig, [grfid](const auto &c) { return !c->flags.Test(GRFConfigFlag::Static) && c->ident.grfid == grfid; });
if (it != std::end(_grfconfig)) return (*it)->version;
return 0;
@ -45,7 +45,7 @@ ScriptNewGRFList::ScriptNewGRFList()
{
grfid = std::byteswap(GB(grfid, 0, 32)); // Match people's expectations.
auto it = std::ranges::find_if(_grfconfig, [grfid](const auto &c) { return !HasBit(c->flags, GCF_STATIC) && c->ident.grfid == grfid; });
auto it = std::ranges::find_if(_grfconfig, [grfid](const auto &c) { return !c->flags.Test(GRFConfigFlag::Static) && c->ident.grfid == grfid; });
if (it != std::end(_grfconfig)) return (*it)->GetName();
return std::nullopt;

View File

@ -1107,14 +1107,14 @@ static GRFConfigList GRFLoadConfig(const IniFile &ini, const char *grpname, bool
}
/* Check if item is valid */
if (!FillGRFDetails(*c, is_static) || HasBit(c->flags, GCF_INVALID)) {
if (!FillGRFDetails(*c, is_static) || c->flags.Test(GRFConfigFlag::Invalid)) {
if (c->status == GCS_NOT_FOUND) {
SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_NOT_FOUND);
} else if (HasBit(c->flags, GCF_UNSAFE)) {
} else if (c->flags.Test(GRFConfigFlag::Unsafe)) {
SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNSAFE);
} else if (HasBit(c->flags, GCF_SYSTEM)) {
} else if (c->flags.Test(GRFConfigFlag::System)) {
SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_SYSTEM);
} else if (HasBit(c->flags, GCF_INVALID)) {
} else if (c->flags.Test(GRFConfigFlag::Invalid)) {
SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_INCOMPATIBLE);
} else {
SetDParam(1, STR_CONFIG_ERROR_INVALID_GRF_UNKNOWN);
@ -1136,7 +1136,7 @@ static GRFConfigList GRFLoadConfig(const IniFile &ini, const char *grpname, bool
if (is_static) {
/* Mark file as static to avoid saving in savegame. */
SetBit(c->flags, GCF_STATIC);
c->flags.Set(GRFConfigFlag::Static);
} else if (++num_grfs > NETWORK_MAX_GRF_COUNT) {
/* Check we will not load more non-static NewGRFs than allowed. This could trigger issues for game servers. */
ShowErrorMessage(STR_CONFIG_ERROR, STR_NEWGRF_ERROR_TOO_MANY_NEWGRFS_LOADED, WL_CRITICAL);

View File

@ -369,7 +369,7 @@ void SurveyGrfs(nlohmann::json &survey)
if ((c->palette & GRFP_BLT_MASK) == GRFP_BLT_UNSET) grf["blitter"] = "unset";
if ((c->palette & GRFP_BLT_MASK) == GRFP_BLT_32BPP) grf["blitter"] = "32bpp";
grf["is_static"] = HasBit(c->flags, GCF_STATIC);
grf["is_static"] = c->flags.Test(GRFConfigFlag::Static);
grf["parameters"] = std::span<const uint32_t>(c->param);
}
}