Remove disaster vehicles from tick cache immediately on deletion

This commit is contained in:
Jonathan G Rennison
2019-03-27 00:36:06 +00:00
parent 7395705775
commit 99b79c26c6
2 changed files with 11 additions and 0 deletions

View File

@@ -1022,6 +1022,8 @@ Vehicle::~Vehicle()
if (this->type != VEH_EFFECT) InvalidateVehicleTickCaches();
if (this->type == VEH_DISASTER) RemoveFromOtherVehicleTickCache(this);
if (this->breakdowns_since_last_service) _vehicles_to_pay_repair.erase(this);
if (this->type < VEH_BEGIN || this->type >= VEH_COMPANY_END) {
@@ -1145,6 +1147,13 @@ void ClearVehicleTickCaches()
_tick_other_veh_cache.clear();
}
void RemoveFromOtherVehicleTickCache(const Vehicle *v)
{
for (auto &u : _tick_other_veh_cache) {
if (u == v) u = nullptr;
}
}
void RebuildVehicleTickCaches()
{
Vehicle *v = NULL;
@@ -1300,6 +1309,7 @@ void CallVehicleTicks()
}
{
for (Vehicle *u : _tick_other_veh_cache) {
if (!u) continue;
v = u;
u->Tick();
}

View File

@@ -1299,5 +1299,6 @@ inline void InvalidateVehicleTickCaches()
}
void ClearVehicleTickCaches();
void RemoveFromOtherVehicleTickCache(const Vehicle *v);
#endif /* VEHICLE_BASE_H */