37 if (group ==
nullptr)
return nullptr;
39 const GRFFile *grf =
object.grffile;
40 auto profiler = std::find_if(_newgrf_profilers.begin(), _newgrf_profilers.end(), [&](
const NewGRFProfiler &pr) {
return pr.grffile == grf; });
42 if (profiler == _newgrf_profilers.end() || !profiler->active) {
43 if (top_level) _temp_store.ClearChanges();
45 }
else if (top_level) {
46 profiler->BeginResolve(
object);
47 _temp_store.ClearChanges();
49 profiler->EndResolve(result);
52 profiler->RecursiveResolve();
57 RealSpriteGroup::~RealSpriteGroup()
63 DeterministicSpriteGroup::~DeterministicSpriteGroup()
69 RandomizedSpriteGroup::~RandomizedSpriteGroup()
74 static inline uint32 GetVariable(
const ResolverObject &
object,
ScopeResolver *scope, byte variable, uint32 parameter,
bool *available)
78 case 0x0C:
return object.callback;
79 case 0x10:
return object.callback_param1;
80 case 0x18:
return object.callback_param2;
81 case 0x1C:
return object.last_value;
85 case 0x7D:
return _temp_store.
GetValue(parameter);
88 if (
object.grffile ==
nullptr)
return 0;
89 return object.grffile->GetParam(parameter);
93 if (variable < 0x40 &&
GetGlobalVariable(variable, &value,
object.grffile))
return value;
95 return scope->
GetVariable(variable, parameter, available);
126 DEBUG(grf, 1,
"Unhandled scope variable 0x%X", variable);
156 return &this->default_scope;
161 template <
typename U,
typename S>
164 value >>= adjust->shift_num;
165 value &= adjust->and_mask;
167 switch (adjust->type) {
168 case DSGA_TYPE_DIV: value = ((S)value + (S)adjust->add_val) / (S)adjust->divmod_val;
break;
169 case DSGA_TYPE_MOD: value = ((S)value + (S)adjust->add_val) % (S)adjust->divmod_val;
break;
170 case DSGA_TYPE_NONE:
break;
173 switch (adjust->operation) {
180 case DSGA_OP_SDIV:
return value == 0 ? (S)last_value : (S)last_value / (S)value;
181 case DSGA_OP_SMOD:
return value == 0 ? (S)last_value : (S)last_value % (S)value;
182 case DSGA_OP_UDIV:
return value == 0 ? (U)last_value : (U)last_value / (U)value;
183 case DSGA_OP_UMOD:
return value == 0 ? (U)last_value : (U)last_value % (U)value;
191 case DSGA_OP_ROR:
return ROR<uint32>((U)last_value, (U)value & 0x1F);
192 case DSGA_OP_SCMP:
return ((S)last_value == (S)value) ? 1 : ((S)last_value < (S)value ? 0 : 2);
193 case DSGA_OP_UCMP:
return ((U)last_value == (U)value) ? 1 : ((U)last_value < (U)value ? 0 : 2);
194 case DSGA_OP_SHL:
return (uint32)(U)last_value << ((U)value & 0x1F);
195 case DSGA_OP_SHR:
return (uint32)(U)last_value >> ((U)value & 0x1F);
196 case DSGA_OP_SAR:
return (int32)(S)last_value >> ((U)value & 0x1F);
197 default:
return value;
204 return range.high < value;
209 uint32 last_value = 0;
215 for (i = 0; i < this->num_adjusts; i++) {
219 bool available =
true;
220 if (adjust->variable == 0x7E) {
222 if (subgroup ==
nullptr) {
225 value = subgroup->GetCallbackResult();
229 }
else if (adjust->variable == 0x7B) {
230 value = GetVariable(
object, scope, adjust->
parameter, last_value, &available);
232 value = GetVariable(
object, scope, adjust->variable, adjust->
parameter, &available);
241 switch (this->size) {
242 case DSG_SIZE_BYTE: value = EvalAdjustT<uint8, int8> (adjust, scope, last_value, value);
break;
243 case DSG_SIZE_WORD: value = EvalAdjustT<uint16, int16>(adjust, scope, last_value, value);
break;
244 case DSG_SIZE_DWORD: value = EvalAdjustT<uint32, int32>(adjust, scope, last_value, value);
break;
245 default: NOT_REACHED();
250 object.last_value = last_value;
252 if (this->calculated_result) {
256 nvarzero.result = value;
260 if (this->num_ranges > 4) {
262 if (lower != this->ranges + this->num_ranges && lower->low <= value) {
263 assert(lower->low <= value && value <= lower->high);
267 for (i = 0; i < this->num_ranges; i++) {
268 if (this->ranges[i].low <= value && value <= this->ranges[i].high) {
280 ScopeResolver *scope =
object.GetScope(this->var_scope, this->count);
283 byte match = this->triggers &
object.waiting_triggers;
284 bool res = (this->cmp_mode == RSG_CMP_ANY) ? (match != 0) : (match == this->triggers);
287 object.used_triggers |= match;
288 object.reseed[this->var_scope] |= (this->num_groups - 1) << this->lowest_randbit;
292 uint32 mask = (this->num_groups - 1) << this->lowest_randbit;
301 return object.ResolveReal(
this);
313 if (!this->dts.NeedsPreprocessing()) {
314 if (stage !=
nullptr && this->dts.consistent_max_offset > 0) *stage =
GetConstructionStageOffset(*stage, this->dts.consistent_max_offset);
319 uint8 actual_stage = stage !=
nullptr ? *stage : 0;
320 this->dts.PrepareLayout(0, 0, 0, actual_stage,
false);
321 this->dts.ProcessRegisters(0, 0,
false);
322 result.
seq = this->dts.GetLayout(&result.
ground);
325 if (stage !=
nullptr) *stage = 0;
rotate a b positions to the right
Interface to query and set values specific to a single VarSpriteGroupScope (action 2 scope)...
const SpriteGroup * Resolve(ResolverObject &object) const
Base sprite group resolver.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Profiling of NewGRF action 2 handling.
Functions related to debugging.
virtual const SpriteGroup * ResolveReal(const RealSpriteGroup *group) const
Get the real sprites of the grf.
Class for temporary storage of data.
Interface for SpriteGroup-s to access the gamestate.
(unsigned) comparison (a < b -> 0, a == b = 1, a > b = 2)
Tindex index
Index of this pool item.
virtual ScopeResolver * GetScope(VarSpriteGroupScope scope=VSG_SCOPE_SELF, byte relative=0)
Get a resolver for the scope.
static T max(const T a, const T b)
Returns the maximum of two values.
const DrawTileSeqStruct * seq
Array of child sprites. Terminated with a terminator entry.
Some methods of Pool are placed here in order to reduce compilation time and binary size...
virtual const SpriteGroup * Resolve(ResolverObject &object) const
Base sprite group resolver.
const DrawTileSprites * ProcessRegisters(uint8 *stage) const
Process registers and the construction stage into the sprite layout.
Ground palette sprite of a tile, together with its sprite layout.
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
void StoreValue(uint pos, int32 value)
Stores some value at a given position.
store a into temporary storage, indexed by b. return a
const SpriteGroup * Resolve(ResolverObject &object) const
Base sprite group resolver.
static T min(const T a, const T b)
Returns the minimum of two values.
Callback profiler for NewGRF development.
const SpriteGroup * Resolve(ResolverObject &object) const
Base sprite group resolver.
virtual uint32 GetVariable(byte variable, uint32 parameter, bool *available) const
Get a variable value.
Base class for all pools.
#define DEBUG(name, level,...)
Output a line of debugging information.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
PalSpriteID ground
Palette and sprite for the ground.
bool GetGlobalVariable(byte param, uint32 *value, const GRFFile *grffile)
Reads a variable common to VarAction2 and Action7/9/D.
virtual void StorePSA(uint reg, int32 value)
Store a value into the persistent storage area (PSA).
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
(signed) comparison (a < b -> 0, a == b = 1, a > b = 2)
store a into persistent storage, indexed by b, return a
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
virtual uint32 GetRandomBits() const
Get a few random bits.
Set when calling a randomizing trigger (almost undocumented).
static uint GetConstructionStageOffset(uint construction_stage, uint num_sprites)
Determines which sprite to use from a spriteset for a specific construction stage.
TYPE GetValue(uint pos) const
Gets the value from a given position.
byte parameter
Used for variables between 0x60 and 0x7F inclusive.
Dynamic data of a loaded NewGRF.
virtual uint32 GetTriggers() const
Get the triggers.