Validate vehicle tick caches in CheckCaches

This commit is contained in:
Jonathan G Rennison
2019-05-02 19:20:47 +01:00
parent a73ec8d386
commit 10d0f79e83
2 changed files with 32 additions and 0 deletions

View File

@@ -1494,6 +1494,9 @@ void CheckCaches(bool force_check)
FOR_ALL_ORDER_LISTS(order_list) { FOR_ALL_ORDER_LISTS(order_list) {
order_list->DebugCheckSanity(); order_list->DebugCheckSanity();
} }
extern void ValidateVehicleTickCaches();
ValidateVehicleTickCaches();
} }
/** /**

View File

@@ -1193,6 +1193,35 @@ void RebuildVehicleTickCaches()
_tick_caches_valid = true; _tick_caches_valid = true;
} }
void ValidateVehicleTickCaches()
{
if (!_tick_caches_valid) return;
std::vector<Train *> saved_tick_train_too_heavy_cache = std::move(_tick_train_too_heavy_cache);
std::sort(saved_tick_train_too_heavy_cache.begin(), saved_tick_train_too_heavy_cache.end(), [&](const Vehicle *a, const Vehicle *b) {
return a->index < b->index;
});
saved_tick_train_too_heavy_cache.erase(std::unique(saved_tick_train_too_heavy_cache.begin(), saved_tick_train_too_heavy_cache.end()), saved_tick_train_too_heavy_cache.end());
std::vector<Train *> saved_tick_train_front_cache = std::move(_tick_train_front_cache);
std::vector<RoadVehicle *> saved_tick_road_veh_front_cache = std::move(_tick_road_veh_front_cache);
std::vector<Aircraft *> saved_tick_aircraft_front_cache = std::move(_tick_aircraft_front_cache);
std::vector<Ship *> saved_tick_ship_cache = std::move(_tick_ship_cache);
std::vector<EffectVehicle *> saved_tick_effect_veh_cache = std::move(_tick_effect_veh_cache);
std::vector<Vehicle *> saved_tick_other_veh_cache = std::move(_tick_other_veh_cache);
saved_tick_effect_veh_cache.erase(std::remove(saved_tick_effect_veh_cache.begin(), saved_tick_effect_veh_cache.end(), nullptr), saved_tick_effect_veh_cache.end());
saved_tick_other_veh_cache.erase(std::remove(saved_tick_other_veh_cache.begin(), saved_tick_other_veh_cache.end(), nullptr), saved_tick_other_veh_cache.end());
RebuildVehicleTickCaches();
assert(saved_tick_train_too_heavy_cache == _tick_train_too_heavy_cache);
assert(saved_tick_train_front_cache == saved_tick_train_front_cache);
assert(saved_tick_road_veh_front_cache == _tick_road_veh_front_cache);
assert(saved_tick_aircraft_front_cache == _tick_aircraft_front_cache);
assert(saved_tick_ship_cache == _tick_ship_cache);
assert(saved_tick_effect_veh_cache == _tick_effect_veh_cache);
assert(saved_tick_other_veh_cache == _tick_other_veh_cache);
}
void VehicleTickCargoAging(Vehicle *v) void VehicleTickCargoAging(Vehicle *v)
{ {
if (v->vcache.cached_cargo_age_period != 0) { if (v->vcache.cached_cargo_age_period != 0) {