changeset 15761:1f4837ccb325 draft

(svn r20435) -Codechange: move spritegroup to GRFFilePropsBase and prepare it for more spritegroups
author rubidium <rubidium@openttd.org>
date Tue, 10 Aug 2010 15:49:35 +0000
parents e8fa9ad15809
children 640ed6b3475c
files src/newgrf.cpp src/newgrf_airport.cpp src/newgrf_airporttiles.cpp src/newgrf_commons.h src/newgrf_house.cpp src/newgrf_industries.cpp src/newgrf_industrytiles.cpp src/newgrf_station.h
diffstat 8 files changed, 37 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -3925,7 +3925,7 @@
 			continue;
 		}
 
-		hs->grf_prop.spritegroup = _cur_grffile->spritegroups[groupid];
+		hs->grf_prop.spritegroup[0] = _cur_grffile->spritegroups[groupid];
 	}
 }
 
@@ -3956,7 +3956,7 @@
 			continue;
 		}
 
-		indsp->grf_prop.spritegroup = _cur_grffile->spritegroups[groupid];
+		indsp->grf_prop.spritegroup[0] = _cur_grffile->spritegroups[groupid];
 	}
 }
 
@@ -3987,7 +3987,7 @@
 			continue;
 		}
 
-		indtsp->grf_prop.spritegroup = _cur_grffile->spritegroups[groupid];
+		indtsp->grf_prop.spritegroup[0] = _cur_grffile->spritegroups[groupid];
 	}
 }
 
@@ -4075,7 +4075,7 @@
 			continue;
 		}
 
-		as->grf_prop.spritegroup = _cur_grffile->spritegroups[groupid];
+		as->grf_prop.spritegroup[0] = _cur_grffile->spritegroups[groupid];
 	}
 }
 
@@ -4106,7 +4106,7 @@
 			continue;
 		}
 
-		airtsp->grf_prop.spritegroup = _cur_grffile->spritegroups[groupid];
+		airtsp->grf_prop.spritegroup[0] = _cur_grffile->spritegroups[groupid];
 	}
 }
 
--- a/src/newgrf_airport.cpp
+++ b/src/newgrf_airport.cpp
@@ -223,7 +223,7 @@
 
 	NewAirportResolver(&object, INVALID_TILE, NULL, as->GetIndex(), layout);
 
-	group = SpriteGroup::Resolve(as->grf_prop.spritegroup, &object);
+	group = SpriteGroup::Resolve(as->grf_prop.spritegroup[0], &object);
 	if (group == NULL) return as->preview_sprite;
 
 	return group->GetResult();
@@ -238,7 +238,7 @@
 	object.callback_param1 = param1;
 	object.callback_param2 = param2;
 
-	const SpriteGroup *group = SpriteGroup::Resolve(st->airport.GetSpec()->grf_prop.spritegroup, &object);
+	const SpriteGroup *group = SpriteGroup::Resolve(st->airport.GetSpec()->grf_prop.spritegroup[0], &object);
 	if (group == NULL) return CALLBACK_FAILED;
 
 	return group->GetCallbackResult();
@@ -252,7 +252,7 @@
 	NewAirportResolver(&object, INVALID_TILE, NULL, as->GetIndex(), layout);
 	object.callback = (CallbackID)callback;
 
-	group = SpriteGroup::Resolve(as->grf_prop.spritegroup, &object);
+	group = SpriteGroup::Resolve(as->grf_prop.spritegroup[0], &object);
 	if (group == NULL) return STR_UNDEFINED;
 
 	return GetGRFStringID(as->grf_prop.grffile->grfid, 0xD000 + group->GetResult());
--- a/src/newgrf_airporttiles.cpp
+++ b/src/newgrf_airporttiles.cpp
@@ -251,7 +251,7 @@
 	object.callback_param1 = param1;
 	object.callback_param2 = param2;
 
