Changeset - r27959:94f36260af09
[Not reviewed]
master
0 1 0
Peter Nelson - 15 months ago 2023-09-20 19:59:31
peter1138@openttd.org
Codechange: Use std::bitset instead of bool array.

This avoids use of C-style pointers and memset.
1 file changed with 7 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/station_cmd.cpp
Show inline comments
 
@@ -67,6 +67,8 @@
 

	
 
#include "table/strings.h"
 

	
 
#include <bitset>
 

	
 
#include "safeguards.h"
 

	
 
/**
 
@@ -216,7 +218,7 @@ enum StationNaming {
 
/** Information to handle station action 0 property 24 correctly */
 
struct StationNameInformation {
 
	uint32_t free_names; ///< Current bitset of free names (we can remove names).
 
	bool *indtypes;    ///< Array of bools telling whether an industry type has been found.
 
	std::bitset<NUM_INDUSTRYTYPES> indtypes; ///< Bit set indicating when an industry type has been found.
 
};
 

	
 
/**
 
@@ -257,19 +259,18 @@ static StringID GenerateStationName(Stat
 
	const Town *t = st->town;
 
	uint32_t free_names = UINT32_MAX;
 

	
 
	bool indtypes[NUM_INDUSTRYTYPES];
 
	memset(indtypes, 0, sizeof(indtypes));
 
	StationNameInformation sni{};
 

	
 
	for (const Station *s : Station::Iterate()) {
 
		if (s != st && s->town == t) {
 
			if (s->indtype != IT_INVALID) {
 
				indtypes[s->indtype] = true;
 
				sni.indtypes[s->indtype] = true;
 
				StringID name = GetIndustrySpec(s->indtype)->station_name;
 
				if (name != STR_UNDEFINED) {
 
					/* Filter for other industrytypes with the same name */
 
					for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
 
						const IndustrySpec *indsp = GetIndustrySpec(it);
 
						if (indsp->enabled && indsp->station_name == name) indtypes[it] = true;
 
						if (indsp->enabled && indsp->station_name == name) sni.indtypes[it] = true;
 
					}
 
				}
 
				continue;
 
@@ -285,7 +286,7 @@ static StringID GenerateStationName(Stat
 
	}
 

	
 
	TileIndex indtile = tile;
 
	StationNameInformation sni = { free_names, indtypes };
 
	sni.free_names = free_names;
 
	if (CircularTileSearch(&indtile, 7, FindNearIndustryName, &sni)) {
 
		/* An industry has been found nearby */
 
		IndustryType indtype = GetIndustryType(indtile);
0 comments (0 inline, 0 general)