Train speed adaptation: Move IsOutOfDate to be a method

pull/615/head
Jonathan G Rennison 6 months ago
parent 85e1146fab
commit c9a205c707

@ -114,12 +114,6 @@ static DateTicksScaled GetSpeedRestrictionTimeout(const Train *t)
return _scaled_date_ticks + ticks;
}
/** Checks if the timeout of the specified signal speed restriction value has passed */
static bool IsOutOfDate(const SignalSpeedValue& value)
{
return _scaled_date_ticks > value.time_stamp;
}
/** Removes all speed restrictions from all signals */
void ClearAllSignalSpeedRestrictions()
{
@ -137,7 +131,7 @@ void AdjustAllSignalSpeedRestrictionTickValues(DateTicksScaled delta)
void ClearOutOfDateSignalSpeedRestrictions()
{
for (auto key_value_pair = _signal_speeds.begin(); key_value_pair != _signal_speeds.end(); ) {
if (IsOutOfDate(key_value_pair->second)) {
if (key_value_pair->second.IsOutOfDate()) {
key_value_pair = _signal_speeds.erase(key_value_pair);
} else {
++key_value_pair;
@ -7582,7 +7576,7 @@ void ApplySignalTrainAdaptationSpeed(Train *v, TileIndex tile, uint16 track)
const auto found_speed_restriction = _signal_speeds.find(speed_key);
if (found_speed_restriction != _signal_speeds.end()) {
if (IsOutOfDate(found_speed_restriction->second)) {
if (found_speed_restriction->second.IsOutOfDate()) {
_signal_speeds.erase(found_speed_restriction);
v->signal_speed_restriction = 0;
} else {

@ -11,13 +11,13 @@
#define TRAIN_SPEED_ADAPTATION_H
#include "date_type.h"
#include "date_func.h"
#include "track_type.h"
#include "tile_type.h"
#include <unordered_map>
struct SignalSpeedKey
{
struct SignalSpeedKey {
TileIndex signal_tile;
uint16 signal_track;
Trackdir last_passing_train_dir;
@ -30,14 +30,18 @@ struct SignalSpeedKey
}
};
struct SignalSpeedValue
{
struct SignalSpeedValue {
uint16 train_speed;
DateTicksScaled time_stamp;
/** Checks if the timeout has passed */
bool IsOutOfDate() const
{
return _scaled_date_ticks > this->time_stamp;
}
};
struct SignalSpeedKeyHashFunc
{
struct SignalSpeedKeyHashFunc {
std::size_t operator() (const SignalSpeedKey &key) const
{
const std::size_t h1 = std::hash<TileIndex>()(key.signal_tile);

Loading…
Cancel
Save