* Check the validity of some of the caches. * Especially in the sense of desyncs between * the cached value and what the value would * be when calculated from the 'base' data. */
| 34 | * be when calculated from the 'base' data. |
| 35 | */ |
| 36 | void CheckCaches() |
| 37 | { |
| 38 | /* Return here so it is easy to add checks that are run |
| 39 | * always to aid testing of caches. */ |
| 40 | if (_debug_desync_level <= 1) return; |
| 41 | |
| 42 | /* Check the town caches. */ |
| 43 | std::vector<TownCache> old_town_caches; |
| 44 | for (const Town *t : Town::Iterate()) { |
| 45 | old_town_caches.push_back(t->cache); |
| 46 | } |
| 47 | |
| 48 | RebuildTownCaches(); |
| 49 | RebuildSubsidisedSourceAndDestinationCache(); |
| 50 | |
| 51 | uint i = 0; |
| 52 | for (Town *t : Town::Iterate()) { |
| 53 | if (old_town_caches[i] != t->cache) { |
| 54 | Debug(desync, 2, "warning: town cache mismatch: town {}", t->index); |
| 55 | } |
| 56 | i++; |
| 57 | } |
| 58 | |
| 59 | /* Check company infrastructure cache. */ |
| 60 | std::vector<CompanyInfrastructure> old_infrastructure; |
| 61 | for (const Company *c : Company::Iterate()) old_infrastructure.push_back(c->infrastructure); |
| 62 | |
| 63 | AfterLoadCompanyStats(); |
| 64 | |
| 65 | i = 0; |
| 66 | for (const Company *c : Company::Iterate()) { |
| 67 | if (old_infrastructure[i] != c->infrastructure) { |
| 68 | Debug(desync, 2, "warning: infrastructure cache mismatch: company {}", c->index); |
| 69 | } |
| 70 | i++; |
| 71 | } |
| 72 | |
| 73 | /* Strict checking of the road stop cache entries */ |
| 74 | for (const RoadStop *rs : RoadStop::Iterate()) { |
| 75 | if (IsBayRoadStopTile(rs->xy)) continue; |
| 76 | |
| 77 | rs->GetEntry(DIAGDIR_NE).CheckIntegrity(rs); |
| 78 | rs->GetEntry(DIAGDIR_NW).CheckIntegrity(rs); |
| 79 | } |
| 80 | |
| 81 | std::vector<NewGRFCache> grf_cache; |
| 82 | std::vector<VehicleCache> veh_cache; |
| 83 | std::vector<GroundVehicleCache> gro_cache; |
| 84 | std::vector<TrainCache> tra_cache; |
| 85 | |
| 86 | for (Vehicle *v : Vehicle::Iterate()) { |
| 87 | if (v != v->First() || v->vehstatus.Test(VehState::Crashed) || !v->IsPrimaryVehicle()) continue; |
| 88 | |
| 89 | for (const Vehicle *u = v; u != nullptr; u = u->Next()) { |
| 90 | FillNewGRFVehicleCache(u); |
| 91 | grf_cache.emplace_back(u->grf_cache); |
| 92 | veh_cache.emplace_back(u->vcache); |
| 93 | switch (u->type) { |
no test coverage detected