18SpriteGroupPool _spritegroup_pool(
"SpriteGroup");
36 if (group ==
nullptr)
return std::monostate{};
38 const GRFFile *grf =
object.grffile;
41 if (profiler == _newgrf_profilers.end() || !profiler->active) {
43 }
else if (top_level) {
44 profiler->BeginResolve(
object);
45 auto result = group->
Resolve(
object);
46 profiler->EndResolve(result);
49 profiler->RecursiveResolve();
54static inline uint32_t GetVariable(
const ResolverObject &
object,
ScopeResolver *scope, uint8_t variable, uint32_t parameter,
bool &available)
58 case 0x0C:
return object.callback;
59 case 0x10:
return object.callback_param1;
60 case 0x18:
return object.callback_param2;
61 case 0x1C:
return object.last_value;
65 case 0x7D:
return object.GetRegister(parameter);
68 if (
object.grffile ==
nullptr)
return 0;
69 return object.grffile->GetParam(parameter);
73 if (variable < 0x40 &&
GetGlobalVariable(variable, &value,
object.grffile))
return value;
75 return scope->
GetVariable(variable, parameter, available);
106 this->
ro.UnhandledVariable(variable);
174 if (!
_unhandled_variables.emplace(this->grffile->grfid, this->GetFeature(), variable, this->callback).second)
return;
176 Debug(
Facility::Grf,
Severity::Error,
"[{}:{}] Unhandled feature 0x{:X} variable 0x{:X} during callback 0x{:X}", this->
grffile->filename, this->root_spritegroup->nfo_line, this->GetFeature(), variable, this->callback);
181template <
typename U,
typename S>
184 value >>= adjust.shift_num;
185 value &= adjust.and_mask;
187 switch (adjust.type) {
193 switch (adjust.operation) {
217 default:
return value;
224 return range.high < value;
229 uint32_t last_value = 0;
234 for (
const auto &adjust : this->adjusts) {
236 bool available =
true;
237 if (adjust.variable == 0x7E) {
239 auto *subvalue = std::get_if<CallbackResult>(&subgroup);
240 value = subvalue !=
nullptr ? *subvalue : UINT16_MAX;
243 }
else if (adjust.variable == 0x7B) {
244 value = GetVariable(
object, scope, adjust.
parameter, last_value, available);
246 value = GetVariable(
object, scope, adjust.variable, adjust.
parameter, available);
255 switch (this->size) {
259 default: NOT_REACHED();
264 object.last_value = last_value;
268 if (this->ranges.size() > 4) {
269 const auto &lower = std::lower_bound(this->ranges.begin(), this->ranges.end(), value, RangeHighComparator);
270 if (lower != this->ranges.end() && lower->low <= value) {
271 assert(lower->low <= value && value <= lower->high);
272 result = lower->result;
275 for (
const auto &range : this->ranges) {
276 if (range.low <= value && value <= range.high) {
277 result = range.result;
283 if (result.calculated_result) {
284 return static_cast<CallbackResult
>(
GB(value, 0, 15));
295 uint8_t match = this->triggers &
object.GetWaitingRandomTriggers();
299 object.AddUsedRandomTriggers(match);
333 if (!this->dts.NeedsPreprocessing()) {
334 if (stage !=
nullptr && this->dts.consistent_max_offset > 0) *stage =
GetConstructionStageOffset(*stage, this->dts.consistent_max_offset);
338 uint8_t actual_stage = stage !=
nullptr ? *stage : 0;
343 if (stage !=
nullptr) *stage = 0;
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Add dynamic register values to a sprite layout.
void ProcessRegisters(const struct ResolverObject &object, uint8_t resolved_var10, uint32_t resolved_sprite)
Evaluates the register modifiers and integrates them into the preprocessed sprite layout.
Functions related to debugging.
bool IsVisibleSeverity(Facility facility, Severity severity)
Test if debug severity is visible for the given facility.
#define Debug(facility, severity, format_string,...)
Output a line of debugging information.
@ Grf
Grf message facility.
@ Error
Error, but we are recovering.
#define S
Climate sub-tropic.
bool GetGlobalVariable(uint8_t param, uint32_t *value, const GRFFile *grffile)
Reads a variable common to VarAction2 and Action7/9/D.
CallbackID
List of implemented NewGRF callbacks.
@ CBID_RANDOM_TRIGGER
Set when calling a randomizing trigger (almost undocumented).
uint GetConstructionStageOffset(uint construction_stage, uint num_sprites)
Determines which sprite to use from a spriteset for a specific construction stage.
Profiling of NewGRF action 2 handling.
std::set< UnhandledVariableItem > _unhandled_variables
Set of unhandled variables that have been seen.
void ResetUnhandledVariableWarnings()
Reset unhandled variable warnings.
@ DWord
Treat variable as a DWord.
@ Word
Treat variable as a Word.
@ Byte
Treat variable as a Byte.
@ Stop
store a into persistent storage, indexed by b, return a
@ UMin
(unsigned) min(a, b)
@ Sto
store a into temporary storage, indexed by b. return a
@ UCmp
(unsigned) comparison (a < b -> 0, a == b = 1, a > b = 2)
@ Ror
rotate a b positions to the right
@ UMax
(unsigned) max(a, b)
@ SCmp
(signed) comparison (a < b -> 0, a == b = 1, a > b = 2)
VarSpriteGroupScope
Shared by deterministic and random groups.
@ Any
Match if any bit is triggered.
@ Div
Apply divide adjustment to value.
@ Mod
Apply modulus adjustment to value.
std::variant< std::monostate, CallbackResult, const ResultSpriteGroup *, const TileLayoutSpriteGroup *, const IndustryProductionSpriteGroup * > ResolverResult
Result of resolving sprite groups:
Label< struct GrfIDTag > GrfID
The unique identifier of a NewGRF.
Some methods of Pool are placed here in order to reduce compilation time and binary size.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
A number of safeguards to prevent using unsafe methods.
Definition of base types and functions in a cross-platform compatible way.
ResolverResult Resolve(ResolverObject &object) const override
Resolves a callback or rerandomisation callback to a NewGRF.
uint8_t parameter
Used for variables between 0x60 and 0x7F inclusive.
ResolverResult Resolve(ResolverObject &object) const override
Resolves a callback or rerandomisation callback to a NewGRF.
DeterministicSpriteGroupResult default_result
Dynamically allocated, this is the sole owner.
const SpriteGroup * error_group
Was first range, before sorting ranges.
Dynamic data of a loaded NewGRF.
const GRFFile * grffile
Which GRF is being profiled.
const SpriteGroupID index
uint8_t lowest_randbit
Look for this in the per-object randomized bitmask:
VarSpriteGroupScope var_scope
Take this object:
std::vector< const SpriteGroup * > groups
Take the group with appropriate index:
ResolverResult Resolve(ResolverObject &object) const override
Resolves a callback or rerandomisation callback to a NewGRF.
RandomizedSpriteGroupCompareMode cmp_mode
Check for these triggers:
'Real' sprite groups contain a list of other result or callback sprite groups.
ResolverResult Resolve(ResolverObject &object) const override
Resolves a callback or rerandomisation callback to a NewGRF.
std::vector< const SpriteGroup * > loaded
List of loaded groups (can be SpriteIDs or Callback results).
std::vector< const SpriteGroup * > loading
List of loading groups (can be SpriteIDs or Callback results).
Interface for SpriteGroup-s to access the gamestate.
const GRFFile * grffile
GRFFile the resolved SpriteGroup belongs to.
void UnhandledVariable(uint8_t variable) const
Log a message for an unhandled NewGRF variable.
ScopeResolver default_scope
Default implementation of the grf scope.
virtual ScopeResolver * GetScope(VarSpriteGroupScope scope=VarSpriteGroupScope::Self, uint8_t relative=0)
Get a resolver for the scope.
virtual const SpriteGroup * ResolveReal(const RealSpriteGroup &group) const
Get the real sprites of the grf.
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope).
virtual void StorePSA(uint reg, int32_t value)
Store a value into the persistent storage area (PSA).
virtual uint32_t GetVariable(uint8_t variable, uint32_t parameter, bool &available) const
Get a variable value.
ResolverObject & ro
Surrounding resolver object.
virtual uint32_t GetRandomTriggers() const
Get the triggers.
virtual uint32_t GetRandomBits() const
Get a few random bits.
Common wrapper for all the different sprite group types.
SpriteGroup(SpriteGroupID index)
Create the SpriteGroup.
virtual ResolverResult Resolve(ResolverObject &object) const =0
Resolves a callback or rerandomisation callback to a NewGRF.
Class for temporary storage of data.
SpriteLayoutProcessor ProcessRegisters(const ResolverObject &object, uint8_t *stage) const
Process registers and the construction stage into the sprite layout.
Record of unhandled variables.
CallbackID callback
The callback.
uint8_t variable
The variable.
constexpr auto operator<=>(const UnhandledVariableItem &) const =default
Compare with another instance of this class.
GrfSpecFeature feature
The feature.