mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use FlatSet for per-industry type industry lists.
parent
6070f8d4f3
commit
7c834921b2
|
@ -10,6 +10,7 @@
|
||||||
#ifndef INDUSTRY_H
|
#ifndef INDUSTRY_H
|
||||||
#define INDUSTRY_H
|
#define INDUSTRY_H
|
||||||
|
|
||||||
|
#include "core/flatset_type.hpp"
|
||||||
#include "newgrf_storage.h"
|
#include "newgrf_storage.h"
|
||||||
#include "subsidy_type.h"
|
#include "subsidy_type.h"
|
||||||
#include "industry_map.h"
|
#include "industry_map.h"
|
||||||
|
@ -257,7 +258,7 @@ struct Industry : IndustryPool::PoolItem<&_industry_pool> {
|
||||||
return this->cached_name;
|
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:
|
private:
|
||||||
void FillCachedName() const;
|
void FillCachedName() const;
|
||||||
|
|
|
@ -63,7 +63,7 @@ void BuildOilRig(TileIndex tile);
|
||||||
static uint8_t _industry_sound_ctr;
|
static uint8_t _industry_sound_ctr;
|
||||||
static TileIndex _industry_sound_tile;
|
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];
|
IndustrySpec _industry_specs[NUM_INDUSTRYTYPES];
|
||||||
IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES];
|
IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES];
|
||||||
|
@ -190,8 +190,7 @@ Industry::~Industry()
|
||||||
delete this->psa;
|
delete this->psa;
|
||||||
|
|
||||||
auto &industries = Industry::industries[type];
|
auto &industries = Industry::industries[type];
|
||||||
auto it = std::ranges::lower_bound(industries, this->index);
|
industries.erase(this->index);
|
||||||
industries.erase(it);
|
|
||||||
|
|
||||||
DeleteIndustryNews(this->index);
|
DeleteIndustryNews(this->index);
|
||||||
CloseWindowById(WC_INDUSTRY_VIEW, this->index);
|
CloseWindowById(WC_INDUSTRY_VIEW, this->index);
|
||||||
|
@ -1760,7 +1759,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type,
|
||||||
i->type = type;
|
i->type = type;
|
||||||
|
|
||||||
auto &industries = Industry::industries[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) {
|
for (size_t index = 0; index < std::size(indspec->produced_cargo); ++index) {
|
||||||
if (!IsValidCargoType(indspec->produced_cargo[index])) break;
|
if (!IsValidCargoType(indspec->produced_cargo[index])) break;
|
||||||
|
|
|
@ -228,7 +228,7 @@ struct INDYChunkHandler : ChunkHandler {
|
||||||
} else if (IsSavegameVersionBefore(SLV_INDUSTRY_CARGO_REORGANISE)) {
|
} else if (IsSavegameVersionBefore(SLV_INDUSTRY_CARGO_REORGANISE)) {
|
||||||
LoadMoveAcceptsProduced(i, INDUSTRY_NUM_INPUTS, INDUSTRY_NUM_OUTPUTS);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -875,7 +875,7 @@ static bool LoadOldIndustry(LoadgameState &ls, int num)
|
||||||
i->random_colour = RemapTTOColour(i->random_colour);
|
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 {
|
} else {
|
||||||
delete i;
|
delete i;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue