diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 4976412f9d..490f3e9f42 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -44,6 +44,7 @@ #include "scope.h" #include "core/checksum_func.hpp" #include "debug_settings.h" +#include "train_speed_adaptation.h" #include "table/strings.h" #include "table/train_cmd.h" @@ -76,39 +77,7 @@ enum ChooseTrainTrackFlags { }; DECLARE_ENUM_AS_BIT_SET(ChooseTrainTrackFlags) -struct SignalSpeedKey -{ - TileIndex signal_tile; - Track signal_track; - Trackdir last_passing_train_dir; - - bool operator==(const SignalSpeedKey& other) const - { - return signal_tile == other.signal_tile && - signal_track == other.signal_track && - last_passing_train_dir == other.last_passing_train_dir; - } -}; - -struct SignalSpeedValue -{ - uint16 train_speed; - DateTicksScaled time_stamp; -}; - -struct SignalSpeedKeyHashFunc -{ - std::size_t operator() (const SignalSpeedKey &key) const - { - const std::size_t h1 = std::hash()(key.signal_tile); - const std::size_t h2 = std::hash()(key.last_passing_train_dir); - const std::size_t h3 = std::hash()(key.signal_track); - - return (h1 ^ h2) ^ h3; - } -}; - -static std::unordered_map _signal_speeds(1 << 16); +std::unordered_map _signal_speeds(1 << 16); static void TryLongReserveChooseTrainTrackFromReservationEnd(Train *v, bool no_reserve_vehicle_tile = false); static Track ChooseTrainTrack(Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, ChooseTrainTrackFlags flags, bool *p_got_reservation, ChooseTrainTrackLookAheadState lookahead_state = {}); diff --git a/src/train_speed_adaptation.h b/src/train_speed_adaptation.h new file mode 100644 index 0000000000..4f4c3e20b2 --- /dev/null +++ b/src/train_speed_adaptation.h @@ -0,0 +1,53 @@ +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . + */ + +/** @file train_speed_adaptation.h Train speed adaptation data structures. */ + +#ifndef TRAIN_SPEED_ADAPTATION_H +#define TRAIN_SPEED_ADAPTATION_H + +#include "date_type.h" +#include "track_type.h" +#include "tile_type.h" + +#include + +struct SignalSpeedKey +{ + TileIndex signal_tile; + Track signal_track; + Trackdir last_passing_train_dir; + + bool operator==(const SignalSpeedKey& other) const + { + return signal_tile == other.signal_tile && + signal_track == other.signal_track && + last_passing_train_dir == other.last_passing_train_dir; + } +}; + +struct SignalSpeedValue +{ + uint16 train_speed; + DateTicksScaled time_stamp; +}; + +struct SignalSpeedKeyHashFunc +{ + std::size_t operator() (const SignalSpeedKey &key) const + { + const std::size_t h1 = std::hash()(key.signal_tile); + const std::size_t h2 = std::hash()(key.last_passing_train_dir); + const std::size_t h3 = std::hash()(key.signal_track); + + return (h1 ^ h2) ^ h3; + } +}; + +extern std::unordered_map _signal_speeds; + +#endif /* TRAIN_SPEED_ADAPTATION_H */