mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-22 19:54:06 +01:00
Codechange: Use EnumBitSet for callback masks.
This commit is contained in:
committed by
Peter Nelson
parent
1dd4adc50c
commit
40aeedeade
@@ -102,11 +102,20 @@ struct NICallback {
|
||||
std::string_view name; ///< The human readable name of the callback
|
||||
NIOffsetProc *offset_proc; ///< Callback proc to get the actual variable address in memory
|
||||
uint8_t read_size; ///< The number of bytes (i.e. byte, word, dword etc) to read
|
||||
uint8_t cb_bit; ///< The bit that needs to be set for this callback to be enabled
|
||||
std::variant<
|
||||
std::monostate,
|
||||
VehicleCallbackMask,
|
||||
StationCallbackMask,
|
||||
RoadStopCallbackMask,
|
||||
HouseCallbackMask,
|
||||
CanalCallbackMask,
|
||||
CargoCallbackMask,
|
||||
IndustryCallbackMask,
|
||||
IndustryTileCallbackMask,
|
||||
ObjectCallbackMask,
|
||||
AirportTileCallbackMask> cb_bit; ///< The bit that needs to be set for this callback to be enabled
|
||||
uint16_t cb_id; ///< The number of the callback
|
||||
};
|
||||
/** Mask to show no bit needs to be enabled for the callback. */
|
||||
static const int CBM_NO_BIT = UINT8_MAX;
|
||||
|
||||
/** Representation on the NewGRF variables. */
|
||||
struct NIVariable {
|
||||
@@ -508,7 +517,7 @@ struct NewGRFInspectWindow : Window {
|
||||
if (!nif->callbacks.empty()) {
|
||||
this->DrawString(r, i++, "Callbacks:");
|
||||
for (const NICallback &nic : nif->callbacks) {
|
||||
if (nic.cb_bit != CBM_NO_BIT) {
|
||||
if (!std::holds_alternative<std::monostate>(nic.cb_bit)) {
|
||||
const void *ptr = nic.offset_proc(base_spec);
|
||||
uint value;
|
||||
switch (nic.read_size) {
|
||||
@@ -518,7 +527,23 @@ struct NewGRFInspectWindow : Window {
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
|
||||
if (!HasBit(value, nic.cb_bit)) continue;
|
||||
struct visitor {
|
||||
uint value;
|
||||
|
||||
bool operator()(const std::monostate &) { return false; }
|
||||
bool operator()(const VehicleCallbackMask &bit) { return static_cast<VehicleCallbackMasks>(this->value).Test(bit); }
|
||||
bool operator()(const StationCallbackMask &bit) { return static_cast<StationCallbackMasks>(this->value).Test(bit); }
|
||||
bool operator()(const RoadStopCallbackMask &bit) { return static_cast<RoadStopCallbackMasks>(this->value).Test(bit); }
|
||||
bool operator()(const HouseCallbackMask &bit) { return static_cast<HouseCallbackMasks>(this->value).Test(bit); }
|
||||
bool operator()(const CanalCallbackMask &bit) { return static_cast<CanalCallbackMasks>(this->value).Test(bit); }
|
||||
bool operator()(const CargoCallbackMask &bit) { return static_cast<CargoCallbackMasks>(this->value).Test(bit); }
|
||||
bool operator()(const IndustryCallbackMask &bit) { return static_cast<IndustryCallbackMasks>(this->value).Test(bit); }
|
||||
bool operator()(const IndustryTileCallbackMask &bit) { return static_cast<IndustryTileCallbackMasks>(this->value).Test(bit); }
|
||||
bool operator()(const ObjectCallbackMask &bit) { return static_cast<ObjectCallbackMasks>(this->value).Test(bit); }
|
||||
bool operator()(const AirportTileCallbackMask &bit) { return static_cast<AirportTileCallbackMasks>(this->value).Test(bit); }
|
||||
};
|
||||
|
||||
if (!std::visit(visitor{value}, nic.cb_bit)) continue;
|
||||
this->DrawString(r, i++, fmt::format(" {:03x}: {}", nic.cb_id, nic.name));
|
||||
} else {
|
||||
this->DrawString(r, i++, fmt::format(" {:03x}: {} (unmasked)", nic.cb_id, nic.name));
|
||||
|
||||
Reference in New Issue
Block a user