Changeset - r27034:b6f1b823160c
[Not reviewed]
master
0 2 0
Peter Nelson - 22 months ago 2023-01-08 15:36:57
peter1138@openttd.org
Codechange: Use std::vector for NewGRF class lists.
2 files changed with 9 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/newgrf_class.h
Show inline comments
 
@@ -12,15 +12,16 @@
 

	
 
#include "strings_type.h"
 

	
 
#include <vector>
 

	
 
/**
 
 * Struct containing information relating to NewGRF classes for stations and airports.
 
 */
 
template <typename Tspec, typename Tid, Tid Tmax>
 
struct NewGRFClass {
 
private:
 
	uint count;       ///< Number of specs in this class.
 
	uint ui_count;    ///< Number of specs in this class potentially available to the user.
 
	Tspec **spec;     ///< Array of specifications.
 
	std::vector<Tspec *> spec; ///< List of specifications.
 

	
 
	/**
 
	 * The actual classes.
 
@@ -41,7 +42,7 @@ public:
 
	void Insert(Tspec *spec);
 

	
 
	/** Get the number of allocated specs within the class. */
 
	uint GetSpecCount() const { return this->count; }
 
	uint GetSpecCount() const { return static_cast<uint>(this->spec.size()); }
 
	/** Get the number of potentially user-available specs within the class. */
 
	uint GetUISpecCount() const { return this->ui_count; }
 
	int GetUIFromIndex(int index) const;
src/newgrf_class_func.h
Show inline comments
 
@@ -28,11 +28,9 @@ DEFINE_NEWGRF_CLASS_METHOD(void)::ResetC
 
{
 
	this->global_id = 0;
 
	this->name      = STR_EMPTY;
 
	this->count     = 0;
 
	this->ui_count  = 0;
 

	
 
	free(this->spec);
 
	this->spec = nullptr;
 
	this->spec.clear();
 
}
 

	
 
/** Reset the classes, i.e. clear everything. */
 
@@ -75,12 +73,9 @@ DEFINE_NEWGRF_CLASS_METHOD(Tid)::Allocat
 
 */
 
DEFINE_NEWGRF_CLASS_METHOD(void)::Insert(Tspec *spec)
 
{
 
	uint i = this->count++;
 
	this->spec = ReallocT(this->spec, this->count);
 
	this->spec.push_back(spec);
 

	
 
	this->spec[i] = spec;
 

	
 
	if (this->IsUIAvailable(i)) this->ui_count++;
 
	if (this->IsUIAvailable(static_cast<uint>(this->spec.size() - 1))) this->ui_count++;
 
}
 

	
 
/**
 
@@ -197,7 +192,8 @@ DEFINE_NEWGRF_CLASS_METHOD(const Tspec *
 
	uint j;
 

	
 
	for (Tid i = (Tid)0; i < Tmax; i++) {
 
		for (j = 0; j < classes[i].count; j++) {
 
		uint count = static_cast<uint>(classes[i].spec.size());
 
		for (j = 0; j < count; j++) {
 
			const Tspec *spec = classes[i].spec[j];
 
			if (spec == nullptr) continue;
 
			if (spec->grf_prop.grffile->grfid == grfid && spec->grf_prop.local_id == local_id) {
0 comments (0 inline, 0 general)