Cleanup: Use std::vector in RealSpriteGroup.

(cherry picked from commit f785a70a2b)
pull/259/head
Peter Nelson 3 years ago committed by Jonathan G Rennison
parent d4c466200f
commit d3b9d19c5a

@ -5326,23 +5326,18 @@ static void NewSpriteGroup(ByteReader *buf)
group->nfo_line = _cur.nfo_line;
act_group = group;
group->num_loaded = num_loaded;
group->num_loading = num_loading;
if (num_loaded > 0) group->loaded = CallocT<const SpriteGroup*>(num_loaded);
if (num_loading > 0) group->loading = CallocT<const SpriteGroup*>(num_loading);
grfmsg(6, "NewSpriteGroup: New SpriteGroup 0x%02X, %u loaded, %u loading",
setid, num_loaded, num_loading);
for (uint i = 0; i < num_loaded; i++) {
uint16 spriteid = buf->ReadWord();
group->loaded[i] = CreateGroupFromGroupID(feature, setid, type, spriteid);
group->loaded.push_back(CreateGroupFromGroupID(feature, setid, type, spriteid));
grfmsg(8, "NewSpriteGroup: + rg->loaded[%i] = subset %u", i, spriteid);
}
for (uint i = 0; i < num_loading; i++) {
uint16 spriteid = buf->ReadWord();
group->loading[i] = CreateGroupFromGroupID(feature, setid, type, spriteid);
group->loading.push_back(CreateGroupFromGroupID(feature, setid, type, spriteid));
grfmsg(8, "NewSpriteGroup: + rg->loading[%i] = subset %u", i, spriteid);
}

@ -223,8 +223,8 @@ void AirportOverrideManager::SetEntitySpec(AirportSpec *as)
{
/* Airport action 2s should always have only 1 "loaded" state, but some
* times things don't follow the spec... */
if (group->num_loaded > 0) return group->loaded[0];
if (group->num_loading > 0) return group->loading[0];
if (!group->loaded.empty()) return group->loaded[0];
if (!group->loading.empty()) return group->loading[0];
return nullptr;
}

@ -111,7 +111,7 @@ struct CanalResolverObject : public ResolverObject {
/* virtual */ const SpriteGroup *CanalResolverObject::ResolveReal(const RealSpriteGroup *group) const
{
if (group->num_loaded == 0) return nullptr;
if (group->loaded.empty()) return nullptr;
return group->loaded[0];
}

@ -29,8 +29,8 @@ struct CargoResolverObject : public ResolverObject {
{
/* Cargo action 2s should always have only 1 "loaded" state, but some
* times things don't follow the spec... */
if (group->num_loaded > 0) return group->loaded[0];
if (group->num_loading > 0) return group->loading[0];
if (!group->loaded.empty()) return group->loaded[0];
if (!group->loading.empty()) return group->loading[0];
return nullptr;
}

@ -1162,14 +1162,14 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
const Vehicle *v = this->self_scope.v;
if (v == nullptr) {
if (group->num_loading > 0) return group->loading[0];
if (group->num_loaded > 0) return group->loaded[0];
if (!group->loading.empty()) return group->loading[0];
if (!group->loaded.empty()) return group->loaded[0];
return nullptr;
}
bool in_motion = !v->First()->current_order.IsType(OT_LOADING);
uint totalsets = in_motion ? group->num_loaded : group->num_loading;
uint totalsets = in_motion ? (uint)group->loaded.size() : (uint)group->loading.size();
if (totalsets == 0) return nullptr;

@ -150,7 +150,7 @@ void AddGenericCallback(uint8 feature, const GRFFile *file, const SpriteGroup *g
/* virtual */ const SpriteGroup *GenericResolverObject::ResolveReal(const RealSpriteGroup *group) const
{
if (group->num_loaded == 0) return nullptr;
if (group->loaded.empty()) return nullptr;
return group->loaded[0];
}

@ -60,8 +60,8 @@
/* virtual */ const SpriteGroup *RailTypeResolverObject::ResolveReal(const RealSpriteGroup *group) const
{
if (group->num_loading > 0) return group->loading[0];
if (group->num_loaded > 0) return group->loaded[0];
if (!group->loading.empty()) return group->loading[0];
if (!group->loaded.empty()) return group->loaded[0];
return nullptr;
}

@ -60,8 +60,8 @@
/* virtual */ const SpriteGroup *RoadTypeResolverObject::ResolveReal(const RealSpriteGroup *group) const
{
if (group->num_loading > 0) return group->loading[0];
if (group->num_loaded > 0) return group->loaded[0];
if (!group->loading.empty()) return group->loading[0];
if (!group->loaded.empty()) return group->loaded[0];
return nullptr;
}

@ -56,12 +56,6 @@ TemporaryStorageArray<int32, 0x110> _temp_store;
}
}
RealSpriteGroup::~RealSpriteGroup()
{
free(this->loaded);
free(this->loading);
}
DeterministicSpriteGroup::~DeterministicSpriteGroup()
{
free(this->adjusts);

@ -78,7 +78,6 @@ public:
* groups. */
struct RealSpriteGroup : SpriteGroup {
RealSpriteGroup() : SpriteGroup(SGT_REAL) {}
~RealSpriteGroup();
/* Loaded = in motion, loading = not moving
* Each group contains several spritesets, for various loading stages */
@ -87,10 +86,8 @@ struct RealSpriteGroup : SpriteGroup {
* with small amount of cargo whilst loading is for stations with a lot
* of da stuff. */
byte num_loaded; ///< Number of loaded groups
byte num_loading; ///< Number of loading groups
const SpriteGroup **loaded; ///< List of loaded groups (can be SpriteIDs or Callback results)
const SpriteGroup **loading; ///< List of loading groups (can be SpriteIDs or Callback results)
std::vector<const SpriteGroup *> loaded; ///< List of loaded groups (can be SpriteIDs or Callback results)
std::vector<const SpriteGroup *> loading; ///< List of loading groups (can be SpriteIDs or Callback results)
protected:
const SpriteGroup *Resolve(ResolverObject &object) const;

@ -523,13 +523,13 @@ uint32 Waypoint::GetNewGRFVariable(const ResolverObject &object, byte variable,
cargo = std::min(0xfffu, cargo);
if (cargo > this->station_scope.statspec->cargo_threshold) {
if (group->num_loading > 0) {
uint set = ((cargo - this->station_scope.statspec->cargo_threshold) * group->num_loading) / (4096 - this->station_scope.statspec->cargo_threshold);
if (!group->loading.empty()) {
uint set = ((cargo - this->station_scope.statspec->cargo_threshold) * (uint)group->loading.size()) / (4096 - this->station_scope.statspec->cargo_threshold);
return group->loading[set];
}
} else {
if (group->num_loaded > 0) {
uint set = (cargo * group->num_loaded) / (this->station_scope.statspec->cargo_threshold + 1);
if (!group->loaded.empty()) {
uint set = (cargo * (uint)group->loaded.size()) / (this->station_scope.statspec->cargo_threshold + 1);
return group->loaded[set];
}
}

Loading…
Cancel
Save