From 89bc7b2a347b1ab98519f5d012f416133965ecbb Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Mon, 23 Nov 2015 19:17:49 +0000 Subject: [PATCH] Check caches at desync level 1, every 500 ticks. Also check aircraft cache. --- src/openttd.cpp | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/openttd.cpp b/src/openttd.cpp index ec01bd7ce8..25ec9e6048 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -1140,7 +1140,9 @@ static void CheckCaches() { /* Return here so it is easy to add checks that are run * always to aid testing of caches. */ - if (_debug_desync_level <= 1) return; + if (_debug_desync_level < 1) return; + + if (_debug_desync_level == 1 && _tick_counter % 500 != 0) return; /* Check the town caches. */ std::vector old_town_caches; @@ -1155,7 +1157,7 @@ static void CheckCaches() uint i = 0; for (Town *t : Town::Iterate()) { if (MemCmpT(old_town_caches.data() + i, &t->cache) != 0) { - DEBUG(desync, 2, "town cache mismatch: town %i", (int)t->index); + DEBUG(desync, 0, "town cache mismatch: town %i", (int)t->index); } i++; } @@ -1170,7 +1172,7 @@ static void CheckCaches() i = 0; for (const Company *c : Company::Iterate()) { if (MemCmpT(old_infrastructure.data() + i, &c->infrastructure) != 0) { - DEBUG(desync, 2, "infrastructure cache mismatch: company %i", (int)c->index); + DEBUG(desync, 0, "infrastructure cache mismatch: company %i", (int)c->index); } i++; } @@ -1194,6 +1196,7 @@ static void CheckCaches() NewGRFCache *grf_cache = CallocT(length); VehicleCache *veh_cache = CallocT(length); GroundVehicleCache *gro_cache = CallocT(length); + AircraftCache *air_cache = CallocT(length); TrainCache *tra_cache = CallocT(length); Vehicle **veh_old = CallocT(length); @@ -1214,6 +1217,11 @@ static void CheckCaches() veh_old[length] = CallocT(1); MemCpyT((RoadVehicle *) veh_old[length], RoadVehicle::From(u)); break; + case VEH_AIRCRAFT: + air_cache[length] = Aircraft::From(u)->acache; + veh_old[length] = CallocT(1); + MemCpyT((Aircraft *) veh_old[length], Aircraft::From(u)); + break; default: veh_old[length] = CallocT(1); MemCpyT(veh_old[length], u); @@ -1234,44 +1242,49 @@ static void CheckCaches() for (const Vehicle *u = v; u != nullptr; 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); + DEBUG(desync, 0, "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); } 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); + DEBUG(desync, 0, "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 (veh_old[length]->acceleration != u->acceleration) { - DEBUG(desync, 2, "acceleration mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length); + DEBUG(desync, 0, "acceleration mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length); } if (veh_old[length]->breakdown_chance != u->breakdown_chance) { - DEBUG(desync, 2, "breakdown_chance mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length); + DEBUG(desync, 0, "breakdown_chance mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length); } if (veh_old[length]->breakdowns_since_last_service != u->breakdowns_since_last_service) { - DEBUG(desync, 2, "breakdowns_since_last_service mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length); + DEBUG(desync, 0, "breakdowns_since_last_service mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length); } if (veh_old[length]->vehicle_flags != u->vehicle_flags) { - DEBUG(desync, 2, "vehicle_flags mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length); + DEBUG(desync, 0, "vehicle_flags mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length); } switch (u->type) { case VEH_TRAIN: if (memcmp(&gro_cache[length], &Train::From(u)->gcache, sizeof(GroundVehicleCache)) != 0) { - DEBUG(desync, 2, "train ground vehicle cache mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length); + DEBUG(desync, 0, "train ground vehicle cache mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length); } if (memcmp(&tra_cache[length], &Train::From(u)->tcache, sizeof(TrainCache)) != 0) { - DEBUG(desync, 2, "train cache mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length); + DEBUG(desync, 0, "train cache mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length); } if (Train::From(veh_old[length])->railtype != Train::From(u)->railtype) { - DEBUG(desync, 2, "railtype mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length); + DEBUG(desync, 0, "railtype mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length); } if (Train::From(veh_old[length])->compatible_railtypes != Train::From(u)->compatible_railtypes) { - DEBUG(desync, 2, "compatible_railtypes mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length); + DEBUG(desync, 0, "compatible_railtypes mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length); } if (Train::From(veh_old[length])->flags != Train::From(u)->flags) { - DEBUG(desync, 2, "flags mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length); + DEBUG(desync, 0, "flags mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length); } break; case VEH_ROAD: if (memcmp(&gro_cache[length], &RoadVehicle::From(u)->gcache, sizeof(GroundVehicleCache)) != 0) { - DEBUG(desync, 2, "road vehicle ground vehicle cache mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length); + DEBUG(desync, 0, "road vehicle ground vehicle cache mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length); + } + break; + case VEH_AIRCRAFT: + if (memcmp(&air_cache[length], &Aircraft::From(u)->acache, sizeof(AircraftCache)) != 0) { + DEBUG(desync, 0, "Aircraft vehicle cache mismatch: vehicle %i, company %i, unit number %i, wagon %i", v->index, (int)v->owner, v->unitnumber, length); } break; default: