mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-08 01:10:28 +00:00
(svn r21338) -Fix [FS#4272]: bogus cache mismatch warnings with desync debugging because some cache was invalidated but never reset
This commit is contained in:
parent
814e780527
commit
aeae689dc4
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user