Changeset - r25356:d308476ebd68
[Not reviewed]
master
0 1 0
Peter Nelson - 3 years ago 2021-05-01 23:04:34
peter1138@openttd.org
Cleanup: Use range iterator to evaluate DeterministicSpriteGroup.
1 file changed with 13 insertions and 16 deletions:
0 comments (0 inline, 0 general)
src/newgrf_spritegroup.cpp
Show inline comments
 
@@ -141,18 +141,18 @@ static inline uint32 GetVariable(const R
 
/* Evaluate an adjustment for a variable of the given size.
 
 * U is the unsigned type and S is the signed type to use. */
 
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->and_mask;
 
	value >>= adjust.shift_num;
 
	value  &= adjust.and_mask;
 

	
 
	switch (adjust->type) {
 
		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;
 
	switch (adjust.type) {
 
		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_NONE: break;
 
	}
 

	
 
	switch (adjust->operation) {
 
	switch (adjust.operation) {
 
		case DSGA_OP_ADD:  return last_value + value;
 
		case DSGA_OP_SUB:  return last_value - value;
 
		case DSGA_OP_SMIN: return std::min<S>(last_value, value);
 
@@ -190,17 +190,14 @@ const SpriteGroup *DeterministicSpriteGr
 
{
 
	uint32 last_value = 0;
 
	uint32 value = 0;
 
	uint i;
 

	
 
	ScopeResolver *scope = object.GetScope(this->var_scope);
 

	
 
	for (i = 0; i < this->adjusts.size(); i++) {
 
		const DeterministicSpriteGroupAdjust *adjust = &this->adjusts[i];
 

	
 
	for (const auto &adjust : this->adjusts) {
 
		/* Try to get the variable. We shall assume it is available, unless told otherwise. */
 
		bool available = true;
 
		if (adjust->variable == 0x7E) {
 
			const SpriteGroup *subgroup = SpriteGroup::Resolve(adjust->subroutine, object, false);
 
		if (adjust.variable == 0x7E) {
 
			const SpriteGroup *subgroup = SpriteGroup::Resolve(adjust.subroutine, object, false);
 
			if (subgroup == nullptr) {
 
				value = CALLBACK_FAILED;
 
			} else {
 
@@ -208,10 +205,10 @@ const SpriteGroup *DeterministicSpriteGr
 
			}
 

	
 
			/* Note: 'last_value' and 'reseed' are shared between the main chain and the procedure */
 
		} else if (adjust->variable == 0x7B) {
 
			value = GetVariable(object, scope, adjust->parameter, last_value, &available);
 
		} else if (adjust.variable == 0x7B) {
 
			value = GetVariable(object, scope, adjust.parameter, last_value, &available);
 
		} else {
 
			value = GetVariable(object, scope, adjust->variable, adjust->parameter, &available);
 
			value = GetVariable(object, scope, adjust.variable, adjust.parameter, &available);
 
		}
 

	
 
		if (!available) {
0 comments (0 inline, 0 general)