-	group = SpriteGroup::Resolve(AirportTileSpec::Get(gfx_id)->grf_prop.spritegroup, &object);
+	group = SpriteGroup::Resolve(AirportTileSpec::Get(gfx_id)->grf_prop.spritegroup[0], &object);
 	if (group == NULL) return CALLBACK_FAILED;
 
 	return group->GetCallbackResult();
@@ -293,7 +293,7 @@
 
 	AirportTileResolver(&object, gfx, ti->tile, st);
 
-	group = SpriteGroup::Resolve(airts->grf_prop.spritegroup, &object);
+	group = SpriteGroup::Resolve(airts->grf_prop.spritegroup[0], &object);
 	if (group == NULL || group->type != SGT_TILELAYOUT) {
 		return false;
 	}
--- a/src/newgrf_commons.h
+++ b/src/newgrf_commons.h
@@ -135,25 +135,31 @@
 TileIndex GetNearbyTile(byte parameter, TileIndex tile);
 uint32 GetNearbyTileInformation(TileIndex tile);
 
-/** Data related to the handling of grf files. */
+/**
+ * Data related to the handling of grf files.
+ * @tparam Tcnt Number of spritegroups
+ */
+template <size_t Tcnt>
 struct GRFFilePropsBase {
-	/** Set all data constructor for the props. */
-	GRFFilePropsBase(uint local_id, const struct GRFFile *grffile) : local_id(local_id), grffile(grffile) {}
-	/** Simple constructor for the props. */
-	GRFFilePropsBase() {}
-	uint16 local_id;                      ///< id defined by the grf file for this entity
-	const struct GRFFile *grffile;        ///< grf file that introduced this entity
+	/* The lack of constructor means the default zero-ing constructor is used. */
+	uint16 local_id;                             ///< id defined by the grf file for this entity
+	const struct GRFFile *grffile;               ///< grf file that introduced this entity
+	const struct SpriteGroup *spritegroup[Tcnt]; ///< pointer to the different sprites of the entity
 };
 
 /** Data related to the handling of grf files. */
