summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-11-27 21:09:41 +0000
committerrubidium <rubidium@openttd.org>2010-11-27 21:09:41 +0000
commitb46e57d3640ea6b2b6f301ebaa454084565da301 (patch)
treef0bd2350642651ff6cba192c5ed3064f204b23e1 /src
parentdef0d7176773c2ff649c6a2ac0d5c686d2233e0c (diff)
downloadopenttd-b46e57d3640ea6b2b6f301ebaa454084565da301.tar.xz
(svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
Diffstat (limited to 'src')
-rw-r--r--src/newgrf_engine.cpp31
-rw-r--r--src/openttd.cpp3
-rw-r--r--src/vehicle_base.h1
3 files changed, 35 insertions, 0 deletions
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index 677c7becc..cd6023861 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -1222,3 +1222,34 @@ void GetVehicleResolver(ResolverObject *ro, uint index)
Vehicle *v = Vehicle::Get(index);
NewVehicleResolver(ro, v->engine_type, v);
}
+
+/**
+ * Fill the grf_cache of the given vehicle.
+ * @param v The vehicle to fill the cache for.
+ */
+void FillNewGRFVehicleCache(const Vehicle *v)
+{
+ ResolverObject ro;
+ memset(&ro, 0, sizeof(ro));
+ GetVehicleResolver(&ro, v->index);
+
+ /* These variables we have to check; these are the ones with a cache. */
+ static const int cache_entries[][2] = {
+ { 0x40, NCVV_POSITION_CONSIST_LENGTH },
+ { 0x41, NCVV_POSITION_SAME_ID_LENGTH },
+ { 0x42, NCVV_CONSIST_CARGO_INFORMATION },
+ { 0x43, NCVV_COMPANY_INFORMATION },
+ };
+ assert_compile(NCVV_END == lengthof(cache_entries));
+
+ /* Resolve all the variables, so their caches are set. */
+ for (size_t i = 0; i < lengthof(cache_entries); i++) {
+ /* Only resolve when the cache isn't valid. */
+ if (HasBit(v->grf_cache.cache_valid, cache_entries[i][1])) continue;
+ bool stub;
+ ro.GetVariable(&ro, cache_entries[i][0], 0, &stub);
+ }
+
+ /* Make sure really all bits are set. */
+ assert(v->grf_cache.cache_valid == (1 << NCVV_END) - 1);
+}
diff --git a/src/openttd.cpp b/src/openttd.cpp
index ef7e356ea..c74709b43 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -1132,6 +1132,7 @@ static void CheckCaches()
Vehicle *v;
FOR_ALL_VEHICLES(v) {
+ extern void FillNewGRFVehicleCache(const Vehicle *v);
if (v != v->First() || v->vehstatus & VS_CRASHED || !v->IsPrimaryVehicle()) continue;
uint length = 0;
@@ -1145,6 +1146,7 @@ static void CheckCaches()
length = 0;
for (const Vehicle *u = v; u != NULL; u = u->Next()) {
+ FillNewGRFVehicleCache(u);
grf_cache[length] = u->grf_cache;
veh_cache[length] = u->vcache;
switch (u->type) {
@@ -1171,6 +1173,7 @@ static void CheckCaches()
length = 0;
for (const Vehicle *u = v; u != NULL; u = u->Next()) {
+ FillNewGRFVehicleCache(u);
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);
}
diff --git a/src/vehicle_base.h b/src/vehicle_base.h
index 149b3d6a3..20cd9ee21 100644
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -52,6 +52,7 @@ enum NewGRFCacheValidValues {
NCVV_POSITION_SAME_ID_LENGTH = 1, ///< This bit will be set if the NewGRF var 41 currently stored is valid.
NCVV_CONSIST_CARGO_INFORMATION = 2, ///< This bit will be set if the NewGRF var 42 currently stored is valid.
NCVV_COMPANY_INFORMATION = 3, ///< This bit will be set if the NewGRF var 43 currently stored is valid.
+ NCVV_END, ///< End of the bits.
};
/** Cached often queried (NewGRF) values */