Cleanup: Use range iterator to evaluate DeterministicSpriteGroup.

(cherry picked from commit 6b0b1bb3de)
This commit is contained in:
Peter Nelson
2021-05-02 00:04:34 +01:00
committed by Jonathan G Rennison
parent f5722a999e
commit 02a62e4c98

View File

@@ -144,18 +144,18 @@ static inline uint32 GetVariable(const ResolverObject &object, ScopeResolver *sc
/* Evaluate an adjustment for a variable of the given size. /* Evaluate an adjustment for a variable of the given size.
* U is the unsigned type and S is the signed type to use. */ * U is the unsigned type and S is the signed type to use. */
template <typename U, typename S> template <typename U, typename S>
static U EvalAdjustT(const DeterministicSpriteGroupAdjust *adjust, ScopeResolver *scope, U last_value, uint32 value) static U EvalAdjustT(const DeterministicSpriteGroupAdjust &adjust, ScopeResolver *scope, U last_value, uint32 value)
{ {
value >>= adjust->shift_num; value >>= adjust.shift_num;
value &= adjust->and_mask; value &= adjust.and_mask;
switch (adjust->type) { switch (adjust.type) {
case DSGA_TYPE_DIV: value = ((S)value + (S)adjust->add_val) / (S)adjust->divmod_val; break; case DSGA_TYPE_DIV: value = ((S)value + (S)adjust.add_val) / (S)adjust.divmod_val; break;
case DSGA_TYPE_MOD: value = ((S)value + (S)adjust->add_val) % (S)adjust->divmod_val; break; case DSGA_TYPE_MOD: value = ((S)value + (S)adjust.add_val) % (S)adjust.divmod_val; break;
case DSGA_TYPE_NONE: break; case DSGA_TYPE_NONE: break;
} }
switch (adjust->operation) { switch (adjust.operation) {
case DSGA_OP_ADD: return last_value + value; case DSGA_OP_ADD: return last_value + value;
case DSGA_OP_SUB: return last_value - value; case DSGA_OP_SUB: return last_value - value;
case DSGA_OP_SMIN: return std::min<S>(last_value, value); case DSGA_OP_SMIN: return std::min<S>(last_value, value);
@@ -192,17 +192,14 @@ const SpriteGroup *DeterministicSpriteGroup::Resolve(ResolverObject &object) con
{ {
uint32 last_value = 0; uint32 last_value = 0;
uint32 value = 0; uint32 value = 0;
uint i;
ScopeResolver *scope = object.GetScope(this->var_scope); ScopeResolver *scope = object.GetScope(this->var_scope);
for (i = 0; i < this->adjusts.size(); i++) { for (const auto &adjust : this->adjusts) {
const DeterministicSpriteGroupAdjust *adjust = &this->adjusts[i];
/* Try to get the variable. We shall assume it is available, unless told otherwise. */ /* Try to get the variable. We shall assume it is available, unless told otherwise. */
GetVariableExtra extra(adjust->and_mask << adjust->shift_num); GetVariableExtra extra(adjust.and_mask << adjust.shift_num);
if (adjust->variable == 0x7E) { if (adjust.variable == 0x7E) {
const SpriteGroup *subgroup = SpriteGroup::Resolve(adjust->subroutine, object, false); const SpriteGroup *subgroup = SpriteGroup::Resolve(adjust.subroutine, object, false);
if (subgroup == nullptr) { if (subgroup == nullptr) {
value = CALLBACK_FAILED; value = CALLBACK_FAILED;
} else { } else {
@@ -210,11 +207,11 @@ const SpriteGroup *DeterministicSpriteGroup::Resolve(ResolverObject &object) con
} }
/* Note: 'last_value' and 'reseed' are shared between the main chain and the procedure */ /* Note: 'last_value' and 'reseed' are shared between the main chain and the procedure */
} else if (adjust->variable == 0x7B) { } else if (adjust.variable == 0x7B) {
_sprite_group_resolve_check_veh_check = false; _sprite_group_resolve_check_veh_check = false;
value = GetVariable(object, scope, adjust->parameter, last_value, &extra); value = GetVariable(object, scope, adjust.parameter, last_value, &extra);
} else { } else {
value = GetVariable(object, scope, adjust->variable, adjust->parameter, &extra); value = GetVariable(object, scope, adjust.variable, adjust.parameter, &extra);
} }
if (!extra.available) { if (!extra.available) {