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 static inline uint32_t GetVariable(
const ResolverObject &
object,
ScopeResolver *scope,
byte variable, uint32_t parameter,
bool *available)
60 case 0x0C:
return object.callback;
61 case 0x10:
return object.callback_param1;
62 case 0x18:
return object.callback_param2;
63 case 0x1C:
return object.last_value;
67 case 0x7D:
return _temp_store.GetValue(parameter);
70 if (
object.grffile ==
nullptr)
return 0;
71 return object.grffile->GetParam(parameter);
75 if (variable < 0x40 &&
GetGlobalVariable(variable, &value,
object.grffile))
return value;
77 return scope->
GetVariable(variable, parameter, available);
108 Debug(grf, 1,
"Unhandled scope variable 0x{:X}", variable);
142 template <
typename U,
typename S>
145 value >>= adjust.shift_num;
146 value &= adjust.and_mask;
148 switch (adjust.type) {
149 case DSGA_TYPE_DIV: value = ((S)value + (S)adjust.add_val) / (S)adjust.divmod_val;
break;
150 case DSGA_TYPE_MOD: value = ((S)value + (S)adjust.add_val) % (S)adjust.divmod_val;
break;
151 case DSGA_TYPE_NONE:
break;
154 switch (adjust.operation) {
157 case DSGA_OP_SMIN:
return std::min<S>(last_value, value);
158 case DSGA_OP_SMAX:
return std::max<S>(last_value, value);
159 case DSGA_OP_UMIN:
return std::min<U>(last_value, value);
160 case DSGA_OP_UMAX:
return std::max<U>(last_value, value);
161 case DSGA_OP_SDIV:
return value == 0 ? (S)last_value : (S)last_value / (S)value;
162 case DSGA_OP_SMOD:
return value == 0 ? (S)last_value : (S)last_value % (S)value;
163 case DSGA_OP_UDIV:
return value == 0 ? (U)last_value : (U)last_value / (U)value;
164 case DSGA_OP_UMOD:
return value == 0 ? (U)last_value : (U)last_value % (U)value;
169 case DSGA_OP_STO: _temp_store.StoreValue((U)value, (S)last_value);
return last_value;
172 case DSGA_OP_ROR:
return std::rotr<uint32_t>((U)last_value, (U)value & 0x1F);
173 case DSGA_OP_SCMP:
return ((S)last_value == (S)value) ? 1 : ((S)last_value < (S)value ? 0 : 2);
174 case DSGA_OP_UCMP:
return ((U)last_value == (U)value) ? 1 : ((U)last_value < (U)value ? 0 : 2);
175 case DSGA_OP_SHL:
return (uint32_t)(U)last_value << ((U)value & 0x1F);
176 case DSGA_OP_SHR:
return (uint32_t)(U)last_value >> ((U)value & 0x1F);
177 case DSGA_OP_SAR:
return (int32_t)(S)last_value >> ((U)value & 0x1F);
178 default:
return value;
185 return range.high < value;
190 uint32_t last_value = 0;
195 for (
const auto &adjust : this->adjusts) {
197 bool available =
true;
198 if (adjust.variable == 0x7E) {
200 if (subgroup ==
nullptr) {
203 value = subgroup->GetCallbackResult();
207 }
else if (adjust.variable == 0x7B) {
208 value = GetVariable(
object, scope, adjust.
parameter, last_value, &available);
210 value = GetVariable(
object, scope, adjust.variable, adjust.
parameter, &available);
219 switch (this->size) {
220 case DSG_SIZE_BYTE: value = EvalAdjustT<uint8_t, int8_t> (adjust, scope, last_value, value);
break;
221 case DSG_SIZE_WORD: value = EvalAdjustT<uint16_t, int16_t>(adjust, scope, last_value, value);
break;
222 case DSG_SIZE_DWORD: value = EvalAdjustT<uint32_t, int32_t>(adjust, scope, last_value, value);
break;
223 default: NOT_REACHED();
228 object.last_value = last_value;
230 if (this->calculated_result) {
234 nvarzero.result = value;
238 if (this->ranges.size() > 4) {
239 const auto &lower = std::lower_bound(this->ranges.begin(), this->ranges.end(), value, RangeHighComparator);
240 if (lower != this->ranges.end() && lower->low <= value) {
241 assert(lower->low <= value && value <= lower->high);
245 for (
const auto &range : this->ranges) {
246 if (range.low <= value && value <= range.high) {
261 byte match = this->triggers &
object.waiting_triggers;
262 bool res = (this->
cmp_mode == RSG_CMP_ANY) ? (match != 0) : (match == this->triggers);
265 object.used_triggers |= match;
279 return object.ResolveReal(
this);
297 uint8_t actual_stage = stage !=
nullptr ? *stage : 0;
300 result.seq = this->dts.
GetLayout(&result.ground);
303 if (stage !=
nullptr) *stage = 0;