mirror of https://github.com/OpenTTD/OpenTTD
Cleanup: Use std::vector in RandomSpriteGroup.
parent
1aeaf39954
commit
913d8a7f28
|
@ -5128,11 +5128,10 @@ static void NewSpriteGroup(ByteReader *buf)
|
||||||
group->triggers = GB(triggers, 0, 7);
|
group->triggers = GB(triggers, 0, 7);
|
||||||
group->cmp_mode = HasBit(triggers, 7) ? RSG_CMP_ALL : RSG_CMP_ANY;
|
group->cmp_mode = HasBit(triggers, 7) ? RSG_CMP_ALL : RSG_CMP_ANY;
|
||||||
group->lowest_randbit = buf->ReadByte();
|
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++) {
|
byte num_groups = buf->ReadByte();
|
||||||
group->groups[i] = GetGroupFromGroupID(setid, type, buf->ReadWord());
|
for (uint i = 0; i < num_groups; i++) {
|
||||||
|
group->groups.push_back(GetGroupFromGroupID(setid, type, buf->ReadWord()));
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
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)
|
static inline uint32 GetVariable(const ResolverObject &object, ScopeResolver *scope, byte variable, uint32 parameter, bool *available)
|
||||||
{
|
{
|
||||||
uint32 value;
|
uint32 value;
|
||||||
|
@ -272,11 +267,11 @@ const SpriteGroup *RandomizedSpriteGroup::Resolve(ResolverObject &object) const
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
object.used_triggers |= match;
|
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;
|
byte index = (scope->GetRandomBits() & mask) >> this->lowest_randbit;
|
||||||
|
|
||||||
return SpriteGroup::Resolve(this->groups[index], object, false);
|
return SpriteGroup::Resolve(this->groups[index], object, false);
|
||||||
|
|
|
@ -189,7 +189,6 @@ enum RandomizedSpriteGroupCompareMode {
|
||||||
|
|
||||||
struct RandomizedSpriteGroup : SpriteGroup {
|
struct RandomizedSpriteGroup : SpriteGroup {
|
||||||
RandomizedSpriteGroup() : SpriteGroup(SGT_RANDOMIZED) {}
|
RandomizedSpriteGroup() : SpriteGroup(SGT_RANDOMIZED) {}
|
||||||
~RandomizedSpriteGroup();
|
|
||||||
|
|
||||||
VarSpriteGroupScope var_scope; ///< Take this object:
|
VarSpriteGroupScope var_scope; ///< Take this object:
|
||||||
|
|
||||||
|
@ -198,9 +197,8 @@ struct RandomizedSpriteGroup : SpriteGroup {
|
||||||
byte count;
|
byte count;
|
||||||
|
|
||||||
byte lowest_randbit; ///< Look for this in the per-object randomized bitmask:
|
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:
|
protected:
|
||||||
const SpriteGroup *Resolve(ResolverObject &object) const;
|
const SpriteGroup *Resolve(ResolverObject &object) const;
|
||||||
|
|
Loading…
Reference in New Issue