summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorterkhen <terkhen@openttd.org>2010-11-06 12:37:55 +0000
committerterkhen <terkhen@openttd.org>2010-11-06 12:37:55 +0000
commit8eb3d653da176d4bd4b966065965001d18e37e90 (patch)
treef63fa5c5774f91b3bc1ff6b9852257879cb0fbaa /src
parent98744c5ff05ad5bf3eec331e263f9306de42e765 (diff)
downloadopenttd-8eb3d653da176d4bd4b966065965001d18e37e90.tar.xz
(svn r21090) -Codechange: Rename VehicleCache to NewGRFCache.
Diffstat (limited to 'src')
-rw-r--r--src/newgrf_engine.cpp32
-rw-r--r--src/openttd.cpp10
-rw-r--r--src/vehicle_base.h17
3 files changed, 30 insertions, 29 deletions
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index f2a70be4d..453856ab2 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -512,21 +512,21 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
return GetEngineGRFID(v->engine_type);
case 0x40: // Get length of consist
- if (!HasBit(v->vcache.cache_valid, 0)) {
- v->vcache.cached_var40 = PositionHelper(v, false);
- SetBit(v->vcache.cache_valid, 0);
+ if (!HasBit(v->grf_cache.cache_valid, 0)) {
+ v->grf_cache.position_consist_length = PositionHelper(v, false);
+ SetBit(v->grf_cache.cache_valid, 0);
}
- return v->vcache.cached_var40;
+ return v->grf_cache.position_consist_length;
case 0x41: // Get length of same consecutive wagons
- if (!HasBit(v->vcache.cache_valid, 1)) {
- v->vcache.cached_var41 = PositionHelper(v, true);
- SetBit(v->vcache.cache_valid, 1);
+ if (!HasBit(v->grf_cache.cache_valid, 1)) {
+ v->grf_cache.position_same_id_length = PositionHelper(v, true);
+ SetBit(v->grf_cache.cache_valid, 1);
}
- return v->vcache.cached_var41;
+ return v->grf_cache.position_same_id_length;
case 0x42: // Consist cargo information
- if (!HasBit(v->vcache.cache_valid, 2)) {
+ if (!HasBit(v->grf_cache.cache_valid, 2)) {
const Vehicle *u;
byte cargo_classes = 0;
uint8 common_cargos[NUM_CARGO];
@@ -576,17 +576,17 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
}
uint8 common_bitnum = (common_cargo_type == CT_INVALID ? 0xFF : CargoSpec::Get(common_cargo_type)->bitnum);
- v->vcache.cached_var42 = cargo_classes | (common_bitnum << 8) | (common_subtype << 16) | (user_def_data << 24);
- SetBit(v->vcache.cache_valid, 2);
+ v->grf_cache.consist_cargo_information = cargo_classes | (common_bitnum << 8) | (common_subtype << 16) | (user_def_data << 24);
+ SetBit(v->grf_cache.cache_valid, 2);
}
- return v->vcache.cached_var42;
+ return v->grf_cache.consist_cargo_information;
case 0x43: // Company information
- if (!HasBit(v->vcache.cache_valid, 3)) {
- v->vcache.cached_var43 = v->owner | (Company::IsHumanID(v->owner) ? 0 : 0x10000) | (LiveryHelper(v->engine_type, v) << 24);
- SetBit(v->vcache.cache_valid, 3);
+ if (!HasBit(v->grf_cache.cache_valid, 3)) {
+ v->grf_cache.company_information = v->owner | (Company::IsHumanID(v->owner) ? 0 : 0x10000) | (LiveryHelper(v->engine_type, v) << 24);
+ SetBit(v->grf_cache.cache_valid, 3);
}
- return v->vcache.cached_var43;
+ return v->grf_cache.company_information;
case 0x44: // Aircraft information
if (v->type != VEH_AIRCRAFT) return UINT_MAX;
diff --git a/src/openttd.cpp b/src/openttd.cpp
index e4f85a302..f1d7aebba 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -1133,7 +1133,7 @@ static void CheckCaches()
uint length = 0;
for (const Vehicle *u = v; u != NULL; u = u->Next()) length++;
- VehicleCache *veh_cache = CallocT<VehicleCache>(length);
+ NewGRFCache *grf_cache = CallocT<NewGRFCache>(length);
AccelerationCache *acc_cache = CallocT<AccelerationCache>(length);
TrainCache *tra_cache = CallocT<TrainCache>(length);
RoadVehicleCache *roa_cache = CallocT<RoadVehicleCache>(length);
@@ -1141,7 +1141,7 @@ static void CheckCaches()
length = 0;
for (const Vehicle *u = v; u != NULL; u = u->Next()) {
- veh_cache[length] = u->vcache;
+ grf_cache[length] = u->grf_cache;
switch (u->type) {
case VEH_TRAIN:
acc_cache[length] = Train::From(u)->acc_cache;
@@ -1168,8 +1168,8 @@ static void CheckCaches()
length = 0;
for (const Vehicle *u = v; u != NULL; u = u->Next()) {
- if (memcmp(&veh_cache[length], &u->vcache, sizeof(VehicleCache)) != 0) {
- DEBUG(desync, 2, "vehicle cache mismatch: type %i, vehicle %i, company %i, unit number %i, wagon %i", (int)v->type, v->index, (int)v->owner, v->unitnumber, length);
+ if (memcmp(&grf_cache[length], &u->grf_cache, sizeof(NewGRFCache)) != 0) {
+ DEBUG(desync, 2, "newgrf cache mismatch: type %i, vehicle %i, company %i, unit number %i, wagon %i", (int)v->type, v->index, (int)v->owner, v->unitnumber, length);
}
switch (u->type) {
case VEH_TRAIN:
@@ -1199,7 +1199,7 @@ static void CheckCaches()
length++;
}
- free(veh_cache);
+ free(grf_cache);
free(acc_cache);
free(tra_cache);
free(roa_cache);
diff --git a/src/vehicle_base.h b/src/vehicle_base.h
index 6bd99e10b..1c794cb09 100644
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -47,12 +47,13 @@ enum VehicleFlags {
};
/** Cached often queried (NewGRF) values */
-struct VehicleCache {
- uint8 cache_valid; ///< Whether the caches are valid
- uint32 cached_var40; ///< Cache for NewGRF var 40
- uint32 cached_var41; ///< Cache for NewGRF var 41
- uint32 cached_var42; ///< Cache for NewGRF var 42
- uint32 cached_var43; ///< Cache for NewGRF var 43
+struct NewGRFCache {
+ /* Values calculated when they are requested for the first time after invalidating the NewGRF cache. */
+ uint32 position_consist_length; ///< Cache for NewGRF var 40.
+ uint32 position_same_id_length; ///< Cache for NewGRF var 41.
+ uint32 consist_cargo_information; ///< Cache for NewGRF var 42.
+ uint32 company_information; ///< Cache for NewGRF var 43.
+ uint8 cache_valid; ///< Bitset that indicates which cache values are valid.
};
/** A vehicle pool for a little over 1 million vehicles. */
@@ -189,7 +190,7 @@ public:
byte subtype; ///< subtype (Filled with values from #EffectVehicles/#TrainSubTypes/#AircraftSubTypes)
- VehicleCache vcache; ///< Cache of often used calculated values
+ NewGRFCache grf_cache; ///< Cache of often used calculated NewGRF values
/** Create a new vehicle */
Vehicle(VehicleType type = VEH_INVALID);
@@ -308,7 +309,7 @@ public:
*/
FORCEINLINE void InvalidateNewGRFCache()
{
- this->vcache.cache_valid = 0;
+ this->grf_cache.cache_valid = 0;
}
/**