mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-10-31 15:20:10 +00:00
Cleanup: Use std::vector in RealSpriteGroup.
This commit is contained in:
parent
e097c83c83
commit
f785a70a2b
@ -5181,23 +5181,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;
|
||||
}
|
||||
|
@ -992,14 +992,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;
|
||||
}
|
||||
|
||||
|
@ -53,12 +53,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…
Reference in New Issue
Block a user