Cleanup: Use std::vector in RandomSpriteGroup.

pull/332/head
Peter Nelson 3 years ago committed by PeterN
parent 1aeaf39954
commit 913d8a7f28

@ -5128,11 +5128,10 @@ static void NewSpriteGroup(ByteReader *buf)
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;

@ -53,11 +53,6 @@ TemporaryStorageArray<int32, 0x110> _temp_store;
}
}
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::Resolve(ResolverObject &object) const
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);

@ -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 : SpriteGroup {
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;

Loading…
Cancel
Save