summaryrefslogtreecommitdiff
path: root/src/newgrf_engine.cpp
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/newgrf_engine.cpp
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/newgrf_engine.cpp')
-rw-r--r--src/newgrf_engine.cpp31
1 files changed, 31 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);
+}