Changeset - r25355:29ba87e2b3c3
[Not reviewed]
master
0 3 0
Peter Nelson - 3 years ago 2021-05-01 23:00:40
peter1138@openttd.org
Cleanup: Use std::vector in RandomSpriteGroup.
3 files changed with 7 insertions and 15 deletions:
0 comments (0 inline, 0 general)
src/newgrf.cpp
Show inline comments
 
@@ -5128,11 +5128,10 @@ static void NewSpriteGroup(ByteReader *b
 
			group->triggers       = GB(triggers, 0, 7);
 
			group->cmp_mode       = HasBit(triggers, 7) ? RSG_CMP_ALL : RSG_CMP_ANY;
 
			group->lowest_randbit = buf->ReadByte();
 
			group->num_groups     = buf->ReadByte();
 
			group->groups = CallocT<const SpriteGroup*>(group->num_groups);
 

	
 
			for (uint i = 0; i < group->num_groups; i++) {
 
				group->groups[i] = GetGroupFromGroupID(setid, type, buf->ReadWord());
 

	
 
			byte num_groups = buf->ReadByte();
 
			for (uint i = 0; i < num_groups; i++) {
 
				group->groups.push_back(GetGroupFromGroupID(setid, type, buf->ReadWord()));
 
			}
 

	
 
			break;
src/newgrf_spritegroup.cpp
Show inline comments
 
@@ -53,11 +53,6 @@ TemporaryStorageArray<int32, 0x110> _tem
 
	}
 
}
 

	
 
RandomizedSpriteGroup::~RandomizedSpriteGroup()
 
{
 
	free(this->groups);
 
}
 

	
 
static inline uint32 GetVariable(const ResolverObject &object, ScopeResolver *scope, byte variable, uint32 parameter, bool *available)
 
{
 
	uint32 value;
 
@@ -272,11 +267,11 @@ const SpriteGroup *RandomizedSpriteGroup
 

	
 
		if (res) {
 
			object.used_triggers |= match;
 
			object.reseed[this->var_scope] |= (this->num_groups - 1) << this->lowest_randbit;
 
			object.reseed[this->var_scope] |= (this->groups.size() - 1) << this->lowest_randbit;
 
		}
 
	}
 

	
 
	uint32 mask  = (this->num_groups - 1) << this->lowest_randbit;
 
	uint32 mask = ((uint)this->groups.size() - 1) << this->lowest_randbit;
 
	byte index = (scope->GetRandomBits() & mask) >> this->lowest_randbit;
 

	
 
	return SpriteGroup::Resolve(this->groups[index], object, false);
src/newgrf_spritegroup.h
Show inline comments
 
@@ -189,7 +189,6 @@ enum RandomizedSpriteGroupCompareMode {
 

	
 
struct RandomizedSpriteGroup : SpriteGroup {
 
	RandomizedSpriteGroup() : SpriteGroup(SGT_RANDOMIZED) {}
 
	~RandomizedSpriteGroup();
 

	
 
	VarSpriteGroupScope var_scope;  ///< Take this object:
 

	
 
@@ -198,9 +197,8 @@ struct RandomizedSpriteGroup : SpriteGro
 
	byte count;
 

	
 
	byte lowest_randbit; ///< Look for this in the per-object randomized bitmask:
 
	byte num_groups; ///< must be power of 2
 

	
 
	const SpriteGroup **groups; ///< Take the group with appropriate index:
 
	std::vector<const SpriteGroup *> groups; ///< Take the group with appropriate index:
 

	
 
protected:
 
	const SpriteGroup *Resolve(ResolverObject &object) const;
0 comments (0 inline, 0 general)