1
0
Fork 0

Codechange: Use std::bitset instead of bool array.

This avoids use of C-style pointers and memset.
pull/11327/head
Peter Nelson 2023-09-20 20:59:31 +01:00 committed by PeterN
parent 2eacf36d0a
commit aeaa552385
1 changed files with 7 additions and 6 deletions

View File

@ -67,6 +67,8 @@
#include "table/strings.h" #include "table/strings.h"
#include <bitset>
#include "safeguards.h" #include "safeguards.h"
/** /**
@ -216,7 +218,7 @@ enum StationNaming {
/** Information to handle station action 0 property 24 correctly */ /** Information to handle station action 0 property 24 correctly */
struct StationNameInformation { struct StationNameInformation {
uint32_t free_names; ///< Current bitset of free names (we can remove names). 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(Station *st, TileIndex tile, StationNaming n
const Town *t = st->town; const Town *t = st->town;
uint32_t free_names = UINT32_MAX; uint32_t free_names = UINT32_MAX;
bool indtypes[NUM_INDUSTRYTYPES]; StationNameInformation sni{};
memset(indtypes, 0, sizeof(indtypes));
for (const Station *s : Station::Iterate()) { for (const Station *s : Station::Iterate()) {
if (s != st && s->town == t) { if (s != st && s->town == t) {
if (s->indtype != IT_INVALID) { if (s->indtype != IT_INVALID) {
indtypes[s->indtype] = true; sni.indtypes[s->indtype] = true;
StringID name = GetIndustrySpec(s->indtype)->station_name; StringID name = GetIndustrySpec(s->indtype)->station_name;
if (name != STR_UNDEFINED) { if (name != STR_UNDEFINED) {
/* Filter for other industrytypes with the same name */ /* Filter for other industrytypes with the same name */
for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) { for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
const IndustrySpec *indsp = GetIndustrySpec(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; continue;
@ -285,7 +286,7 @@ static StringID GenerateStationName(Station *st, TileIndex tile, StationNaming n
} }
TileIndex indtile = tile; TileIndex indtile = tile;
StationNameInformation sni = { free_names, indtypes }; sni.free_names = free_names;
if (CircularTileSearch(&indtile, 7, FindNearIndustryName, &sni)) { if (CircularTileSearch(&indtile, 7, FindNearIndustryName, &sni)) {
/* An industry has been found nearby */ /* An industry has been found nearby */
IndustryType indtype = GetIndustryType(indtile); IndustryType indtype = GetIndustryType(indtile);