(svn r19336) -Codechange: Move rail speed limit to its own function.

This commit is contained in:
terkhen 2010-03-06 12:27:23 +00:00
parent d4b748e27e
commit b5714c3597
2 changed files with 26 additions and 8 deletions

View File

@ -70,6 +70,7 @@ struct AccelerationCache {
uint32 cached_power; ///< total power of the consist.
uint32 cached_air_drag; ///< Air drag coefficient of the vehicle
uint16 cached_axle_resistance; ///< Resistance caused by the axles of the vehicle
uint16 cached_max_track_speed; ///< Max consist speed limited by track type
};
/** Variables that are cached to improve performance and such */
@ -86,7 +87,6 @@ struct TrainCache : public AccelerationCache {
/* cached max. speed / acceleration data */
uint16 cached_max_speed; ///< max speed of the consist. (minimum of the max speed of all vehicles in the consist)
uint16 cached_max_rail_speed; ///< max consist speed limited by rail type
int cached_max_curve_speed; ///< max consist speed limited by curves
/**
@ -512,6 +512,24 @@ protected: // These functions should not be called outside acceleration code.
{
return 20 * _settings_game.vehicle.train_slope_steepness; // 1% slope * slope steepness
}
/**
* Gets the maximum speed of the vehicle, ignoring the limitations of the kind of track the vehicle is on.
* @return Maximum speed of the vehicle.
*/
FORCEINLINE uint16 GetInitialMaxSpeed() const
{
return this->tcache.cached_max_speed;
}
/**
* Gets the maximum speed allowed by the track for this vehicle.
* @return Maximum speed allowed.
*/
FORCEINLINE uint16 GetMaxTrackSpeed() const
{
return GetRailTypeInfo(GetRailType(this->tile))->max_speed;
}
};
#define FOR_ALL_TRAINS(var) FOR_ALL_VEHICLES_OF_TYPE(Train, var)

View File

@ -99,7 +99,7 @@ void Train::PowerChanged()
uint32 total_power = 0;
uint32 max_te = 0;
uint32 number_of_parts = 0;
uint16 max_rail_speed = this->tcache.cached_max_speed;
uint16 max_track_speed = this->GetInitialMaxSpeed();
for (const Train *u = this; u != NULL; u = u->Next()) {
uint32 current_power = u->GetPower();
@ -110,9 +110,9 @@ void Train::PowerChanged()
total_power += u->GetPoweredPartPower(this);
number_of_parts++;
/* Get minimum max speed for rail */
uint16 rail_speed = GetRailTypeInfo(GetRailType(u->tile))->max_speed;
if (rail_speed > 0) max_rail_speed = min(max_rail_speed, rail_speed);
/* Get minimum max speed for this track */
uint16 track_speed = u->GetMaxTrackSpeed();
if (track_speed > 0) max_track_speed = min(max_track_speed, track_speed);
}
this->tcache.cached_axle_resistance = 60 * number_of_parts;
@ -130,7 +130,7 @@ void Train::PowerChanged()
SetWindowWidgetDirty(WC_VEHICLE_VIEW, this->index, VVW_WIDGET_START_STOP_VEH);
}
this->tcache.cached_max_rail_speed = max_rail_speed;
this->tcache.cached_max_track_speed = max_track_speed;
}
@ -498,7 +498,7 @@ int Train::GetCurrentMaxSpeed() const
}
}
return min(max_speed, this->tcache.cached_max_rail_speed);
return min(max_speed, this->tcache.cached_max_track_speed);
}
/**
@ -564,7 +564,7 @@ void Train::UpdateAcceleration()
{
assert(this->IsFrontEngine());
this->max_speed = this->tcache.cached_max_rail_speed;
this->max_speed = this->tcache.cached_max_track_speed;
uint power = this->tcache.cached_power;
uint weight = this->tcache.cached_weight;