mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Make station variable cache a member of StationScopeResolver.
parent
ec38cb10d0
commit
5389ecf688
|
@ -250,21 +250,6 @@ static uint32_t GetRailContinuationInfo(TileIndex tile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Station variable cache
|
|
||||||
* This caches 'expensive' station variable lookups which iterate over
|
|
||||||
* several tiles that may be called multiple times per Resolve().
|
|
||||||
*/
|
|
||||||
static struct {
|
|
||||||
uint32_t v40;
|
|
||||||
uint32_t v41;
|
|
||||||
uint32_t v45;
|
|
||||||
uint32_t v46;
|
|
||||||
uint32_t v47;
|
|
||||||
uint32_t v49;
|
|
||||||
uint8_t valid; ///< Bits indicating what variable is valid (for each bit, \c 0 is invalid, \c 1 is valid).
|
|
||||||
} _svc;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the town scope associated with a station, if it exists.
|
* Get the town scope associated with a station, if it exists.
|
||||||
* On the first call, the town scope is created (if possible).
|
* On the first call, the town scope is created (if possible).
|
||||||
|
@ -322,31 +307,31 @@ TownScopeResolver *StationResolverObject::GetTown()
|
||||||
switch (variable) {
|
switch (variable) {
|
||||||
/* Calculated station variables */
|
/* Calculated station variables */
|
||||||
case 0x40:
|
case 0x40:
|
||||||
if (!HasBit(_svc.valid, 0)) { _svc.v40 = GetPlatformInfoHelper(this->tile, false, false, false); SetBit(_svc.valid, 0); }
|
if (!this->cache.v40.has_value()) this->cache.v40 = GetPlatformInfoHelper(this->tile, false, false, false);
|
||||||
return _svc.v40;
|
return *this->cache.v40;
|
||||||
|
|
||||||
case 0x41:
|
case 0x41:
|
||||||
if (!HasBit(_svc.valid, 1)) { _svc.v41 = GetPlatformInfoHelper(this->tile, true, false, false); SetBit(_svc.valid, 1); }
|
if (!this->cache.v41.has_value()) this->cache.v41 = GetPlatformInfoHelper(this->tile, true, false, false);
|
||||||
return _svc.v41;
|
return *this->cache.v41;
|
||||||
|
|
||||||
case 0x42: return GetTerrainType(this->tile) | (GetReverseRailTypeTranslation(GetRailType(this->tile), this->statspec->grf_prop.grffile) << 8);
|
case 0x42: return GetTerrainType(this->tile) | (GetReverseRailTypeTranslation(GetRailType(this->tile), this->statspec->grf_prop.grffile) << 8);
|
||||||
case 0x43: return GetCompanyInfo(this->st->owner); // Station owner
|
case 0x43: return GetCompanyInfo(this->st->owner); // Station owner
|
||||||
case 0x44: return HasStationReservation(this->tile) ? 7 : 4; // PBS status
|
case 0x44: return HasStationReservation(this->tile) ? 7 : 4; // PBS status
|
||||||
case 0x45:
|
case 0x45:
|
||||||
if (!HasBit(_svc.valid, 2)) { _svc.v45 = GetRailContinuationInfo(this->tile); SetBit(_svc.valid, 2); }
|
if (!this->cache.v45.has_value()) this->cache.v45 = GetRailContinuationInfo(this->tile);
|
||||||
return _svc.v45;
|
return *this->cache.v45;
|
||||||
|
|
||||||
case 0x46:
|
case 0x46:
|
||||||
if (!HasBit(_svc.valid, 3)) { _svc.v46 = GetPlatformInfoHelper(this->tile, false, false, true); SetBit(_svc.valid, 3); }
|
if (!this->cache.v46.has_value()) this->cache.v46 = GetPlatformInfoHelper(this->tile, false, false, true);
|
||||||
return _svc.v46;
|
return *this->cache.v46;
|
||||||
|
|
||||||
case 0x47:
|
case 0x47:
|
||||||
if (!HasBit(_svc.valid, 4)) { _svc.v47 = GetPlatformInfoHelper(this->tile, true, false, true); SetBit(_svc.valid, 4); }
|
if (!this->cache.v47.has_value()) this->cache.v47 = GetPlatformInfoHelper(this->tile, true, false, true);
|
||||||
return _svc.v47;
|
return *this->cache.v47;
|
||||||
|
|
||||||
case 0x49:
|
case 0x49:
|
||||||
if (!HasBit(_svc.valid, 5)) { _svc.v49 = GetPlatformInfoHelper(this->tile, false, true, false); SetBit(_svc.valid, 5); }
|
if (!this->cache.v49.has_value()) this->cache.v49 = GetPlatformInfoHelper(this->tile, false, true, false);
|
||||||
return _svc.v49;
|
return *this->cache.v49;
|
||||||
|
|
||||||
case 0x4A: // Animation frame of tile
|
case 0x4A: // Animation frame of tile
|
||||||
return GetAnimationFrame(this->tile);
|
return GetAnimationFrame(this->tile);
|
||||||
|
@ -593,9 +578,6 @@ StationResolverObject::StationResolverObject(const StationSpec *statspec, BaseSt
|
||||||
: SpecializedResolverObject<StationRandomTriggers>(statspec->grf_prop.grffile, callback, callback_param1, callback_param2),
|
: SpecializedResolverObject<StationRandomTriggers>(statspec->grf_prop.grffile, callback, callback_param1, callback_param2),
|
||||||
station_scope(*this, statspec, base_station, tile)
|
station_scope(*this, statspec, base_station, tile)
|
||||||
{
|
{
|
||||||
/* Invalidate all cached vars */
|
|
||||||
_svc.valid = 0;
|
|
||||||
|
|
||||||
CargoType ctype = CargoGRFFileProps::SG_DEFAULT_NA;
|
CargoType ctype = CargoGRFFileProps::SG_DEFAULT_NA;
|
||||||
|
|
||||||
if (this->station_scope.st == nullptr) {
|
if (this->station_scope.st == nullptr) {
|
||||||
|
|
|
@ -30,6 +30,21 @@ struct StationScopeResolver : public ScopeResolver {
|
||||||
CargoType cargo_type; ///< Type of cargo of the station.
|
CargoType cargo_type; ///< Type of cargo of the station.
|
||||||
Axis axis; ///< Station axis, used only for the slope check callback.
|
Axis axis; ///< Station axis, used only for the slope check callback.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Station variable cache
|
||||||
|
* This caches 'expensive' station variable lookups which iterate over
|
||||||
|
* several tiles that may be called multiple times per Resolve().
|
||||||
|
*/
|
||||||
|
struct Cache {
|
||||||
|
std::optional<uint32_t> v40;
|
||||||
|
std::optional<uint32_t> v41;
|
||||||
|
std::optional<uint32_t> v45;
|
||||||
|
std::optional<uint32_t> v46;
|
||||||
|
std::optional<uint32_t> v47;
|
||||||
|
std::optional<uint32_t> v49;
|
||||||
|
};
|
||||||
|
mutable Cache cache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for station scopes.
|
* Constructor for station scopes.
|
||||||
* @param ro Surrounding resolver.
|
* @param ro Surrounding resolver.
|
||||||
|
|
Loading…
Reference in New Issue