37 if (group == NULL)
return NULL;
39 _temp_store.ClearChanges();
44 RealSpriteGroup::~RealSpriteGroup()
50 DeterministicSpriteGroup::~DeterministicSpriteGroup()
56 RandomizedSpriteGroup::~RandomizedSpriteGroup()
61 static inline uint32 GetVariable(
const ResolverObject &
object,
ScopeResolver *scope, byte variable, uint32 parameter,
bool *available)
69 case 0x0C:
return object.callback;
70 case 0x10:
return object.callback_param1;
71 case 0x18:
return object.callback_param2;
72 case 0x1C:
return object.last_value;
76 case 0x7D:
return _temp_store.GetValue(parameter);
79 if (
object.grffile == NULL)
return 0;
80 return object.grffile->GetParam(parameter);
83 default:
return scope->
GetVariable(variable, parameter, available);
92 ScopeResolver::~ScopeResolver() {}
127 DEBUG(grf, 1,
"Unhandled scope variable 0x%X", variable);
147 : default_scope(*this)
158 ResolverObject::~ResolverObject() {}
192 return (val >> rot) | (val << (32 - rot));
198 template <
typename U,
typename S>
201 value >>= adjust->shift_num;
202 value &= adjust->and_mask;
204 if (adjust->type != DSGA_TYPE_NONE) value += (S)adjust->add_val;
206 switch (adjust->type) {
207 case DSGA_TYPE_DIV: value /= (S)adjust->divmod_val;
break;
208 case DSGA_TYPE_MOD: value %= (U)adjust->divmod_val;
break;
209 case DSGA_TYPE_NONE:
break;
212 switch (adjust->operation) {
219 case DSGA_OP_SDIV:
return value == 0 ? (S)last_value : (S)last_value / (S)value;
220 case DSGA_OP_SMOD:
return value == 0 ? (S)last_value : (S)last_value % (S)value;
221 case DSGA_OP_UDIV:
return value == 0 ? (U)last_value : (U)last_value / (U)value;
222 case DSGA_OP_UMOD:
return value == 0 ? (U)last_value : (U)last_value % (U)value;
227 case DSGA_OP_STO: _temp_store.StoreValue((U)value, (S)last_value);
return last_value;
231 case DSGA_OP_SCMP:
return ((S)last_value == (S)value) ? 1 : ((S)last_value < (S)value ? 0 : 2);
232 case DSGA_OP_UCMP:
return ((U)last_value == (U)value) ? 1 : ((U)last_value < (U)value ? 0 : 2);
233 case DSGA_OP_SHL:
return (uint32)(U)last_value << ((U)value & 0x1F);
234 case DSGA_OP_SHR:
return (uint32)(U)last_value >> ((U)value & 0x1F);
235 case DSGA_OP_SAR:
return (int32)(S)last_value >> ((U)value & 0x1F);
236 default:
return value;
243 uint32 last_value = 0;
249 for (i = 0; i < this->num_adjusts; i++) {
253 bool available =
true;
254 if (adjust->variable == 0x7E) {
256 if (subgroup == NULL) {
259 value = subgroup->GetCallbackResult();
263 }
else if (adjust->variable == 0x7B) {
264 value = GetVariable(
object, scope, adjust->
parameter, last_value, &available);
266 value = GetVariable(
object, scope, adjust->variable, adjust->
parameter, &available);
272 return SpriteGroup::Resolve(this->num_ranges > 0 ? this->ranges[0].group : this->default_group,
object,
false);
275 switch (this->size) {
276 case DSG_SIZE_BYTE: value = EvalAdjustT<uint8, int8> (adjust, scope, last_value, value);
break;
277 case DSG_SIZE_WORD: value = EvalAdjustT<uint16, int16>(adjust, scope, last_value, value);
break;
278 case DSG_SIZE_DWORD: value = EvalAdjustT<uint32, int32>(adjust, scope, last_value, value);
break;
279 default: NOT_REACHED();
284 object.last_value = last_value;
286 if (this->num_ranges == 0) {
290 nvarzero.result = value;
294 for (i = 0; i < this->num_ranges; i++) {
295 if (this->ranges[i].low <= value && value <= this->ranges[i].high) {
307 if (
object.trigger != 0) {
311 byte match = this->triggers & (waiting_triggers |
object.trigger);
312 bool res = (this->
cmp_mode == RSG_CMP_ANY) ? (match != 0) : (match == this->triggers);
315 waiting_triggers &= ~match;
318 waiting_triggers |=
object.trigger;
333 return object.ResolveReal(
this);
351 uint8 actual_stage = stage != NULL ? *stage : 0;
357 if (stage != NULL) *stage = 0;