36 if (group ==
nullptr)
return nullptr;
38 const GRFFile *grf =
object.grffile;
39 auto profiler = std::find_if(_newgrf_profilers.begin(), _newgrf_profilers.end(), [&](
const NewGRFProfiler &pr) { return pr.grffile == grf; });
41 if (profiler == _newgrf_profilers.end() || !profiler->active) {
42 if (top_level) _temp_store.ClearChanges();
44 }
else if (top_level) {
45 profiler->BeginResolve(
object);
46 _temp_store.ClearChanges();
48 profiler->EndResolve(result);
51 profiler->RecursiveResolve();
56 RealSpriteGroup::~RealSpriteGroup()
62 DeterministicSpriteGroup::~DeterministicSpriteGroup()
68 RandomizedSpriteGroup::~RandomizedSpriteGroup()
73 static inline uint32 GetVariable(
const ResolverObject &
object,
ScopeResolver *scope,
byte variable, uint32 parameter,
bool *available)
77 case 0x0C:
return object.callback;
78 case 0x10:
return object.callback_param1;
79 case 0x18:
return object.callback_param2;
80 case 0x1C:
return object.last_value;
84 case 0x7D:
return _temp_store.GetValue(parameter);
87 if (
object.grffile ==
nullptr)
return 0;
88 return object.grffile->GetParam(parameter);
92 if (variable < 0x40 &&
GetGlobalVariable(variable, &value,
object.grffile))
return value;
94 return scope->
GetVariable(variable, parameter, available);
125 DEBUG(grf, 1,
"Unhandled scope variable 0x%X", variable);
160 template <
typename U,
typename S>
163 value >>= adjust->shift_num;
164 value &= adjust->and_mask;
166 switch (adjust->type) {
167 case DSGA_TYPE_DIV: value = ((S)value + (S)adjust->add_val) / (S)adjust->divmod_val;
break;
168 case DSGA_TYPE_MOD: value = ((S)value + (S)adjust->add_val) % (S)adjust->divmod_val;
break;
169 case DSGA_TYPE_NONE:
break;
172 switch (adjust->operation) {
175 case DSGA_OP_SMIN:
return std::min<S>(last_value, value);
176 case DSGA_OP_SMAX:
return std::max<S>(last_value, value);
177 case DSGA_OP_UMIN:
return std::min<U>(last_value, value);
178 case DSGA_OP_UMAX:
return std::max<U>(last_value, value);
179 case DSGA_OP_SDIV:
return value == 0 ? (S)last_value : (S)last_value / (S)value;
180 case DSGA_OP_SMOD:
return value == 0 ? (S)last_value : (S)last_value % (S)value;
181 case DSGA_OP_UDIV:
return value == 0 ? (U)last_value : (U)last_value / (U)value;
182 case DSGA_OP_UMOD:
return value == 0 ? (U)last_value : (U)last_value % (U)value;
187 case DSGA_OP_STO: _temp_store.StoreValue((U)value, (S)last_value);
return last_value;
190 case DSGA_OP_ROR:
return ROR<uint32>((U)last_value, (U)value & 0x1F);
191 case DSGA_OP_SCMP:
return ((S)last_value == (S)value) ? 1 : ((S)last_value < (S)value ? 0 : 2);
192 case DSGA_OP_UCMP:
return ((U)last_value == (U)value) ? 1 : ((U)last_value < (U)value ? 0 : 2);
193 case DSGA_OP_SHL:
return (uint32)(U)last_value << ((U)value & 0x1F);
194 case DSGA_OP_SHR:
return (uint32)(U)last_value >> ((U)value & 0x1F);
195 case DSGA_OP_SAR:
return (int32)(S)last_value >> ((U)value & 0x1F);
196 default:
return value;
203 return range.high < value;
208 uint32 last_value = 0;
214 for (i = 0; i < this->num_adjusts; i++) {
218 bool available =
true;
219 if (adjust->variable == 0x7E) {
221 if (subgroup ==
nullptr) {
224 value = subgroup->GetCallbackResult();
228 }
else if (adjust->variable == 0x7B) {
229 value = GetVariable(
object, scope, adjust->
parameter, last_value, &available);
231 value = GetVariable(
object, scope, adjust->variable, adjust->
parameter, &available);
240 switch (this->size) {
241 case DSG_SIZE_BYTE: value = EvalAdjustT<uint8, int8> (adjust, scope, last_value, value);
break;
242 case DSG_SIZE_WORD: value = EvalAdjustT<uint16, int16>(adjust, scope, last_value, value);
break;
243 case DSG_SIZE_DWORD: value = EvalAdjustT<uint32, int32>(adjust, scope, last_value, value);
break;
244 default: NOT_REACHED();
249 object.last_value = last_value;
251 if (this->calculated_result) {
255 nvarzero.result = value;
259 if (this->num_ranges > 4) {
261 if (lower != this->ranges + this->num_ranges && lower->low <= value) {
262 assert(lower->low <= value && value <= lower->high);
266 for (i = 0; i < this->num_ranges; i++) {
267 if (this->ranges[i].low <= value && value <= this->ranges[i].high) {
282 byte match = this->triggers &
object.waiting_triggers;
283 bool res = (this->
cmp_mode == RSG_CMP_ANY) ? (match != 0) : (match == this->triggers);
286 object.used_triggers |= match;
300 return object.ResolveReal(
this);
318 uint8 actual_stage = stage !=
nullptr ? *stage : 0;
324 if (stage !=
nullptr) *stage = 0;