Check vehicle tile hash in CheckCaches

This commit is contained in:
Jonathan G Rennison 2019-05-27 15:58:30 +01:00
parent 31ad8bdd07
commit 9b87610cd6
2 changed files with 14 additions and 0 deletions

View File

@ -1423,6 +1423,11 @@ void CheckCaches(bool force_check, std::function<void(const char *)> log)
Vehicle *v;
FOR_ALL_VEHICLES(v) {
extern bool ValidateVehicleTileHash(const Vehicle *v);
if (!ValidateVehicleTileHash(v)) {
CCLOG("vehicle tile hash mismatch: type %i, vehicle %i, company %i, unit number %i", (int)v->type, v->index, (int)v->owner, v->unitnumber);
}
extern void FillNewGRFVehicleCache(const Vehicle *v);
if (v != v->First() || v->vehstatus & VS_CRASHED || !v->IsPrimaryVehicle()) continue;

View File

@ -762,6 +762,15 @@ static void UpdateVehicleTileHash(Vehicle *v, bool remove)
v->hash_tile_current = new_hash;
}
bool ValidateVehicleTileHash(const Vehicle *v)
{
if (v->type == VEH_TRAIN && Train::From(v)->IsVirtual()) return v->hash_tile_current == nullptr;
int x = GB(TileX(v->tile), HASH_RES, HASH_BITS);
int y = GB(TileY(v->tile), HASH_RES, HASH_BITS) << HASH_BITS;
return v->hash_tile_current == &_vehicle_tile_hash[(x + y) & TOTAL_HASH_MASK];
}
static Vehicle *_vehicle_viewport_hash[1 << (GEN_HASHX_BITS + GEN_HASHY_BITS)];
static void UpdateVehicleViewportHash(Vehicle *v, int x, int y)