File diff r19258:f88011d357af → r19259:e556e5a2d55f
src/newgrf_class_func.h
Show inline comments
 
@@ -56,36 +56,24 @@ DEFINE_NEWGRF_CLASS_METHOD(Tid)::Allocat
 
		} else if (classes[i].global_id == 0) {
 
			/* This class is empty, so allocate it to the global id. */
 
			classes[i].global_id = global_id;
 
			return i;
 
		}
 
	}
 

	
 
	grfmsg(2, "ClassAllocate: already allocated %d classes, using default", Tmax);
 
	return (Tid)0;
 
}
 

	
 
/**
 
 * 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.
 
 */
 
DEFINE_NEWGRF_CLASS_METHOD(void)::Assign(Tspec *spec)
 
{
 
	assert(spec->cls_id < Tmax);
 
	NewGRFClass<Tspec, Tid, Tmax> *cls = &classes[spec->cls_id];
 

	
 
	uint i = cls->count++;
 
	cls->spec = ReallocT(cls->spec, cls->count);
 

	
 
@@ -96,36 +84,24 @@ DEFINE_NEWGRF_CLASS_METHOD(void)::Assign
 
 * Get a particular class.
 
 * @param cls_id The id for the class.
 
 * @pre cls_id < Tmax
 
 */
 
template <typename Tspec, typename Tid, Tid Tmax>
 
NewGRFClass<Tspec, Tid, Tmax> *NewGRFClass<Tspec, Tid, Tmax>::Get(Tid cls_id)
 
{
 
	assert(cls_id < Tmax);
 
	return classes + cls_id;
 
}
 

	
 
/**
 
 * 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.
 
 */
 
DEFINE_NEWGRF_CLASS_METHOD(uint)::GetCount()
 
{
 
	uint i;
 
	for (i = 0; i < Tmax && classes[i].global_id != 0; i++) {}
 
	return i;
 
}
 

	
 
/**
 
 * Get the number of allocated specs within a particular class.
 
@@ -177,20 +153,18 @@ DEFINE_NEWGRF_CLASS_METHOD(const Tspec *
 
		}
 
	}
 

	
 
	return NULL;
 
}
 

	
 
#undef DEFINE_NEWGRF_CLASS_METHOD
 

	
 
/** Force instantiation of the methods so we don't get linker errors. */
 
#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); \
 
	template const Tspec *name::GetByGrf(uint32 grfid, byte localidx, int *index);