Move StationCargoList and FlowStatMap out of GoodsEntry struct

Move them into a new GoodsEntryData struct referenced
using a std::unique_ptr from GoodsEntry.
The unique_ptr may be nullptr if the cargo list and flow stat map
are both empty (this is the case for unused cargoes).

This reduces GoodsEntry from 128 to 24 bytes,
and Station from 8680 to 2024 bytes,
(on Linux x86_64).
This commit is contained in:
Jonathan G Rennison
2023-08-19 21:21:31 +01:00
parent cd2ab6430b
commit 19835b51ee
24 changed files with 283 additions and 137 deletions

View File

@@ -447,10 +447,10 @@ uint32 Station::GetNewGRFVariable(const ResolverObject &object, uint16 variable,
const GoodsEntry *ge = &this->goods[c];
switch (variable) {
case 0x60: return std::min<uint32>(ge->cargo.TotalCount(), 4095);
case 0x60: return std::min<uint32>(ge->CargoTotalCount(), 4095);
case 0x61: return ge->HasVehicleEverTriedLoading() && ge->IsSupplyAllowed() ? ge->time_since_pickup : 0;
case 0x62: return ge->HasRating() ? ge->rating : 0xFFFFFFFF;
case 0x63: return ge->cargo.DaysInTransit();
case 0x63: return ge->data != nullptr ? ge->data->cargo.DaysInTransit() : 0;
case 0x64: return ge->HasVehicleEverTriedLoading() && ge->IsSupplyAllowed() ? ge->last_speed | (ge->last_age << 8) : 0xFF00;
case 0x65: return GB(ge->status, GoodsEntry::GES_ACCEPTANCE, 1) << 3;
case 0x69: {
@@ -466,12 +466,12 @@ uint32 Station::GetNewGRFVariable(const ResolverObject &object, uint16 variable,
if (variable >= 0x8C && variable <= 0xEC) {
const GoodsEntry *g = &this->goods[GB(variable - 0x8C, 3, 4)];
switch (GB(variable - 0x8C, 0, 3)) {
case 0: return g->cargo.TotalCount();
case 1: return GB(std::min(g->cargo.TotalCount(), 4095u), 0, 4) | (GB(g->status, GoodsEntry::GES_ACCEPTANCE, 1) << 7);
case 0: return g->CargoTotalCount();
case 1: return GB(std::min(g->CargoTotalCount(), 4095u), 0, 4) | (GB(g->status, GoodsEntry::GES_ACCEPTANCE, 1) << 7);
case 2: return g->time_since_pickup;
case 3: return g->rating;
case 4: return g->cargo.Source();
case 5: return g->cargo.DaysInTransit();
case 4: return g->data != nullptr ? g->data->cargo.Source() : INVALID_STATION;
case 5: return g->data != nullptr ? g->data->cargo.DaysInTransit() : 0;
case 6: return g->last_speed;
case 7: return g->last_age;
}
@@ -533,12 +533,12 @@ uint32 Waypoint::GetNewGRFVariable(const ResolverObject &object, uint16 variable
case CT_DEFAULT:
for (CargoID cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) {
cargo += st->goods[cargo_type].cargo.TotalCount();
cargo += st->goods[cargo_type].CargoTotalCount();
}
break;
default:
cargo = st->goods[this->station_scope.cargo_type].cargo.TotalCount();
cargo = st->goods[this->station_scope.cargo_type].CargoTotalCount();
break;
}
@@ -598,7 +598,7 @@ StationResolverObject::StationResolverObject(const StationSpec *statspec, BaseSt
/* Pick the first cargo that we have waiting */
for (const CargoSpec *cs : CargoSpec::Iterate()) {
if (this->station_scope.statspec->grf_prop.spritegroup[cs->Index()] != nullptr &&
st->goods[cs->Index()].cargo.TotalCount() > 0) {
st->goods[cs->Index()].CargoTotalCount() > 0) {
ctype = cs->Index();
break;
}
@@ -1006,7 +1006,7 @@ void TriggerStationRandomisation(Station *st, TileIndex trigger_tile, StationRan
if (trigger == SRT_CARGO_TAKEN) {
/* Create a bitmask of completely empty cargo types to be matched */
for (CargoID i = 0; i < NUM_CARGO; i++) {
if (st->goods[i].cargo.TotalCount() == 0) {
if (st->goods[i].CargoTotalCount() == 0) {
SetBit(empty_mask, i);
}
}