mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-21 19:32:54 +01:00
Codechange: Split GoodsEntry cargo and flows data to unique_ptr. (#13058)
This allows cargo packets and cargo flow data to be empty if not in use, which is the case for the majority of station goods entries, and data is allocated when needed. This reduces the initial size of a Station from 9192 bytes to 2024 bytes (on 64 bit platforms), although an allocation of 120 bytes is made for each active cargo type at a station. Based on similar changes in JGRPP.
This commit is contained in:
@@ -59,7 +59,10 @@ template<bool Tfrom, bool Tvia>
|
||||
return -1;
|
||||
}
|
||||
|
||||
const StationCargoList &cargo_list = ::Station::Get(station_id)->goods[cargo_id].cargo;
|
||||
const ::GoodsEntry &goods = ::Station::Get(station_id)->goods[cargo_id];
|
||||
if (!goods.HasData()) return 0;
|
||||
|
||||
const StationCargoList &cargo_list = goods.GetData().cargo;
|
||||
if (!Tfrom && !Tvia) return cargo_list.TotalCount();
|
||||
|
||||
uint16_t cargo_count = 0;
|
||||
@@ -107,7 +110,10 @@ template<bool Tfrom, bool Tvia>
|
||||
return -1;
|
||||
}
|
||||
|
||||
const FlowStatMap &flows = ::Station::Get(station_id)->goods[cargo_id].flows;
|
||||
const ::GoodsEntry &goods = ::Station::Get(station_id)->goods[cargo_id];
|
||||
if (!goods.HasData()) return 0;
|
||||
|
||||
const FlowStatMap &flows = goods.GetData().flows;
|
||||
if (Tfrom) {
|
||||
return Tvia ? flows.GetFlowFromVia(from_station_id, via_station_id) :
|
||||
flows.GetFlowFrom(from_station_id);
|
||||
|
||||
@@ -179,9 +179,10 @@ void ScriptStationList_CargoWaiting::Add(StationID station_id, CargoID cargo, St
|
||||
{
|
||||
CargoCollector collector(this, station_id, cargo, other_station);
|
||||
if (collector.GE() == nullptr) return;
|
||||
if (!collector.GE()->HasData()) return;
|
||||
|
||||
StationCargoList::ConstIterator iter = collector.GE()->cargo.Packets()->begin();
|
||||
StationCargoList::ConstIterator end = collector.GE()->cargo.Packets()->end();
|
||||
StationCargoList::ConstIterator iter = collector.GE()->GetData().cargo.Packets()->begin();
|
||||
StationCargoList::ConstIterator end = collector.GE()->GetData().cargo.Packets()->end();
|
||||
for (; iter != end; ++iter) {
|
||||
collector.Update<Tselector>((*iter)->GetFirstStation(), iter.GetKey(), (*iter)->Count());
|
||||
}
|
||||
@@ -193,9 +194,10 @@ void ScriptStationList_CargoPlanned::Add(StationID station_id, CargoID cargo, St
|
||||
{
|
||||
CargoCollector collector(this, station_id, cargo, other_station);
|
||||
if (collector.GE() == nullptr) return;
|
||||
if (!collector.GE()->HasData()) return;
|
||||
|
||||
FlowStatMap::const_iterator iter = collector.GE()->flows.begin();
|
||||
FlowStatMap::const_iterator end = collector.GE()->flows.end();
|
||||
FlowStatMap::const_iterator iter = collector.GE()->GetData().flows.begin();
|
||||
FlowStatMap::const_iterator end = collector.GE()->GetData().flows.end();
|
||||
for (; iter != end; ++iter) {
|
||||
const FlowStat::SharesMap *shares = iter->second.GetShares();
|
||||
uint prev = 0;
|
||||
@@ -218,9 +220,10 @@ ScriptStationList_CargoWaitingViaByFrom::ScriptStationList_CargoWaitingViaByFrom
|
||||
{
|
||||
CargoCollector collector(this, station_id, cargo, via);
|
||||
if (collector.GE() == nullptr) return;
|
||||
if (!collector.GE()->HasData()) return;
|
||||
|
||||
std::pair<StationCargoList::ConstIterator, StationCargoList::ConstIterator> range =
|
||||
collector.GE()->cargo.Packets()->equal_range(via);
|
||||
collector.GE()->GetData().cargo.Packets()->equal_range(via);
|
||||
for (StationCargoList::ConstIterator iter = range.first; iter != range.second; ++iter) {
|
||||
collector.Update<CS_VIA_BY_FROM>((*iter)->GetFirstStation(), iter.GetKey(), (*iter)->Count());
|
||||
}
|
||||
@@ -264,9 +267,10 @@ ScriptStationList_CargoPlannedFromByVia::ScriptStationList_CargoPlannedFromByVia
|
||||
{
|
||||
CargoCollector collector(this, station_id, cargo, from);
|
||||
if (collector.GE() == nullptr) return;
|
||||
if (!collector.GE()->HasData()) return;
|
||||
|
||||
FlowStatMap::const_iterator iter = collector.GE()->flows.find(from);
|
||||
if (iter == collector.GE()->flows.end()) return;
|
||||
FlowStatMap::const_iterator iter = collector.GE()->GetData().flows.find(from);
|
||||
if (iter == collector.GE()->GetData().flows.end()) return;
|
||||
const FlowStat::SharesMap *shares = iter->second.GetShares();
|
||||
uint prev = 0;
|
||||
for (FlowStat::SharesMap::const_iterator flow_iter = shares->begin();
|
||||
|
||||
Reference in New Issue
Block a user