OpenTTD Source: src/track_func.h Source File

OpenTTD Source 14.0-beta1

track_func.h
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
7
10 #ifndef TRACK_FUNC_H
11 #define TRACK_FUNC_H
12
13 #include "core/bitmath_func.hpp"
14 #include "track_type.h"
15 #include "direction_func.h"
16 #include "slope_func.h"
17
18 using SetTrackBitIterator = SetBitIterator<Track, TrackBits>;
19 using SetTrackdirBitIterator = SetBitIterator<Trackdir, TrackdirBits>;
20
28 inline bool IsValidTrack(Track track)
29 {
30 return track < TRACK_END;
31 }
32
40 inline bool IsValidTrackdirForRoadVehicle(Trackdir trackdir)
41 {
42 return trackdir < TRACKDIR_END;
43 }
44
52 inline bool IsValidTrackdir(Trackdir trackdir)
53 {
54 return trackdir != INVALID_TRACKDIR && ((1 << trackdir & TRACKDIR_BIT_MASK) != TRACKDIR_BIT_NONE);
55 }
56
66 inline Track AxisToTrack(Axis a)
67 {
68 assert(IsValidAxis(a));
69 return (Track)a;
70 }
71
77 inline TrackBits TrackToTrackBits(Track track)
78 {
79 assert(IsValidTrack(track));
80 return (TrackBits)(1 << track);
81 }
82
88 inline TrackBits AxisToTrackBits(Axis a)
89 {
90 return TrackToTrackBits(AxisToTrack(a));
91 }
92
99 inline TrackBits CornerToTrackBits(Corner corner)
100 {
101 extern const TrackBits _corner_to_trackbits[];
102 assert(IsValidCorner(corner));
103 return _corner_to_trackbits[corner];
104 }
105
111 inline TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir)
112 {
113 assert(IsValidTrackdir(trackdir));
114 return (TrackdirBits)(1 << trackdir);
115 }
116
131 inline Track RemoveFirstTrack(TrackBits *tracks)
132 {
133 if (*tracks != TRACK_BIT_NONE && *tracks != INVALID_TRACK_BIT) {
134 assert((*tracks & ~TRACK_BIT_MASK) == TRACK_BIT_NONE);
135 Track first = (Track)FindFirstBit(*tracks);
136 ClrBit(*tracks, first);
137 return first;
138 }
139 return INVALID_TRACK;
140 }
141
156 inline Trackdir RemoveFirstTrackdir(TrackdirBits *trackdirs)
157 {
158 if (*trackdirs != TRACKDIR_BIT_NONE && *trackdirs != INVALID_TRACKDIR_BIT) {
159 assert((*trackdirs & ~TRACKDIR_BIT_MASK) == TRACKDIR_BIT_NONE);
160 Trackdir first = (Trackdir)FindFirstBit(*trackdirs);
161 ClrBit(*trackdirs, first);
162 return first;
163 }
164 return INVALID_TRACKDIR;
165 }
166
177 inline Track FindFirstTrack(TrackBits tracks)
178 {
179 return (tracks != TRACK_BIT_NONE && tracks != INVALID_TRACK_BIT) ? (Track)FindFirstBit(tracks) : INVALID_TRACK;
180 }
181
193 inline Track TrackBitsToTrack(TrackBits tracks)
194 {
195 assert(tracks == INVALID_TRACK_BIT || (tracks != TRACK_BIT_NONE && KillFirstBit(tracks & TRACK_BIT_MASK) == TRACK_BIT_NONE));
196 return tracks != INVALID_TRACK_BIT ? (Track)FindFirstBit(tracks & TRACK_BIT_MASK) : INVALID_TRACK;
197 }
198
211 inline Trackdir FindFirstTrackdir(TrackdirBits trackdirs)
212 {
213 assert((trackdirs & ~TRACKDIR_BIT_MASK) == TRACKDIR_BIT_NONE);
214 return (trackdirs != TRACKDIR_BIT_NONE) ? (Trackdir)FindFirstBit(trackdirs) : INVALID_TRACKDIR;
215 }
216
217 /*
218 * Functions describing logical relations between Tracks, TrackBits, Trackdirs
219 * TrackdirBits, Direction and DiagDirections.
220 */
221
231 inline Track TrackToOppositeTrack(Track t)
232 {
233 assert(IsValidTrack(t));
234 return (Track)(t ^ 1);
235 }
236
247 inline Trackdir ReverseTrackdir(Trackdir trackdir)
248 {
249 assert(IsValidTrackdirForRoadVehicle(trackdir));
250 return (Trackdir)(trackdir ^ 8);
251 }
252
262 inline Track TrackdirToTrack(Trackdir trackdir)
263 {
264 assert(IsValidTrackdir(trackdir));
265 return (Track)(trackdir & 0x7);
266 }
267
279 inline Trackdir TrackToTrackdir(Track track)
280 {
281 assert(IsValidTrack(track));
282 return (Trackdir)track;
283 }
284
294 inline TrackdirBits TrackToTrackdirBits(Track track)
295 {
296 Trackdir td = TrackToTrackdir(track);
297 return (TrackdirBits)(TrackdirToTrackdirBits(td) | TrackdirToTrackdirBits(ReverseTrackdir(td)));
298 }
299
308 inline TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
309 {
310 return (TrackBits)((bits | (bits >> 8)) & TRACK_BIT_MASK);
311 }
312
319 inline TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
320 {
321 return (TrackdirBits)(bits * 0x101);
322 }
323
329 inline bool HasTrack(TrackBits tracks, Track track)
330 {
331 assert(IsValidTrack(track));
332 return HasBit(tracks, track);
333 }
334
340 inline bool HasTrackdir(TrackdirBits trackdirs, Trackdir trackdir)
341 {
342 assert(IsValidTrackdir(trackdir));
343 return HasBit(trackdirs, trackdir);
344 }
345
352 inline TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
353 {
354 return (TrackdirBits)(ts & TRACKDIR_BIT_MASK);
355 }
356
363 inline TrackBits TrackStatusToTrackBits(TrackStatus ts)
364 {
365 return TrackdirBitsToTrackBits(TrackStatusToTrackdirBits(ts));
366 }
367
376 inline TrackdirBits TrackStatusToRedSignals(TrackStatus ts)
377 {
378 return (TrackdirBits)((ts >> 16) & TRACKDIR_BIT_MASK);
379 }
380
388 inline TrackStatus CombineTrackStatus(TrackdirBits trackdirbits, TrackdirBits red_signals)
389 {
390 return (TrackStatus)(trackdirbits | (red_signals << 16));
391 }
392
403 inline Trackdir NextTrackdir(Trackdir trackdir)
404 {
405 assert(IsValidTrackdir(trackdir));
406 extern const Trackdir _next_trackdir[TRACKDIR_END];
407 return _next_trackdir[trackdir];
408 }
409
420 inline TrackBits TrackCrossesTracks(Track track)
421 {
422 assert(IsValidTrack(track));
423 extern const TrackBits _track_crosses_tracks[TRACK_END];
424 return _track_crosses_tracks[track];
425 }
426
439 inline DiagDirection TrackdirToExitdir(Trackdir trackdir)
440 {
441 assert(IsValidTrackdirForRoadVehicle(trackdir));
442 extern const DiagDirection _trackdir_to_exitdir[TRACKDIR_END];
443 return _trackdir_to_exitdir[trackdir];
444 }
445
461 inline Trackdir TrackExitdirToTrackdir(Track track, DiagDirection diagdir)
462 {
463 assert(IsValidTrack(track));
464 assert(IsValidDiagDirection(diagdir));
465 extern const Trackdir _track_exitdir_to_trackdir[TRACK_END][DIAGDIR_END];
466 return _track_exitdir_to_trackdir[track][diagdir];
467 }
468
486 inline Trackdir TrackEnterdirToTrackdir(Track track, DiagDirection diagdir)
487 {
488 assert(IsValidTrack(track));
489 assert(IsValidDiagDirection(diagdir));
490 extern const Trackdir _track_enterdir_to_trackdir[TRACK_END][DIAGDIR_END];
491 return _track_enterdir_to_trackdir[track][diagdir];
492 }
493
498 inline Trackdir TrackDirectionToTrackdir(Track track, Direction dir)
499 {
500 assert(IsValidTrack(track));
501 assert(IsValidDirection(dir));
502 extern const Trackdir _track_direction_to_trackdir[TRACK_END][DIR_END];
503 return _track_direction_to_trackdir[track][dir];
504 }
505
512 inline Track DiagDirToDiagTrack(DiagDirection diagdir)
513 {
514 assert(IsValidDiagDirection(diagdir));
515 return (Track)(diagdir & 1);
516 }
517
524 inline TrackBits DiagDirToDiagTrackBits(DiagDirection diagdir)
525 {
526 assert(IsValidDiagDirection(diagdir));
527 return TrackToTrackBits(DiagDirToDiagTrack(diagdir));
528 }
529
537 inline Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
538 {
539 assert(IsValidDiagDirection(diagdir));
540 extern const Trackdir _dir_to_diag_trackdir[DIAGDIR_END];
541 return _dir_to_diag_trackdir[diagdir];
542 }
543
555 inline TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir)
556 {
557 assert(IsValidDiagDirection(diagdir));
558 extern const TrackdirBits _exitdir_reaches_trackdirs[DIAGDIR_END];
559 return _exitdir_reaches_trackdirs[diagdir];
560 }
561
573 inline TrackBits DiagdirReachesTracks(DiagDirection diagdir) { return TrackdirBitsToTrackBits(DiagdirReachesTrackdirs(diagdir)); }
574
584 inline TrackdirBits TrackdirReachesTrackdirs(Trackdir trackdir)
585 {
586 assert(IsValidTrackdir(trackdir));
587 extern const TrackdirBits _exitdir_reaches_trackdirs[DIAGDIR_END];
588 return _exitdir_reaches_trackdirs[TrackdirToExitdir(trackdir)];
589 }
590 /* Note that there is no direct table for this function (there used to be),
591 * but it uses two simpler tables to achieve the result */
592
606 inline TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir)
607 {
608 assert(IsValidTrackdirForRoadVehicle(trackdir));
609 extern const TrackdirBits _track_crosses_trackdirs[TRACK_END];
610 return _track_crosses_trackdirs[TrackdirToTrack(trackdir)];
611 }
612
619 inline bool IsDiagonalTrack(Track track)
620 {
621 assert(IsValidTrack(track));
622 return (track == TRACK_X) || (track == TRACK_Y);
623 }
624
631 inline bool IsDiagonalTrackdir(Trackdir trackdir)
632 {
633 assert(IsValidTrackdir(trackdir));
634 return IsDiagonalTrack(TrackdirToTrack(trackdir));
635 }
636
637
645 inline bool TracksOverlap(TrackBits bits)
646 {
647 /* With no, or only one track, there is no overlap */
648 if (bits == TRACK_BIT_NONE || KillFirstBit(bits) == TRACK_BIT_NONE) return false;
649 /* We know that there are at least two tracks present. When there are more
650 * than 2 tracks, they will surely overlap. When there are two, they will
651 * always overlap unless they are lower & upper or right & left. */
652 return bits != TRACK_BIT_HORZ && bits != TRACK_BIT_VERT;
653 }
654
662 inline bool TrackOverlapsTracks(TrackBits tracks, Track track)
663 {
664 if (HasBit(tracks, track)) return true;
665 return TracksOverlap(tracks | TrackToTrackBits(track));
666 }
667
673 inline bool IsReversingRoadTrackdir(Trackdir dir)
674 {
675 assert(IsValidTrackdirForRoadVehicle(dir));
676 return (dir & 0x07) >= 6;
677 }
678
684 inline bool IsStraightRoadTrackdir(Trackdir dir)
685 {
686 assert(IsValidTrackdirForRoadVehicle(dir));
687 return (dir & 0x06) == 0;
688 }
689
700 inline bool IsUphillTrackdir(Slope slope, Trackdir dir)
701 {
702 assert(IsValidTrackdirForRoadVehicle(dir));
703 extern const TrackdirBits _uphill_trackdirs[];
704 return HasBit(_uphill_trackdirs[RemoveHalftileSlope(slope)], dir);
705 }
706
714 inline DiagDirection VehicleExitDir(Direction direction, TrackBits track)
715 {
716 static const TrackBits state_dir_table[DIAGDIR_END] = { TRACK_BIT_RIGHT, TRACK_BIT_LOWER, TRACK_BIT_LEFT, TRACK_BIT_UPPER };
717
718 DiagDirection diagdir = DirToDiagDir(direction);
719
720 /* Determine the diagonal direction in which we will exit this tile */
721 if (!HasBit(direction, 0) && track != state_dir_table[diagdir]) {
722 diagdir = ChangeDiagDir(diagdir, DIAGDIRDIFF_90LEFT);
723 }
724
725 return diagdir;
726 }
727
728 #endif /* TRACK_FUNC_H */
DiagdirReachesTracks
TrackBits DiagdirReachesTracks(DiagDirection diagdir)
Returns all tracks that can be reached when entering a tile from a given (diagonal) direction.
Definition: track_func.h:573
TRACK_BIT_MASK
@ TRACK_BIT_MASK
Bitmask for the first 6 bits.
Definition: track_type.h:51
FindFirstTrack
Track FindFirstTrack(TrackBits tracks)
Returns first Track from TrackBits or INVALID_TRACK.
Definition: track_func.h:177
TRACK_BIT_NONE
@ TRACK_BIT_NONE
No track.
Definition: track_type.h:36
IsUphillTrackdir
bool IsUphillTrackdir(Slope slope, Trackdir dir)
Checks whether a trackdir on a specific slope is going uphill.
Definition: track_func.h:700
Direction
Direction
Defines the 8 directions on the map.
Definition: direction_type.h:24
TrackStatusToTrackdirBits
TrackdirBits TrackStatusToTrackdirBits(TrackStatus ts)
Returns the present-trackdir-information of a TrackStatus.
Definition: track_func.h:352
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition: direction_type.h:116
TrackdirToTrack
Track TrackdirToTrack(Trackdir trackdir)
Returns the Track that a given Trackdir represents.
Definition: track_func.h:262
TrackdirToExitdir
DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
Definition: track_func.h:439
RemoveHalftileSlope
static constexpr Slope RemoveHalftileSlope(Slope s)
Removes a halftile slope from a slope.
Definition: slope_func.h:60
TrackExitdirToTrackdir
Trackdir TrackExitdirToTrackdir(Track track, DiagDirection diagdir)
Maps a track and an (4-way) dir to the trackdir that represents the track with the exit in the given ...
Definition: track_func.h:461
IsValidTrackdirForRoadVehicle
bool IsValidTrackdirForRoadVehicle(Trackdir trackdir)
Checks if a Trackdir is valid for road vehicles.
Definition: track_func.h:40
TrackdirToTrackdirBits
TrackdirBits TrackdirToTrackdirBits(Trackdir trackdir)
Maps a Trackdir to the corresponding TrackdirBits value.
Definition: track_func.h:111
DIAGDIR_END
@ DIAGDIR_END
Used for iterations.
Definition: direction_type.h:79
TRACK_X
@ TRACK_X
Track along the x-axis (north-east to south-west)
Definition: track_type.h:21
FindFirstTrackdir
Trackdir FindFirstTrackdir(TrackdirBits trackdirs)
Returns first Trackdir from TrackdirBits or INVALID_TRACKDIR.
Definition: track_func.h:211
TrackOverlapsTracks
bool TrackOverlapsTracks(TrackBits tracks, Track track)
Check if a given track is contained within or overlaps some other tracks.
Definition: track_func.h:662
DIAGDIRDIFF_90LEFT
@ DIAGDIRDIFF_90LEFT
90 degrees left
Definition: direction_type.h:100
IsValidTrack
bool IsValidTrack(Track track)
Checks if a Track is valid.
Definition: track_func.h:28
NextTrackdir
Trackdir NextTrackdir(Trackdir trackdir)
Maps a trackdir to the trackdir that you will end up on if you go straight ahead.
Definition: track_func.h:403
KillFirstBit
constexpr T KillFirstBit(T value)
Clear the first bit in an integer.
Definition: bitmath_func.hpp:231
TRACK_BIT_UPPER
@ TRACK_BIT_UPPER
Upper track.
Definition: track_type.h:39
TrackStatusToRedSignals
TrackdirBits TrackStatusToRedSignals(TrackStatus ts)
Returns the red-signal-information of a TrackStatus.
Definition: track_func.h:376
TrackToTrackBits
TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
Definition: track_func.h:77
TracksOverlap
bool TracksOverlap(TrackBits bits)
Checks if the given tracks overlap, ie form a crossing.
Definition: track_func.h:645
TRACK_BIT_RIGHT
@ TRACK_BIT_RIGHT
Right track.
Definition: track_type.h:42
DiagDirToDiagTrackBits
TrackBits DiagDirToDiagTrackBits(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal track bits incidating with that diagdir.
Definition: track_func.h:524
Slope
Slope
Enumeration for the slope-type.
Definition: slope_type.h:48
TrackToTrackdir
Trackdir TrackToTrackdir(Track track)
Returns a Trackdir for the given Track.
Definition: track_func.h:279
bitmath_func.hpp
TRACK_BIT_VERT
@ TRACK_BIT_VERT
Left and right track.
Definition: track_type.h:45
TrackBitsToTrackdirBits
TrackdirBits TrackBitsToTrackdirBits(TrackBits bits)
Converts TrackBits to TrackdirBits while allowing both directions.
Definition: track_func.h:319
TRACK_Y
@ TRACK_Y
Track along the y-axis (north-west to south-east)
Definition: track_type.h:22
SetBitIterator
Iterable ensemble of each set bit in a value.
Definition: bitmath_func.hpp:282
RemoveFirstTrack
Track RemoveFirstTrack(TrackBits *tracks)
Removes first Track from TrackBits and returns it.
Definition: track_func.h:131
TrackToTrackdirBits
TrackdirBits TrackToTrackdirBits(Track track)
Returns a TrackdirBit mask from a given Track.
Definition: track_func.h:294
ChangeDiagDir
DiagDirection ChangeDiagDir(DiagDirection d, DiagDirDiff delta)
Applies a difference on a DiagDirection.
Definition: direction_func.h:149
TrackBitsToTrack
Track TrackBitsToTrack(TrackBits tracks)
Converts TrackBits to Track.
Definition: track_func.h:193
IsStraightRoadTrackdir
bool IsStraightRoadTrackdir(Trackdir dir)
Checks whether the given trackdir is a straight road.
Definition: track_func.h:684
IsValidDirection
bool IsValidDirection(Direction d)
Checks if an integer value is a valid Direction.
Definition: direction_func.h:32
slope_func.h
TrackCrossesTracks
TrackBits TrackCrossesTracks(Track track)
Maps a track to all tracks that make 90 deg turns with it.
Definition: track_func.h:420
TRACKDIR_BIT_NONE
@ TRACKDIR_BIT_NONE
No track build.
Definition: track_type.h:99
IsValidCorner
static constexpr bool IsValidCorner(Corner corner)
Rangecheck for Corner enumeration.
Definition: slope_func.h:24
Corner
Corner
Enumeration of tile corners.
Definition: slope_type.h:22
TrackdirReachesTrackdirs
TrackdirBits TrackdirReachesTrackdirs(Trackdir trackdir)
Maps a trackdir to the trackdirs that can be reached from it (ie, when entering the next tile.
Definition: track_func.h:584
ReverseTrackdir
Trackdir ReverseTrackdir(Trackdir trackdir)
Maps a trackdir to the reverse trackdir.
Definition: track_func.h:247
DiagdirReachesTrackdirs
TrackdirBits DiagdirReachesTrackdirs(DiagDirection diagdir)
Returns all trackdirs that can be reached when entering a tile from a given (diagonal) direction.
Definition: track_func.h:555
TrackdirBitsToTrackBits
TrackBits TrackdirBitsToTrackBits(TrackdirBits bits)
Discards all directional information from a TrackdirBits value.
Definition: track_func.h:308
VehicleExitDir
DiagDirection VehicleExitDir(Direction direction, TrackBits track)
Determine the side in which the vehicle will leave the tile.
Definition: track_func.h:714
RemoveFirstTrackdir
Trackdir RemoveFirstTrackdir(TrackdirBits *trackdirs)
Removes first Trackdir from TrackdirBits and returns it.
Definition: track_func.h:156
DirToDiagDir
DiagDirection DirToDiagDir(Direction dir)
Convert a Direction to a DiagDirection.
Definition: direction_func.h:166
INVALID_TRACKDIR
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
Definition: track_type.h:86
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition: direction_type.h:73
CombineTrackStatus
TrackStatus CombineTrackStatus(TrackdirBits trackdirbits, TrackdirBits red_signals)
Builds a TrackStatus.
Definition: track_func.h:388
TrackStatusToTrackBits
TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
Definition: track_func.h:363
TRACK_BIT_LOWER
@ TRACK_BIT_LOWER
Lower track.
Definition: track_type.h:40
IsValidAxis
bool IsValidAxis(Axis d)
Checks if an integer value is a valid Axis.
Definition: direction_func.h:43
INVALID_TRACK_BIT
@ INVALID_TRACK_BIT
Flag for an invalid trackbits value.
Definition: track_type.h:54
HasTrack
bool HasTrack(TrackBits tracks, Track track)
Checks whether a TrackBits has a given Track.
Definition: track_func.h:329
TRACK_END
@ TRACK_END
Used for iterations.
Definition: track_type.h:27
TRACK_BIT_HORZ
@ TRACK_BIT_HORZ
Upper and lower track.
Definition: track_type.h:44
IsValidDiagDirection
bool IsValidDiagDirection(DiagDirection d)
Checks if an integer value is a valid DiagDirection.
Definition: direction_func.h:21
TRACKDIR_BIT_MASK
@ TRACKDIR_BIT_MASK
Bitmask for bit-operations.
Definition: track_type.h:113
IsDiagonalTrack
bool IsDiagonalTrack(Track track)
Checks if a given Track is diagonal.
Definition: track_func.h:619
TRACK_BIT_LEFT
@ TRACK_BIT_LEFT
Left track.
Definition: track_type.h:41
DIR_END
@ DIR_END
Used to iterate.
Definition: direction_type.h:34
TRACKDIR_END
@ TRACKDIR_END
Used for iterations.
Definition: track_type.h:85
DiagDirToDiagTrack
Track DiagDirToDiagTrack(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal track incidating with that diagdir.
Definition: track_func.h:512
IsReversingRoadTrackdir
bool IsReversingRoadTrackdir(Trackdir dir)
Checks whether the trackdir means that we are reversing.
Definition: track_func.h:673
IsDiagonalTrackdir
bool IsDiagonalTrackdir(Trackdir trackdir)
Checks if a given Trackdir is diagonal.
Definition: track_func.h:631
AxisToTrack
Track AxisToTrack(Axis a)
Convert an Axis to the corresponding Track AXIS_X -> TRACK_X AXIS_Y -> TRACK_Y Uses the fact that the...
Definition: track_func.h:66
TrackBits
TrackBits
Allow incrementing of Track variables.
Definition: track_type.h:35
AxisToTrackBits
TrackBits AxisToTrackBits(Axis a)
Maps an Axis to the corresponding TrackBits value.
Definition: track_func.h:88
Trackdir
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:67
TrackDirectionToTrackdir
Trackdir TrackDirectionToTrackdir(Track track, Direction dir)
Maps a track and a full (8-way) direction to the trackdir that represents the track running in the gi...
Definition: track_func.h:498
TrackdirCrossesTrackdirs
TrackdirBits TrackdirCrossesTrackdirs(Trackdir trackdir)
Maps a trackdir to all trackdirs that make 90 deg turns with it.
Definition: track_func.h:606
TrackdirBits
TrackdirBits
Allow incrementing of Trackdir variables.
Definition: track_type.h:98
Track
Track
These are used to specify a single track.
Definition: track_type.h:19
HasTrackdir
bool HasTrackdir(TrackdirBits trackdirs, Trackdir trackdir)
Checks whether a TrackdirBits has a given Trackdir.
Definition: track_func.h:340
IsValidTrackdir
bool IsValidTrackdir(Trackdir trackdir)
Checks if a Trackdir is valid for non-road vehicles.
Definition: track_func.h:52
ClrBit
constexpr T ClrBit(T &x, const uint8_t y)
Clears a bit in a variable.
Definition: bitmath_func.hpp:151
DiagDirToDiagTrackdir
Trackdir DiagDirToDiagTrackdir(DiagDirection diagdir)
Maps a (4-way) direction to the diagonal trackdir that runs in that direction.
Definition: track_func.h:537
TrackEnterdirToTrackdir
Trackdir TrackEnterdirToTrackdir(Track track, DiagDirection diagdir)
Maps a track and an (4-way) dir to the trackdir that represents the track with the entry in the given...
Definition: track_func.h:486
CornerToTrackBits
TrackBits CornerToTrackBits(Corner corner)
Returns a single horizontal/vertical trackbit that is in a specific tile corner.
Definition: track_func.h:99
INVALID_TRACKDIR_BIT
@ INVALID_TRACKDIR_BIT
Flag for an invalid trackdirbit value.
Definition: track_type.h:114
track_type.h
direction_func.h
TrackToOppositeTrack
Track TrackToOppositeTrack(Track t)
Find the opposite track to a given track.
Definition: track_func.h:231
INVALID_TRACK
@ INVALID_TRACK
Flag for an invalid track.
Definition: track_type.h:28
FindFirstBit
constexpr uint8_t FindFirstBit(T x)
Search the first set bit in a value.
Definition: bitmath_func.hpp:194
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103