mirror of https://github.com/OpenTTD/OpenTTD
Cleanup: Use std::vector in RealSpriteGroup.
parent
e097c83c83
commit
f785a70a2b
|
@ -5181,23 +5181,18 @@ static void NewSpriteGroup(ByteReader *buf)
|
||||||
group->nfo_line = _cur.nfo_line;
|
group->nfo_line = _cur.nfo_line;
|
||||||
act_group = group;
|
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",
|
grfmsg(6, "NewSpriteGroup: New SpriteGroup 0x%02X, %u loaded, %u loading",
|
||||||
setid, num_loaded, num_loading);
|
setid, num_loaded, num_loading);
|
||||||
|
|
||||||
for (uint i = 0; i < num_loaded; i++) {
|
for (uint i = 0; i < num_loaded; i++) {
|
||||||
uint16 spriteid = buf->ReadWord();
|
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);
|
grfmsg(8, "NewSpriteGroup: + rg->loaded[%i] = subset %u", i, spriteid);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint i = 0; i < num_loading; i++) {
|
for (uint i = 0; i < num_loading; i++) {
|
||||||
uint16 spriteid = buf->ReadWord();
|
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);
|
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
|
/* Airport action 2s should always have only 1 "loaded" state, but some
|
||||||
* times things don't follow the spec... */
|
* times things don't follow the spec... */
|
||||||
if (group->num_loaded > 0) return group->loaded[0];
|
if (!group->loaded.empty()) return group->loaded[0];
|
||||||
if (group->num_loading > 0) return group->loading[0];
|
if (!group->loading.empty()) return group->loading[0];
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,7 +111,7 @@ struct CanalResolverObject : public ResolverObject {
|
||||||
|
|
||||||
/* virtual */ const SpriteGroup *CanalResolverObject::ResolveReal(const RealSpriteGroup *group) const
|
/* 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];
|
return group->loaded[0];
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,8 @@ struct CargoResolverObject : public ResolverObject {
|
||||||
{
|
{
|
||||||
/* Cargo action 2s should always have only 1 "loaded" state, but some
|
/* Cargo action 2s should always have only 1 "loaded" state, but some
|
||||||
* times things don't follow the spec... */
|
* times things don't follow the spec... */
|
||||||
if (group->num_loaded > 0) return group->loaded[0];
|
if (!group->loaded.empty()) return group->loaded[0];
|
||||||
if (group->num_loading > 0) return group->loading[0];
|
if (!group->loading.empty()) return group->loading[0];
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -992,14 +992,14 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object,
|
||||||
const Vehicle *v = this->self_scope.v;
|
const Vehicle *v = this->self_scope.v;
|
||||||
|
|
||||||
if (v == nullptr) {
|
if (v == nullptr) {
|
||||||
if (group->num_loading > 0) return group->loading[0];
|
if (!group->loading.empty()) return group->loading[0];
|
||||||
if (group->num_loaded > 0) return group->loaded[0];
|
if (!group->loaded.empty()) return group->loaded[0];
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool in_motion = !v->First()->current_order.IsType(OT_LOADING);
|
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;
|
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
|
/* 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];
|
return group->loaded[0];
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,8 +60,8 @@
|
||||||
|
|
||||||
/* virtual */ const SpriteGroup *RailTypeResolverObject::ResolveReal(const RealSpriteGroup *group) const
|
/* virtual */ const SpriteGroup *RailTypeResolverObject::ResolveReal(const RealSpriteGroup *group) const
|
||||||
{
|
{
|
||||||
if (group->num_loading > 0) return group->loading[0];
|
if (!group->loading.empty()) return group->loading[0];
|
||||||
if (group->num_loaded > 0) return group->loaded[0];
|
if (!group->loaded.empty()) return group->loaded[0];
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,8 +60,8 @@
|
||||||
|
|
||||||
/* virtual */ const SpriteGroup *RoadTypeResolverObject::ResolveReal(const RealSpriteGroup *group) const
|
/* virtual */ const SpriteGroup *RoadTypeResolverObject::ResolveReal(const RealSpriteGroup *group) const
|
||||||
{
|
{
|
||||||
if (group->num_loading > 0) return group->loading[0];
|
if (!group->loading.empty()) return group->loading[0];
|
||||||
if (group->num_loaded > 0) return group->loaded[0];
|
if (!group->loaded.empty()) return group->loaded[0];
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,12 +53,6 @@ TemporaryStorageArray<int32, 0x110> _temp_store;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RealSpriteGroup::~RealSpriteGroup()
|
|
||||||
{
|
|
||||||
free(this->loaded);
|
|
||||||
free(this->loading);
|
|
||||||
}
|
|
||||||
|
|
||||||
DeterministicSpriteGroup::~DeterministicSpriteGroup()
|
DeterministicSpriteGroup::~DeterministicSpriteGroup()
|
||||||
{
|
{
|
||||||
free(this->adjusts);
|
free(this->adjusts);
|
||||||
|
|
|
@ -78,7 +78,6 @@ public:
|
||||||
* groups. */
|
* groups. */
|
||||||
struct RealSpriteGroup : SpriteGroup {
|
struct RealSpriteGroup : SpriteGroup {
|
||||||
RealSpriteGroup() : SpriteGroup(SGT_REAL) {}
|
RealSpriteGroup() : SpriteGroup(SGT_REAL) {}
|
||||||
~RealSpriteGroup();
|
|
||||||
|
|
||||||
/* Loaded = in motion, loading = not moving
|
/* Loaded = in motion, loading = not moving
|
||||||
* Each group contains several spritesets, for various loading stages */
|
* 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
|
* with small amount of cargo whilst loading is for stations with a lot
|
||||||
* of da stuff. */
|
* of da stuff. */
|
||||||
|
|
||||||
byte num_loaded; ///< Number of loaded groups
|
std::vector<const SpriteGroup *> loaded; ///< List of loaded groups (can be SpriteIDs or Callback results)
|
||||||
byte num_loading; ///< Number of loading groups
|
std::vector<const SpriteGroup *> loading; ///< List of loading groups (can be SpriteIDs or Callback results)
|
||||||
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)
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const SpriteGroup *Resolve(ResolverObject &object) const;
|
const SpriteGroup *Resolve(ResolverObject &object) const;
|
||||||
|
|
|
@ -523,13 +523,13 @@ uint32 Waypoint::GetNewGRFVariable(const ResolverObject &object, byte variable,
|
||||||
cargo = std::min(0xfffu, cargo);
|
cargo = std::min(0xfffu, cargo);
|
||||||
|
|
||||||
if (cargo > this->station_scope.statspec->cargo_threshold) {
|
if (cargo > this->station_scope.statspec->cargo_threshold) {
|
||||||
if (group->num_loading > 0) {
|
if (!group->loading.empty()) {
|
||||||
uint set = ((cargo - this->station_scope.statspec->cargo_threshold) * group->num_loading) / (4096 - this->station_scope.statspec->cargo_threshold);
|
uint set = ((cargo - this->station_scope.statspec->cargo_threshold) * (uint)group->loading.size()) / (4096 - this->station_scope.statspec->cargo_threshold);
|
||||||
return group->loading[set];
|
return group->loading[set];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (group->num_loaded > 0) {
|
if (!group->loaded.empty()) {
|
||||||
uint set = (cargo * group->num_loaded) / (this->station_scope.statspec->cargo_threshold + 1);
|
uint set = (cargo * (uint)group->loaded.size()) / (this->station_scope.statspec->cargo_threshold + 1);
|
||||||
return group->loaded[set];
|
return group->loaded[set];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue