Reduce redundant calls to get current max speed for trains and RVs

Between ShowVisualEffect() and UpdateSpeed()
This commit is contained in:
Jonathan G Rennison
2022-06-01 20:05:45 +01:00
parent af270a63ad
commit 6d877b5e70
7 changed files with 28 additions and 21 deletions

View File

@@ -3865,9 +3865,10 @@ int ReversingDistanceTargetSpeed(const Train *v);
/**
* Draw visual effects (smoke and/or sparks) for a vehicle chain.
* @param max_speed The speed as limited by underground and orders, UINT_MAX if not already known
* @pre this->IsPrimaryVehicle()
*/
void Vehicle::ShowVisualEffect() const
void Vehicle::ShowVisualEffect(uint max_speed) const
{
assert(this->IsPrimaryVehicle());
bool sound = false;
@@ -3883,8 +3884,7 @@ void Vehicle::ShowVisualEffect() const
return;
}
/* Use the speed as limited by underground and orders. */
uint max_speed = this->GetCurrentMaxSpeed();
if (max_speed == UINT_MAX) max_speed = this->GetCurrentMaxSpeed();
if (this->type == VEH_TRAIN) {
const Train *t = Train::From(this);