Merge branch 'development' into feature/no_multiplayer_grf_limit
[openttd-joker.git] / src / bridge_signal_map.h
blob26474a2b9414e5d5c9e7e20839d3aec063fb88c5
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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 <http://www.gnu.org/licenses/>.
8 */
10 /** @file bridge_signal_map.h Map accessor functions for bridge signal simulation. */
12 #ifndef BRIDGE_SIGNAL_MAP_H
13 #define BRIDGE_SIGNAL_MAP_H
15 #include "tile_type.h"
16 #include "map_func.h"
17 #include "signal_type.h"
18 #include "core/bitmath_func.hpp"
20 #include <vector>
21 #include <unordered_map>
23 struct LongBridgeSignalStorage {
24 std::vector<uint64> signal_red_bits;
27 extern std::unordered_map<TileIndex, LongBridgeSignalStorage> _long_bridge_signal_sim_map;
29 SignalState GetBridgeEntranceSimulatedSignalStateExtended(TileIndex t, uint16 signal);
31 static inline SignalState GetBridgeEntranceSimulatedSignalState(TileIndex t, uint16 signal)
33 if (signal < 15) {
34 return GB(_m[t].m2, signal, 1) ? SIGNAL_STATE_RED : SIGNAL_STATE_GREEN;
35 } else {
36 return GetBridgeEntranceSimulatedSignalStateExtended(t, signal);
40 void SetBridgeEntranceSimulatedSignalStateExtended(TileIndex t, uint16 signal, SignalState state);
42 static inline void SetBridgeEntranceSimulatedSignalState(TileIndex t, uint16 signal, SignalState state)
44 if (signal < 15) {
45 SB(_m[t].m2, signal, 1, (state == SIGNAL_STATE_RED) ? 1 : 0);
46 } else {
47 SetBridgeEntranceSimulatedSignalStateExtended(t, signal, state);
51 void SetAllBridgeEntranceSimulatedSignalsGreenExtended(TileIndex t);
53 static inline void SetAllBridgeEntranceSimulatedSignalsGreen(TileIndex t)
55 if (_m[t].m2 & 0x8000) {
56 SetAllBridgeEntranceSimulatedSignalsGreenExtended(t);
57 } else {
58 _m[t].m2 = 0;
62 void ClearBridgeEntranceSimulatedSignalsExtended(TileIndex t);
64 static inline void ClearBridgeEntranceSimulatedSignals(TileIndex t)
66 if (_m[t].m2 & 0x8000) {
67 ClearBridgeEntranceSimulatedSignalsExtended(t);
68 } else {
69 _m[t].m2 = 0;
73 void ClearBridgeSimulatedSignalMapping();
75 #endif /* BRIDGE_SIGNAL_MAP_H */