1
0
Fork 0

Codechange: Use FlatSet for per-industry type industry lists.

pull/14219/head
Peter Nelson 2025-05-05 00:49:13 +01:00 committed by Peter Nelson
parent 6070f8d4f3
commit 7c834921b2
4 changed files with 7 additions and 7 deletions

View File

@ -10,6 +10,7 @@
#ifndef INDUSTRY_H
#define INDUSTRY_H
#include "core/flatset_type.hpp"
#include "newgrf_storage.h"
#include "subsidy_type.h"
#include "industry_map.h"
@ -257,7 +258,7 @@ struct Industry : IndustryPool::PoolItem<&_industry_pool> {
return this->cached_name;
}
static std::array<std::vector<IndustryID>, NUM_INDUSTRYTYPES> industries; ///< List of industries of each type.
static std::array<FlatSet<IndustryID>, NUM_INDUSTRYTYPES> industries; ///< List of industries of each type.
private:
void FillCachedName() const;

View File

@ -63,7 +63,7 @@ void BuildOilRig(TileIndex tile);
static uint8_t _industry_sound_ctr;
static TileIndex _industry_sound_tile;
std::array<std::vector<IndustryID>, NUM_INDUSTRYTYPES> Industry::industries;
std::array<FlatSet<IndustryID>, NUM_INDUSTRYTYPES> Industry::industries;
IndustrySpec _industry_specs[NUM_INDUSTRYTYPES];
IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES];
@ -190,8 +190,7 @@ Industry::~Industry()
delete this->psa;
auto &industries = Industry::industries[type];
auto it = std::ranges::lower_bound(industries, this->index);
industries.erase(it);
industries.erase(this->index);
DeleteIndustryNews(this->index);
CloseWindowById(WC_INDUSTRY_VIEW, this->index);
@ -1760,7 +1759,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
i->type = type;
auto &industries = Industry::industries[type];
industries.emplace(std::ranges::lower_bound(industries, i->index), i->index);
industries.insert(i->index);
for (size_t index = 0; index < std::size(indspec->produced_cargo); ++index) {
if (!IsValidCargoType(indspec->produced_cargo[index])) break;

View File

@ -228,7 +228,7 @@ struct INDYChunkHandler : ChunkHandler {
} else if (IsSavegameVersionBefore(SLV_INDUSTRY_CARGO_REORGANISE)) {
LoadMoveAcceptsProduced(i, INDUSTRY_NUM_INPUTS, INDUSTRY_NUM_OUTPUTS);
}
Industry::industries[i->type].push_back(i->index); // Assume savegame indices are sorted.
Industry::industries[i->type].insert(i->index);
}
}

View File

@ -875,7 +875,7 @@ static bool LoadOldIndustry(LoadgameState &ls, int num)
i->random_colour = RemapTTOColour(i->random_colour);
}
Industry::industries[i->type].push_back(i->index); // Assume savegame indices are sorted.
Industry::industries[i->type].insert(i->index);
} else {
delete i;
}