OpenTTD Source: src/direction_type.h Source File

OpenTTD Source 15.3

direction_type.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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#ifndef DIRECTION_TYPE_H
11#define DIRECTION_TYPE_H
12
13#include "core/enum_type.hpp"
14
24 enum Direction : uint8_t {
25 DIR_BEGIN = 0,
26 DIR_N = 0,
27 DIR_NE = 1,
28 DIR_E = 2,
29 DIR_SE = 3,
30 DIR_S = 4,
31 DIR_SW = 5,
32 DIR_W = 6,
33 DIR_NW = 7,
34 DIR_END,
35 INVALID_DIR = 0xFF,
36};
37
39 DECLARE_INCREMENT_DECREMENT_OPERATORS(Direction)
40
41using Directions = EnumBitSet<Direction, uint8_t>;
42
44static constexpr Directions DIRECTIONS_ALL{DIR_N, DIR_NE, DIR_E, DIR_SE, DIR_S, DIR_SW, DIR_W, DIR_NW};
45
63 enum DirDiff : uint8_t {
64 DIRDIFF_SAME = 0,
65 DIRDIFF_45RIGHT = 1,
66 DIRDIFF_90RIGHT = 2,
67 DIRDIFF_REVERSE = 4,
68 DIRDIFF_90LEFT = 6,
69 DIRDIFF_45LEFT = 7,
70};
71
72
78 enum DiagDirection : uint8_t {
79 DIAGDIR_BEGIN = 0,
80 DIAGDIR_NE = 0,
81 DIAGDIR_SE = 1,
82 DIAGDIR_SW = 2,
83 DIAGDIR_NW = 3,
84 DIAGDIR_END,
85 INVALID_DIAGDIR = 0xFF,
86};
87 DECLARE_INCREMENT_DECREMENT_OPERATORS(DiagDirection)
88 DECLARE_ENUM_AS_ADDABLE(DiagDirection)
89
90using DiagDirections = EnumBitSet<DiagDirection, uint8_t>;
91
102 enum DiagDirDiff : uint8_t {
103 DIAGDIRDIFF_BEGIN = 0,
104 DIAGDIRDIFF_SAME = 0,
105 DIAGDIRDIFF_90RIGHT = 1,
106 DIAGDIRDIFF_REVERSE = 2,
107 DIAGDIRDIFF_90LEFT = 3,
108 DIAGDIRDIFF_END,
109};
110
112 DECLARE_INCREMENT_DECREMENT_OPERATORS(DiagDirDiff)
113
114
115
123enum Axis : uint8_t {
124 AXIS_X = 0,
125 AXIS_Y = 1,
126 AXIS_END,
127 INVALID_AXIS = 0xFF,
128};
129 DECLARE_ENUM_AS_ADDABLE(Axis)
130
131#endif /* DIRECTION_TYPE_H */
EnumBitSet
Enum-as-bit-set wrapper.
Definition enum_type.hpp:177
DirDiff
DirDiff
Enumeration for the difference between two directions.
Definition direction_type.h:63
DIRDIFF_90LEFT
@ DIRDIFF_90LEFT
Angle of 90 degrees left.
Definition direction_type.h:68
DIRDIFF_45LEFT
@ DIRDIFF_45LEFT
Angle of 45 degrees left.
Definition direction_type.h:69
DIRDIFF_REVERSE
@ DIRDIFF_REVERSE
One direction is the opposite of the other one.
Definition direction_type.h:67
DIRDIFF_45RIGHT
@ DIRDIFF_45RIGHT
Angle of 45 degrees right.
Definition direction_type.h:65
DIRDIFF_SAME
@ DIRDIFF_SAME
Both directions faces to the same direction.
Definition direction_type.h:64
DIRDIFF_90RIGHT
@ DIRDIFF_90RIGHT
Angle of 90 degrees right.
Definition direction_type.h:66
Direction
Direction
Defines the 8 directions on the map.
Definition direction_type.h:24
DIR_BEGIN
@ DIR_BEGIN
Used to iterate.
Definition direction_type.h:25
DIR_SW
@ DIR_SW
Southwest.
Definition direction_type.h:31
DIR_NW
@ DIR_NW
Northwest.
Definition direction_type.h:33
INVALID_DIR
@ INVALID_DIR
Flag for an invalid direction.
Definition direction_type.h:35
DIR_N
@ DIR_N
North.
Definition direction_type.h:26
DIR_SE
@ DIR_SE
Southeast.
Definition direction_type.h:29
DIR_S
@ DIR_S
South.
Definition direction_type.h:30
DIR_NE
@ DIR_NE
Northeast.
Definition direction_type.h:27
DIR_END
@ DIR_END
Used to iterate.
Definition direction_type.h:34
DIR_W
@ DIR_W
West.
Definition direction_type.h:32
DIR_E
@ DIR_E
East.
Definition direction_type.h:28
DiagDirDiff
DiagDirDiff
Enumeration for the difference between to DiagDirection.
Definition direction_type.h:102
DIAGDIRDIFF_END
@ DIAGDIRDIFF_END
Used for iterations.
Definition direction_type.h:108
DIAGDIRDIFF_90RIGHT
@ DIAGDIRDIFF_90RIGHT
90 degrees right
Definition direction_type.h:105
DIAGDIRDIFF_90LEFT
@ DIAGDIRDIFF_90LEFT
90 degrees left
Definition direction_type.h:107
DIAGDIRDIFF_REVERSE
@ DIAGDIRDIFF_REVERSE
Reverse directions.
Definition direction_type.h:106
DIAGDIRDIFF_SAME
@ DIAGDIRDIFF_SAME
Same directions.
Definition direction_type.h:104
DIAGDIRDIFF_BEGIN
@ DIAGDIRDIFF_BEGIN
Used for iterations.
Definition direction_type.h:103
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition direction_type.h:123
INVALID_AXIS
@ INVALID_AXIS
Flag for an invalid Axis.
Definition direction_type.h:127
AXIS_END
@ AXIS_END
Used for iterations.
Definition direction_type.h:126
AXIS_X
@ AXIS_X
The X axis.
Definition direction_type.h:124
AXIS_Y
@ AXIS_Y
The y axis.
Definition direction_type.h:125
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition direction_type.h:78
DIAGDIR_NE
@ DIAGDIR_NE
Northeast, upper right on your monitor.
Definition direction_type.h:80
DIAGDIR_NW
@ DIAGDIR_NW
Northwest.
Definition direction_type.h:83
DIAGDIR_SE
@ DIAGDIR_SE
Southeast.
Definition direction_type.h:81
DIAGDIR_END
@ DIAGDIR_END
Used for iterations.
Definition direction_type.h:84
DIAGDIR_BEGIN
@ DIAGDIR_BEGIN
Used for iterations.
Definition direction_type.h:79
INVALID_DIAGDIR
@ INVALID_DIAGDIR
Flag for an invalid DiagDirection.
Definition direction_type.h:85
DIAGDIR_SW
@ DIAGDIR_SW
Southwest.
Definition direction_type.h:82
DIRECTIONS_ALL
static constexpr Directions DIRECTIONS_ALL
All possible directions.
Definition direction_type.h:44
enum_type.hpp
Type (helpers) for enums.
DECLARE_ENUM_AS_ADDABLE
#define DECLARE_ENUM_AS_ADDABLE(EnumType)
Operator that allows this enumeration to be added to any other enumeration.
Definition enum_type.hpp:129
DECLARE_INCREMENT_DECREMENT_OPERATORS
#define DECLARE_INCREMENT_DECREMENT_OPERATORS(enum_type)
For some enums it is useful to have pre/post increment/decrement operators.
Definition enum_type.hpp:63