Skip to content

Commit

Permalink
Train, VehicleSpeedCurve: rename some variables
Browse files Browse the repository at this point in the history
  • Loading branch information
gfgit committed Sep 12, 2024
1 parent b188364 commit 8b25858
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
12 changes: 6 additions & 6 deletions server/src/train/train.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ void Train::setThrottleSpeed(const SpeedPoint& targetSpeed)

if(throttleSpeedPoint.tableIdx > lastSetSpeedPoint.tableIdx)
{
if(m_speedState == SpeedState::Accelerate)
if(m_speedState == SpeedState::Accelerating)
{
// Keep accelerating
}
Expand All @@ -381,7 +381,7 @@ void Train::setThrottleSpeed(const SpeedPoint& targetSpeed)

scheduleAccelerationFrom(currentSpeed,
nextTableIdx,
SpeedState::Accelerate);
SpeedState::Accelerating);
}
}
else if(throttleSpeedPoint.tableIdx < lastSetSpeedPoint.tableIdx)
Expand All @@ -395,7 +395,7 @@ void Train::setThrottleSpeed(const SpeedPoint& targetSpeed)
double currentSpeed = lastSetSpeedPoint.speedMetersPerSecond;
int prevTableIdx = lastSetSpeedPoint.tableIdx - 1;

if(m_speedState == SpeedState::Accelerate)
if(m_speedState == SpeedState::Accelerating)
{
// We start from above last set speed
double deltaSpeed = m_accelerationRate * double(millis.count()) / 1000.0;
Expand Down Expand Up @@ -451,14 +451,14 @@ void Train::updateSpeed()
if(m_speedState == SpeedState::Idle)
return;

if(m_speedState == SpeedState::Accelerate && !active)
if(m_speedState == SpeedState::Accelerating && !active)
return;

// TODO: needed?
m_speedTimer.cancel();

uint8_t newTableIdx = lastSetSpeedPoint.tableIdx;
if(m_speedState == SpeedState::Accelerate)
if(m_speedState == SpeedState::Accelerating)
{
newTableIdx++;
}
Expand All @@ -484,7 +484,7 @@ void Train::updateSpeed()

scheduleAccelerationFrom(currentSpeed,
nextTableIdx,
SpeedState::Accelerate);
SpeedState::Accelerating);
}
else if(throttleSpeedPoint.tableIdx < lastSetSpeedPoint.tableIdx)
{
Expand Down
2 changes: 1 addition & 1 deletion server/src/train/train.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Train : public IdObject
enum class SpeedState
{
Idle,
Accelerate,
Accelerating,
Braking,
};

Expand Down
20 changes: 10 additions & 10 deletions server/src/vehicle/rail/vehiclespeedcurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <algorithm>

VehicleSpeedCurve::VehicleSpeedCurve(const std::array<double, 126> &arr)
: mSpeedCurve(arr)
: m_speedCurve(arr)
{

}
Expand All @@ -36,17 +36,17 @@ double VehicleSpeedCurve::getSpeedForStep(uint8_t step) const
return 0;

// We do not store zero so index is step - 1
return mSpeedCurve.at(step - 1);
return m_speedCurve.at(step - 1);
}

uint8_t VehicleSpeedCurve::stepUpperBound(double speed) const
{
auto it = std::upper_bound(mSpeedCurve.begin(),
mSpeedCurve.end(),
auto it = std::upper_bound(m_speedCurve.begin(),
m_speedCurve.end(),
speed);
if(it != mSpeedCurve.end())
if(it != m_speedCurve.end())
{
int idx = std::distance(mSpeedCurve.begin(), it);
int idx = std::distance(m_speedCurve.begin(), it);

// We do not store zero so step is index + 1
int step = idx + 1;
Expand All @@ -57,12 +57,12 @@ uint8_t VehicleSpeedCurve::stepUpperBound(double speed) const

uint8_t VehicleSpeedCurve::stepLowerBound(double speed) const
{
auto it = std::lower_bound(mSpeedCurve.begin(),
mSpeedCurve.end(),
auto it = std::lower_bound(m_speedCurve.begin(),
m_speedCurve.end(),
speed);
if(it != mSpeedCurve.end())
if(it != m_speedCurve.end())
{
int idx = std::distance(mSpeedCurve.begin(), it);
int idx = std::distance(m_speedCurve.begin(), it);
// We do not store zero so step is index + 1
int step = idx + 1;
return step;
Expand Down
2 changes: 1 addition & 1 deletion server/src/vehicle/rail/vehiclespeedcurve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class VehicleSpeedCurve
uint8_t stepLowerBound(double speed) const;

private:
std::array<double, 126> mSpeedCurve;
std::array<double, 126> m_speedCurve;
};

#endif // TRAINTASTIC_SERVER_VEHICLE_RAIL_VEHICLESPEEDCURVE_HPP

0 comments on commit 8b25858

Please sign in to comment.