Changeset - r25353:18f8979adb60
[Not reviewed]
master
0 11 0
Peter Nelson - 3 years ago 2021-05-01 22:58:18
peter1138@openttd.org
Cleanup: Use std::vector in RealSpriteGroup.
11 files changed with 21 insertions and 35 deletions:
0 comments (0 inline, 0 general)
src/newgrf.cpp
Show inline comments
 
@@ -5181,23 +5181,18 @@ static void NewSpriteGroup(ByteReader *b
 
					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);
 
					}
 

	
src/newgrf_airport.cpp
Show inline comments
 
@@ -223,8 +223,8 @@ void AirportOverrideManager::SetEntitySp
 
{
 
	/* 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;
 
}
src/newgrf_canal.cpp
Show inline comments
 
@@ -111,7 +111,7 @@ struct CanalResolverObject : public Reso
 

	
 
/* 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];
 
}
src/newgrf_cargo.cpp
Show inline comments
 
@@ -29,8 +29,8 @@ struct CargoResolverObject : public Reso
 
{
 
	/* 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;
 
}
src/newgrf_engine.cpp
Show inline comments
 
@@ -992,14 +992,14 @@ static uint32 VehicleGetVariable(Vehicle
 
	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;
 

	
src/newgrf_generic.cpp
Show inline comments
 
@@ -150,7 +150,7 @@ void AddGenericCallback(uint8 feature, c
 

	
 
/* 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];
 
}
src/newgrf_railtype.cpp
Show inline comments
 
@@ -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;
 
}
 

	
src/newgrf_roadtype.cpp
Show inline comments
 
@@ -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;
 
}
 

	
src/newgrf_spritegroup.cpp
Show inline comments
 
@@ -53,12 +53,6 @@ TemporaryStorageArray<int32, 0x110> _tem
 
	}
 
}
 

	
 
RealSpriteGroup::~RealSpriteGroup()
 
{
 
	free(this->loaded);
 
	free(this->loading);
 
}
 

	
 
DeterministicSpriteGroup::~DeterministicSpriteGroup()
 
{
 
	free(this->adjusts);
src/newgrf_spritegroup.h
Show inline comments
 
@@ -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;
src/newgrf_station.cpp
Show inline comments
 
@@ -523,13 +523,13 @@ uint32 Waypoint::GetNewGRFVariable(const
 
	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];
 
		}
 
	}
0 comments (0 inline, 0 general)