Fix handling of effect vehicles in CallVehicleTicks

Move effect vehicles into separate cache vector
Call effect vehicle ticks before other vehicle types

See #76
This commit is contained in:
Jonathan G Rennison
2019-02-15 18:14:15 +00:00
parent 884fa9a9d4
commit e28e2f638e
2 changed files with 17 additions and 5 deletions

View File

@@ -691,14 +691,14 @@ TransparencyOption EffectVehicle::GetTransparencyOption() const
return _effect_transparency_options[this->subtype]; return _effect_transparency_options[this->subtype];
} }
extern std::vector<Vehicle *> _tick_other_veh_cache; extern std::vector<EffectVehicle *> _tick_effect_veh_cache;
extern bool _tick_caches_valid; extern bool _tick_caches_valid;
void EffectVehicle::AddEffectVehicleToTickCache() void EffectVehicle::AddEffectVehicleToTickCache()
{ {
if (!_tick_caches_valid) return; if (!_tick_caches_valid) return;
_tick_other_veh_cache.erase(std::remove(_tick_other_veh_cache.begin(), _tick_other_veh_cache.end(), nullptr), _tick_other_veh_cache.end()); _tick_effect_veh_cache.erase(std::remove(_tick_effect_veh_cache.begin(), _tick_effect_veh_cache.end(), nullptr), _tick_effect_veh_cache.end());
_tick_other_veh_cache.insert(std::upper_bound(_tick_other_veh_cache.begin(), _tick_other_veh_cache.end(), this, [&](const Vehicle *a, const Vehicle *b) { _tick_effect_veh_cache.insert(std::upper_bound(_tick_effect_veh_cache.begin(), _tick_effect_veh_cache.end(), this, [&](const Vehicle *a, const Vehicle *b) {
return a->index < b->index; return a->index < b->index;
}), this); }), this);
} }
@@ -706,7 +706,7 @@ void EffectVehicle::AddEffectVehicleToTickCache()
void EffectVehicle::RemoveEffectVehicleFromTickCache() void EffectVehicle::RemoveEffectVehicleFromTickCache()
{ {
if (!_tick_caches_valid) return; if (!_tick_caches_valid) return;
for (auto &v : _tick_other_veh_cache) { for (auto &v : _tick_effect_veh_cache) {
if (v == this) v = nullptr; if (v == this) v = nullptr;
} }
} }

View File

@@ -1131,6 +1131,7 @@ std::vector<Train *> _tick_train_front_cache;
std::vector<RoadVehicle *> _tick_road_veh_front_cache; std::vector<RoadVehicle *> _tick_road_veh_front_cache;
std::vector<Aircraft *> _tick_aircraft_front_cache; std::vector<Aircraft *> _tick_aircraft_front_cache;
std::vector<Ship *> _tick_ship_cache; std::vector<Ship *> _tick_ship_cache;
std::vector<EffectVehicle *> _tick_effect_veh_cache;
std::vector<Vehicle *> _tick_other_veh_cache; std::vector<Vehicle *> _tick_other_veh_cache;
void ClearVehicleTickCaches() void ClearVehicleTickCaches()
@@ -1140,6 +1141,7 @@ void ClearVehicleTickCaches()
_tick_road_veh_front_cache.clear(); _tick_road_veh_front_cache.clear();
_tick_aircraft_front_cache.clear(); _tick_aircraft_front_cache.clear();
_tick_ship_cache.clear(); _tick_ship_cache.clear();
_tick_effect_veh_cache.clear();
_tick_other_veh_cache.clear(); _tick_other_veh_cache.clear();
} }
@@ -1172,6 +1174,10 @@ void RebuildVehicleTickCaches()
case VEH_SHIP: case VEH_SHIP:
_tick_ship_cache.push_back(Ship::From(v)); _tick_ship_cache.push_back(Ship::From(v));
break; break;
case VEH_EFFECT:
_tick_effect_veh_cache.push_back(EffectVehicle::From(v));
break;
} }
} }
_tick_caches_valid = true; _tick_caches_valid = true;
@@ -1230,6 +1236,13 @@ void CallVehicleTicks()
Vehicle *v = NULL; Vehicle *v = NULL;
SCOPE_INFO_FMT([&v], "CallVehicleTicks: %s", scope_dumper().VehicleInfo(v)); SCOPE_INFO_FMT([&v], "CallVehicleTicks: %s", scope_dumper().VehicleInfo(v));
{
for (EffectVehicle *u : _tick_effect_veh_cache) {
if (!u) continue;
v = u;
u->Tick();
}
}
{ {
PerformanceMeasurer framerate(PFE_GL_TRAINS); PerformanceMeasurer framerate(PFE_GL_TRAINS);
for (Train *t : _tick_train_too_heavy_cache) { for (Train *t : _tick_train_too_heavy_cache) {
@@ -1287,7 +1300,6 @@ void CallVehicleTicks()
} }
{ {
for (Vehicle *u : _tick_other_veh_cache) { for (Vehicle *u : _tick_other_veh_cache) {
if (!u) continue;
v = u; v = u;
u->Tick(); u->Tick();
} }