Changeset - r19259:e556e5a2d55f
[Not reviewed]
master
0 9 0
frosch - 12 years ago 2012-04-22 16:27:55
frosch@openttd.org
(svn r24162) -Codechange: Remove NewGRFClass::GetName() and SetName() in favour of using Get() and direct member access (which is needed anyway for GRF string resolving).
9 files changed with 19 insertions and 46 deletions:
0 comments (0 inline, 0 general)
src/airport_gui.cpp
Show inline comments
 
@@ -208,7 +208,7 @@ class BuildAirportWindow : public Picker
 
		DropDownList *list = new DropDownList();
 

	
 
		for (uint i = 0; i < AirportClass::GetCount(); i++) {
 
			list->push_back(new DropDownListStringItem(AirportClass::GetName((AirportClassID)i), i, false));
 
			list->push_back(new DropDownListStringItem(AirportClass::Get((AirportClassID)i)->name, i, false));
 
		}
 

	
 
		return list;
 
@@ -242,7 +242,7 @@ public:
 
	{
 
		switch (widget) {
 
			case WID_AP_CLASS_DROPDOWN:
 
				SetDParam(0, AirportClass::GetName(_selected_airport_class));
 
				SetDParam(0, AirportClass::Get(_selected_airport_class)->name);
 
				break;
 

	
 
			case WID_AP_LAYOUT_NUM:
 
@@ -269,7 +269,7 @@ public:
 
			case WID_AP_CLASS_DROPDOWN: {
 
				Dimension d = {0, 0};
 
				for (uint i = 0; i < AirportClass::GetCount(); i++) {
 
					SetDParam(0, AirportClass::GetName((AirportClassID)i));
 
					SetDParam(0, AirportClass::Get((AirportClassID)i)->name);
 
					d = maxdim(d, GetStringBoundingBox(STR_BLACK_STRING));
 
				}
 
				d.width += padding.width;
src/newgrf.cpp
Show inline comments
 
@@ -3809,8 +3809,9 @@ static ChangeInfoResult ObjectChangeInfo
 

	
 
			case 0x09: { // Class name
 
				StringID class_name = buf->ReadWord();
 
				ObjectClass::SetName(spec->cls_id, class_name);
 
				_string_to_grf_mapping[&ObjectClass::classes[spec->cls_id].name] = _cur.grffile->grfid;
 
				ObjectClass *objclass = ObjectClass::Get(spec->cls_id);
 
				objclass->name = class_name;
 
				_string_to_grf_mapping[&objclass->name] = _cur.grffile->grfid;
 
				break;
 
			}
 

	
 
@@ -5351,7 +5352,7 @@ static void FeatureNewName(ByteReader *b
 
							grfmsg(1, "FeatureNewName: Attempt to name undefined station 0x%X, ignoring", GB(id, 0, 8));
 
						} else {
 
							StationClassID cls_id = _cur.grffile->stations[GB(id, 0, 8)]->cls_id;
 
							StationClass::SetName(cls_id, AddGRFString(_cur.grffile->grfid, id, lang, new_scheme, false, name, STR_UNDEFINED));
 
							StationClass::Get(cls_id)->name = AddGRFString(_cur.grffile->grfid, id, lang, new_scheme, false, name, STR_UNDEFINED);
 
						}
 
						break;
 

	
src/newgrf_airport.cpp
Show inline comments
 
@@ -25,10 +25,10 @@
 
template <typename Tspec, typename Tid, Tid Tmax>
 
/* static */ void NewGRFClass<Tspec, Tid, Tmax>::InsertDefaults()
 
{
 
	AirportClass::SetName(AirportClass::Allocate('SMAL'), STR_AIRPORT_CLASS_SMALL);
 
	AirportClass::SetName(AirportClass::Allocate('LARG'), STR_AIRPORT_CLASS_LARGE);
 
	AirportClass::SetName(AirportClass::Allocate('HUB_'), STR_AIRPORT_CLASS_HUB);
 
	AirportClass::SetName(AirportClass::Allocate('HELI'), STR_AIRPORT_CLASS_HELIPORTS);
 
	AirportClass::Get(AirportClass::Allocate('SMAL'))->name = STR_AIRPORT_CLASS_SMALL;
 
	AirportClass::Get(AirportClass::Allocate('LARG'))->name = STR_AIRPORT_CLASS_LARGE;
 
	AirportClass::Get(AirportClass::Allocate('HUB_'))->name = STR_AIRPORT_CLASS_HUB;
 
	AirportClass::Get(AirportClass::Allocate('HELI'))->name = STR_AIRPORT_CLASS_HELIPORTS;
 
}
 

	
 
INSTANTIATE_NEWGRF_CLASS_METHODS(AirportClass, AirportSpec, AirportClassID, APC_MAX)
src/newgrf_class.h
Show inline comments
 
@@ -32,11 +32,9 @@ struct NewGRFClass {
 
	static void InsertDefaults();
 

	
 
	static Tid Allocate(uint32 global_id);
 
	static void SetName(Tid cls_id, StringID name);
 
	static void Assign(Tspec *spec);
 
	static NewGRFClass *Get(Tid cls_id);
 

	
 
	static StringID GetName(Tid cls_id);
 
	static uint GetCount();
 
	static uint GetCount(Tid cls_id);
 
	static const Tspec *Get(Tid cls_id, uint index);
src/newgrf_class_func.h
Show inline comments
 
@@ -65,18 +65,6 @@ DEFINE_NEWGRF_CLASS_METHOD(Tid)::Allocat
 
}
 

	
 
/**
 
 * Set the name of a particular class.
 
 * @param cls_id The id for the class.
 
 * @pre index < GetCount(cls_id)
 
 * @param name   The new name for the class.
 
 */
 
DEFINE_NEWGRF_CLASS_METHOD(void)::SetName(Tid cls_id, StringID name)
 
{
 
	assert(cls_id < Tmax);
 
	classes[cls_id].name = name;
 
}
 

	
 
/**
 
 * Assign a spec to one of the classes.
 
 * @param spec The spec to assign.
 
 * @note The spec must have a valid class id set.
 
@@ -105,18 +93,6 @@ NewGRFClass<Tspec, Tid, Tmax> *NewGRFCla
 
}
 

	
 
/**
 
 * Get the name of a particular class.
 
 * @param cls_id The class to get the name of.
 
 * @pre index < GetCount(cls_id)
 
 * @return The name of said class.
 
 */
 
DEFINE_NEWGRF_CLASS_METHOD(StringID)::GetName(Tid cls_id)
 
{
 
	assert(cls_id < Tmax);
 
	return classes[cls_id].name;
 
}
 

	
 
/**
 
 * Get the number of allocated classes.
 
 * @return The number of classes.
 
 */
 
@@ -186,10 +162,8 @@ DEFINE_NEWGRF_CLASS_METHOD(const Tspec *
 
#define INSTANTIATE_NEWGRF_CLASS_METHODS(name, Tspec, Tid, Tmax) \
 
	template void name::Reset(); \
 
	template Tid name::Allocate(uint32 global_id); \
 
	template void name::SetName(Tid cls_id, StringID name); \
 
	template void name::Assign(Tspec *spec); \
 
	template NewGRFClass<Tspec, Tid, Tmax> *name::Get(Tid cls_id); \
 
	template StringID name::GetName(Tid cls_id); \
 
	template uint name::GetCount(); \
 
	template uint name::GetCount(Tid cls_id); \
 
	template const Tspec *name::Get(Tid cls_id, uint index); \
src/newgrf_object.cpp
Show inline comments
 
@@ -103,12 +103,12 @@ template <typename Tspec, typename Tid, 
 
	if (_game_mode != GM_EDITOR) return;
 

	
 
	ObjectClassID cls = ObjectClass::Allocate('LTHS');
 
	ObjectClass::SetName(cls, STR_OBJECT_CLASS_LTHS);
 
	ObjectClass::Get(cls)->name = STR_OBJECT_CLASS_LTHS;
 
	_object_specs[OBJECT_LIGHTHOUSE].cls_id = cls;
 
	ObjectClass::Assign(&_object_specs[OBJECT_LIGHTHOUSE]);
 

	
 
	cls = ObjectClass::Allocate('TRNS');
 
	ObjectClass::SetName(cls, STR_OBJECT_CLASS_TRNS);
 
	ObjectClass::Get(cls)->name = STR_OBJECT_CLASS_TRNS;
 
	_object_specs[OBJECT_TRANSMITTER].cls_id = cls;
 
	ObjectClass::Assign(&_object_specs[OBJECT_TRANSMITTER]);
 
}
src/object_gui.cpp
Show inline comments
 
@@ -78,7 +78,7 @@ public:
 
		switch (widget) {
 
			case WID_BO_CLASS_LIST: {
 
				for (uint i = 0; i < ObjectClass::GetCount(); i++) {
 
					size->width = max(size->width, GetStringBoundingBox(ObjectClass::GetName((ObjectClassID)i)).width);
 
					size->width = max(size->width, GetStringBoundingBox(ObjectClass::Get((ObjectClassID)i)->name).width);
 
				}
 
				size->width += padding.width;
 
				this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
 
@@ -156,7 +156,7 @@ public:
 
			case WID_BO_CLASS_LIST: {
 
				int y = r.top;
 
				for (uint i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < ObjectClass::GetCount(); i++) {
 
					SetDParam(0, ObjectClass::GetName((ObjectClassID)i));
 
					SetDParam(0, ObjectClass::Get((ObjectClassID)i)->name);
 
					DrawString(r.left + WD_MATRIX_LEFT, r.right + WD_MATRIX_RIGHT, y + WD_MATRIX_TOP, STR_JUST_STRING,
 
							((int)i == _selected_object_class) ? TC_WHITE : TC_BLACK);
 
					y += this->line_height;
src/rail_gui.cpp
Show inline comments
 
@@ -1026,7 +1026,7 @@ public:
 
				Dimension d = {0, 0};
 
				for (uint i = 0; i < StationClass::GetCount(); i++) {
 
					if (i == STAT_CLASS_WAYP) continue;
 
					SetDParam(0, StationClass::GetName((StationClassID)i));
 
					SetDParam(0, StationClass::Get((StationClassID)i)->name);
 
					d = maxdim(d, GetStringBoundingBox(STR_BLACK_STRING));
 
				}
 
				size->width = max(size->width, d.width + padding.width);
 
@@ -1104,7 +1104,7 @@ public:
 
				for (uint i = 0; i < StationClass::GetCount(); i++) {
 
					if (i == STAT_CLASS_WAYP) continue;
 
					if (this->vscroll->IsVisible(statclass)) {
 
						SetDParam(0, StationClass::GetName((StationClassID)i));
 
						SetDParam(0, StationClass::Get((StationClassID)i)->name);
 
						DrawString(r.left + WD_MATRIX_LEFT, r.right - WD_MATRIX_RIGHT, row * this->line_height + r.top + WD_MATRIX_TOP, STR_JUST_STRING,
 
								(StationClassID)i == _railstation.station_class ? TC_WHITE : TC_BLACK);
 
						row++;
src/station_cmd.cpp
Show inline comments
 
@@ -2912,7 +2912,7 @@ static void GetTileDesc_Station(TileInde
 
		const StationSpec *spec = GetStationSpec(tile);
 

	
 
		if (spec != NULL) {
 
			td->station_class = StationClass::GetName(spec->cls_id);
 
			td->station_class = StationClass::Get(spec->cls_id)->name;
 
			td->station_name  = spec->name;
 

	
 
			if (spec->grf_prop.grffile != NULL) {
 
@@ -2927,7 +2927,7 @@ static void GetTileDesc_Station(TileInde
 

	
 
	if (IsAirport(tile)) {
 
		const AirportSpec *as = Station::GetByTile(tile)->airport.GetSpec();
 
		td->airport_class = AirportClass::GetName(as->cls_id);
 
		td->airport_class = AirportClass::Get(as->cls_id)->name;
 
		td->airport_name = as->name;
 

	
 
		const AirportTileSpec *ats = AirportTileSpec::GetByTile(tile);
0 comments (0 inline, 0 general)