-struct GRFFileProps : GRFFilePropsBase {
+struct GRFFileProps : GRFFilePropsBase<1> {
 	/** Set all default data constructor for the props. */
 	GRFFileProps(uint16 subst_id) :
-			GRFFilePropsBase(0, NULL), subst_id(subst_id), spritegroup(NULL), override(subst_id) {}
+			GRFFilePropsBase<1>(), subst_id(subst_id), override(subst_id)
+	{
+		/* Check whether the constructor did comply with the specs. */
+		assert(this->spritegroup[0] == NULL);
+	}
+
 	/** Simple constructor for the props. */
-	GRFFileProps() : GRFFilePropsBase() {}
+	GRFFileProps() : GRFFilePropsBase<1>() {}
 	uint16 subst_id;
-	struct SpriteGroup *spritegroup;      ///< pointer to the different sprites of the entity
 	uint16 override;                      ///< id of the entity been replaced by
 };
 
--- a/src/newgrf_house.cpp
+++ b/src/newgrf_house.cpp
@@ -408,7 +408,7 @@
 	object.u.house.not_yet_constructed = not_yet_constructed;
 	object.u.house.initial_random_bits = initial_random_bits;
 
-	group = SpriteGroup::Resolve(HouseSpec::Get(house_id)->grf_prop.spritegroup, &object);
+	group = SpriteGroup::Resolve(HouseSpec::Get(house_id)->grf_prop.spritegroup[0], &object);
 	if (group == NULL) return CALLBACK_FAILED;
 
 	return group->GetCallbackResult();
@@ -459,7 +459,7 @@
 
 	NewHouseResolver(&object, house_id, ti->tile, Town::GetByTile(ti->tile));
 
-	group = SpriteGroup::Resolve(hs->grf_prop.spritegroup, &object);
+	group = SpriteGroup::Resolve(hs->grf_prop.spritegroup[0], &object);
 	if (group == NULL || group->type != SGT_TILELAYOUT) {
 		return;
 	} else {
@@ -639,7 +639,7 @@
 	object.callback = CBID_RANDOM_TRIGGER;
 	object.trigger = trigger;
 
-	const SpriteGroup *group = SpriteGroup::Resolve(hs->grf_prop.spritegroup, &object);
+	const SpriteGroup *group = SpriteGroup::Resolve(hs->grf_prop.spritegroup[0], &object);
 	if (group == NULL) return;
 
 	byte new_random_bits = Random();
--- a/src/newgrf_industries.cpp
+++ b/src/newgrf_industries.cpp
@@ -397,7 +397,7 @@
 	object.callback_param1 = param1;
 	object.callback_param2 = param2;
 
-	group = SpriteGroup::Resolve(GetIndustrySpec(type)->grf_prop.spritegroup, &object);
+	group = SpriteGroup::Resolve(GetIndustrySpec(type)->grf_prop.spritegroup[0], &object);
 	if (group == NULL) return CALLBACK_FAILED;
 
 	return group->GetCallbackResult();
@@ -483,7 +483,7 @@
 	object.callback = CBID_INDUSTRY_LOCATION;
 	_industry_creation_random_bits = seed;
 
-	group = SpriteGroup::Resolve(GetIndustrySpec(type)->grf_prop.spritegroup, &object);
+	group = SpriteGroup::Resolve(GetIndustrySpec(type)->grf_prop.spritegroup[0], &object);
 
 	/* Unlike the "normal" cases, not having a valid result means we allow
 	 * the building of the industry, as that's how it's done in TTDP. */
@@ -552,7 +552,7 @@
 		}
 
 		SB(object.callback_param2, 8, 16, loop);
-		const SpriteGroup *tgroup = SpriteGroup::Resolve(spec->grf_prop.spritegroup, &object);
+		const SpriteGroup *tgroup = SpriteGroup::Resolve(spec->grf_prop.spritegroup[0], &object);
 		if (tgroup == NULL || tgroup->type != SGT_INDUSTRY_PRODUCTION) break;
 		const IndustryProductionSpriteGroup *group = (const IndustryProductionSpriteGroup *)tgroup;
 
--- a/src/newgrf_industrytiles.cpp
+++ b/src/newgrf_industrytiles.cpp
@@ -212,7 +212,7 @@
 	object.callback_param1 = param1;
 	object.callback_param2 = param2;
 
-	group = SpriteGroup::Resolve(GetIndustryTileSpec(gfx_id)->grf_prop.spritegroup, &object);
+	group = SpriteGroup::Resolve(GetIndustryTileSpec(gfx_id)->grf_prop.spritegroup[0], &object);
 	if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED;
 
 	return group->GetCallbackResult();
@@ -236,7 +236,7 @@
 
 	NewIndustryTileResolver(&object, gfx, ti->tile, i);
 
-	group = SpriteGroup::Resolve(inds->grf_prop.spritegroup, &object);
+	group = SpriteGroup::Resolve(inds->grf_prop.spritegroup[0], &object);
 	if (group == NULL || group->type != SGT_TILELAYOUT) {
 		return false;
 	} else {
@@ -426,7 +426,7 @@
 	object.callback = CBID_RANDOM_TRIGGER;
 	object.trigger = trigger;
 
-	const SpriteGroup *group = SpriteGroup::Resolve(itspec->grf_prop.spritegroup, &object);
+	const SpriteGroup *group = SpriteGroup::Resolve(itspec->grf_prop.spritegroup[0], &object);
 	if (group == NULL) return;
 
 	byte new_random_bits = Random();
--- a/src/newgrf_station.h
+++ b/src/newgrf_station.h
@@ -47,7 +47,7 @@
 
 /** Station specification. */
 struct StationSpec {
-	GRFFilePropsBase grf_prop; ///< Properties related the the grf file
+	GRFFilePropsBase<0> grf_prop; ///< Properties related the the grf file
 	StationClassID cls_id;     ///< The class to which this spec belongs.
 	StringID name;             ///< Name of this station.