From b46e57d3640ea6b2b6f301ebaa454084565da301 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sat, 27 Nov 2010 21:09:41 +0000 Subject: (svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset --- src/newgrf_engine.cpp | 31 +++++++++++++++++++++++++++++++ src/openttd.cpp | 3 +++ src/vehicle_base.h | 1 + 3 files changed, 35 insertions(+) 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 */ -- cgit v1.2.3-54-g00ecf