OpenTTD Source
20240917-master-g9ab0a47812
|
Go to the documentation of this file.
52 template <
typename Tdir, u
int items>
67 SmallSet(
const char *name) : n(0), overflowed(false), name(name) { }
73 this->overflowed =
false;
82 return this->overflowed;
121 for (uint i = 0; i < this->n; i++) {
122 if (this->data[i].tile == tile && this->data[i].dir == dir) {
123 this->data[i] = this->data[--this->n];
139 for (uint i = 0; i < this->n; i++) {
140 if (this->data[i].tile == tile && this->data[i].dir == dir)
return true;
157 Debug(misc, 0,
"SignalSegment too complex. Set {} is full (maximum {})", name, items);
161 this->data[this->n].tile = tile;
162 this->data[this->n].dir = dir;
176 if (this->n == 0)
return false;
179 *tile = this->data[this->n].tile;
180 *dir = this->data[this->n].dir;
220 return !
_tbdset.Remove(t2, d2);
276 while (
_tbdset.Get(&tile, &enterdir)) {
304 tracks = tracks_masked;
325 if (IsPbsSignal(sig)) flags |=
SF_PBS;
418 while (
_tbuset.Get(&tile, &trackdir)) {
606 _globset.Add(tile, _search_dir_1[track]);
607 _globset.Add(tile, _search_dir_2[track]);
static void UpdateSignalsAroundSegment(SigFlags flags)
Update signals around segment in _tbuset.
@ DIAGDIR_NE
Northeast, upper right on your monitor.
static SigSegState UpdateSignalsInBuffer(Owner owner)
Updates blocks in _globset buffer.
static const uint SIG_GLOB_UPDATE
how many items need to be in _globset to force update
bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
Checks whether a vehicle is on a specific location.
@ SF_EXIT
exitsignal found
@ SIGTYPE_COMBO
presignal inter-block
bool IsOnewaySignal(Tile t, Track track)
One-way signals can't be passed the 'wrong' way.
Track TrackdirToTrack(Trackdir trackdir)
Returns the Track that a given Trackdir represents.
DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
@ INVALID_OWNER
An invalid owner.
static void ResetSets()
Reset all sets after one set overflowed.
Owner
Enum for all companies/owners.
@ TRACK_BIT_HORZ
Upper and lower track.
Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
@ VEH_TRAIN
Train vehicle type.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
@ SIGNAL_STATE_GREEN
The signal is green.
@ TRACKDIR_BIT_LEFT_N
Track left, direction north.
@ TRACK_BIT_VERT
Left and right track.
DiagDirection
Enumeration for diagonal directions.
SignalState
These are states in which a signal can be.
static const TrackBits _enterdir_to_trackbits[DIAGDIR_END]
incidating trackbits with given enterdir
SigSegState UpdateSignalsOnSegment(TileIndex tile, DiagDirection side, Owner owner)
Update signals, starting at one side of a tile Will check tile next to this at opposite side too.
bool IsLevelCrossing(Tile t)
Return whether a tile is a level crossing.
@ TRACK_BIT_3WAY_SW
"Arrow" to the south-west
@ TRACKDIR_BIT_Y_NW
Track y-axis, direction north-west.
static bool MaybeAddToTodoSet(TileIndex t1, DiagDirection d1, TileIndex t2, DiagDirection d2)
Perform some operations before adding data into Todo set The new and reverse direction is removed fro...
@ MP_ROAD
A tile with road (or tram tracks)
static Vehicle * TrainOnTileEnum(Vehicle *v, void *)
Check whether there is a train on rail, not in a depot.
SmallSet(const char *name)
Constructor - just set default values and 'name'.
static const uint SIG_TBU_SIZE
these are the maximums used for updating signal blocks
Axis GetRailStationAxis(Tile t)
Get the rail direction of a rail station.
bool Add(TileIndex tile, Tdir dir)
Adds tile & dir into the set, checks for full set Sets the 'overflowed' flag if the set was full.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
TrackBits TrackToTrackBits(Track track)
Maps a Track to the corresponding TrackBits value.
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
@ TRACK_BIT_NONE
No track.
void SetSignalsOnBothDir(TileIndex tile, Track track, Owner owner)
Update signals at segments that are at both ends of given (existent or non-existent) track.
DiagDirection GetRailDepotDirection(Tile t)
Returns the direction the depot is facing to.
uint Items()
Reads the number of items.
static debug_inline bool IsRailDepot(Tile t)
Is this rail tile a rail depot?
@ TRACK_BIT_3WAY_NE
"Arrow" to the north-east
@ SF_EXIT2
two or more exits found
@ SF_SPLIT
track merge/split found
static const uint SIG_TBD_SIZE
number of intersections - open nodes in current block
Track TrackBitsToTrack(TrackBits tracks)
Converts TrackBits to Track.
TrackBits
Allow incrementing of Track variables.
@ INVALID_DIAGDIR
Flag for an invalid DiagDirection.
@ SIGNAL_STATE_RED
The signal is red.
@ DIAGDIR_BEGIN
Used for iterations.
TrackBits GetRailReservationTrackBits(Tile t)
Returns the reserved track bits of the tile.
DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
bool HasSignalOnTrack(Tile tile, Track track)
Checks for the presence of signals (either way) on the given track on the given rail tile.
bool Failed() const
Did this command fail?
@ TRACKDIR_BIT_LOWER_W
Track lower, direction west.
static const uint SIG_GLOB_SIZE
number of open blocks (block can be opened more times until detected)
Trackdir ReverseTrackdir(Trackdir trackdir)
Maps a trackdir to the reverse trackdir.
static const TrackdirBits _enterdir_to_trackdirbits[DIAGDIR_END]
incidating trackdirbits with given enterdir
@ TRACKDIR_BIT_UPPER_E
Track upper, direction east.
@ TRACKDIR_BIT_LEFT_S
Track left, direction south.
@ SIGSEG_PBS
Segment is a PBS segment.
#define lengthof(array)
Return the length of an fixed size array.
@ TRACKDIR_BIT_RIGHT_S
Track right, direction south.
SignalState GetSignalStateByTrackdir(Tile tile, Trackdir trackdir)
Gets the state of the signal along the given trackdir.
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
bool Get(TileIndex *tile, Tdir *dir)
Reads the last added element into the set.
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
SigFlags
Current signal block state flags.
static SmallSet< Trackdir, SIG_TBU_SIZE > _tbuset("_tbuset")
set of signals that will be updated
SigSegState
State of the signal segment.
TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
bool IsIn(TileIndex tile, Tdir dir)
Tries to find given tile and dir in the set.
TrackBits GetTrackBits(Tile tile)
Gets the track bits of the given tile.
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
static SigFlags ExploreSegment(Owner owner)
Search signal block.
@ TRACKDIR_BIT_X_NE
Track x-axis, direction north-east.
bool IsEmpty()
Checks for empty set.
@ SF_FULL
some of buffers was full, do not continue
bool IsValidDiagDirection(DiagDirection d)
Checks if an integer value is a valid DiagDirection.
Track
These are used to specify a single track.
CommandCost EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits)
Tests if a vehicle interacts with the specified track bits.
Trackdir
Enumeration for tracks and directions.
Axis GetCrossingRoadAxis(Tile t)
Get the road axis of a level crossing.
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
@ TRANSPORT_RAIL
Transport by train.
@ TRACKDIR_BIT_LOWER_E
Track lower, direction east.
@ SF_ENTER2
two or more signals entering the block found
static Owner _last_owner
last owner whose track was put into _globset
constexpr bool HasAtMostOneBit(T value)
Test whether value has at most 1 bit set.
bool HasStationRail(Tile t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
bool IsFull()
Checks for full set.
@ SF_GREEN2
two or more green exits found
bool HasSignals(Tile t)
Checks if a rail tile has signals.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
void AddSideToSignalBuffer(TileIndex tile, DiagDirection side, Owner owner)
Add side of tile to signal update buffer.
Set containing 'items' items of 'tile and Tdir' No tree structure is used because it would cause slow...
@ MP_STATION
A tile of a station.
TransportType GetTunnelBridgeTransportType(Tile t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
@ SF_TRAIN
train found in segment
@ DIAGDIR_END
Used for iterations.
bool Overflowed()
Returns value of 'overflowed'.
void AddTrackToSignalBuffer(TileIndex tile, Track track, Owner owner)
Add track to signal update buffer.
@ SIGSEG_FULL
Occupied by a train.
@ SF_GREEN
green exitsignal found
TileIndex GetOtherTunnelBridgeEnd(Tile t)
Determines type of the wormhole and returns its other end.
static SmallSet< DiagDirection, SIG_GLOB_SIZE > _globset("_globset")
set of places to be updated in following runs
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
@ TRACKDIR_BIT_Y_SE
Track y-axis, direction south-east.
void Reset()
Reset variables to default values.
@ TRACKDIR_BIT_RIGHT_N
Track right, direction north.
bool IsStationTileBlocked(Tile t)
Is tile t a blocked tile?
@ TRACK_BIT_3WAY_NW
"Arrow" to the north-west
SignalType
Type of signal, i.e.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
VehicleType type
Type of vehicle.
bool Remove(TileIndex tile, Tdir dir)
Tries to remove first instance of given tile and dir.
TrackdirBits
Allow incrementing of Trackdir variables.
@ TRACK_BIT_3WAY_SE
"Arrow" to the south-east
static SmallSet< DiagDirection, SIG_TBD_SIZE > _tbdset("_tbdset")
set of open nodes in current signal block
@ TRACK_BIT_DEPOT
Bitflag for a depot.
void SetSignalStateByTrackdir(Tile tile, Trackdir trackdir, SignalState state)
Sets the state of the signal along the given trackdir.
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
@ TRACKDIR_BIT_UPPER_W
Track upper, direction west.
static bool CheckAddToTodoSet(TileIndex t1, DiagDirection d1, TileIndex t2, DiagDirection d2)
Perform some operations before adding data into Todo set The new and reverse direction is removed fro...
@ SIGSEG_FREE
Free and has no pre-signal exits or at least one green exit.
@ SF_ENTER
signal entering the block found
@ TRACKDIR_BIT_X_SW
Track x-axis, direction south-west.
bool HasSignalOnTrackdir(Tile tile, Trackdir trackdir)
Checks for the presence of signals along the given trackdir on the given rail tile.
DiagDirection GetTunnelBridgeDirection(Tile t)
Get the direction pointing to the other end.
constexpr uint8_t FindFirstBit(T x)
Search the first set bit in a value.