OpenTTD Source 20241224-master-gf74b0cf984
|
functions related to rail signals updating More...
#include "stdafx.h"
#include "debug.h"
#include "station_map.h"
#include "tunnelbridge_map.h"
#include "vehicle_func.h"
#include "viewport_func.h"
#include "train.h"
#include "company_base.h"
#include "pbs.h"
#include "safeguards.h"
Go to the source code of this file.
Data Structures | |
struct | SmallSet< Tdir, items > |
Set containing 'items' items of 'tile and Tdir' No tree structure is used because it would cause slowdowns in most usual cases. More... | |
struct | SmallSet< Tdir, items >::SSdata |
Element of set. More... | |
Enumerations | |
enum | SigFlags { SF_NONE = 0 , SF_TRAIN = 1 << 0 , SF_EXIT = 1 << 1 , SF_EXIT2 = 1 << 2 , SF_GREEN = 1 << 3 , SF_GREEN2 = 1 << 4 , SF_FULL = 1 << 5 , SF_PBS = 1 << 6 , SF_SPLIT = 1 << 7 , SF_ENTER = 1 << 8 , SF_ENTER2 = 1 << 9 } |
Current signal block state flags. More... | |
Functions | |
static Vehicle * | TrainOnTileEnum (Vehicle *v, void *) |
Check whether there is a train on rail, not in a depot. | |
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 from _globset, because we are sure it doesn't need to be checked again Also, remove reverse direction from _tbdset This is the 'core' part so the graph searching won't enter any tile twice. | |
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 from Global set, because we are sure it doesn't need to be checked again Also, remove reverse direction from Todo set This is the 'core' part so the graph searching won't enter any tile twice. | |
static SigFlags | ExploreSegment (Owner owner) |
Search signal block. | |
static void | UpdateSignalsAroundSegment (SigFlags flags) |
Update signals around segment in _tbuset. | |
static void | ResetSets () |
Reset all sets after one set overflowed. | |
static SigSegState | UpdateSignalsInBuffer (Owner owner) |
Updates blocks in _globset buffer. | |
void | UpdateSignalsInBuffer () |
Update signals in buffer Called from 'outside'. | |
void | AddTrackToSignalBuffer (TileIndex tile, Track track, Owner owner) |
Add track to signal update buffer. | |
void | AddSideToSignalBuffer (TileIndex tile, DiagDirection side, Owner owner) |
Add side of tile to signal update buffer. | |
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. | |
void | SetSignalsOnBothDir (TileIndex tile, Track track, Owner owner) |
Update signals at segments that are at both ends of given (existent or non-existent) track. | |
Variables | |
static const uint | SIG_TBU_SIZE = 64 |
these are the maximums used for updating signal blocks | |
static const uint | SIG_TBD_SIZE = 256 |
number of intersections - open nodes in current block | |
static const uint | SIG_GLOB_SIZE = 128 |
number of open blocks (block can be opened more times until detected) | |
static const uint | SIG_GLOB_UPDATE = 64 |
how many items need to be in _globset to force update | |
static const TrackBits | _enterdir_to_trackbits [DIAGDIR_END] |
incidating trackbits with given enterdir | |
static const TrackdirBits | _enterdir_to_trackdirbits [DIAGDIR_END] |
incidating trackdirbits with given enterdir | |
static SmallSet< Trackdir, SIG_TBU_SIZE > | _tbuset ("_tbuset") |
set of signals that will be updated | |
static SmallSet< DiagDirection, SIG_TBD_SIZE > | _tbdset ("_tbdset") |
set of open nodes in current signal block | |
static SmallSet< DiagDirection, SIG_GLOB_SIZE > | _globset ("_globset") |
set of places to be updated in following runs | |
static Owner | _last_owner = INVALID_OWNER |
last owner whose track was put into _globset | |
functions related to rail signals updating
Definition in file signal.cpp.
enum SigFlags |
Current signal block state flags.
Definition at line 246 of file signal.cpp.
void AddSideToSignalBuffer | ( | TileIndex | tile, |
DiagDirection | side, | ||
Owner | owner | ||
) |
Add side of tile to signal update buffer.
tile | tile where we start |
side | side of tile |
owner | owner whose signals we will update |
Definition at line 624 of file signal.cpp.
References _globset, _last_owner, INVALID_OWNER, SIG_GLOB_UPDATE, and UpdateSignalsInBuffer().
Referenced by CmdBuildBridge(), CmdBuildTrainDepot(), CmdBuildTunnel(), DoClearBridge(), DoClearTunnel(), and FreeTrainTrackReservation().
Add track to signal update buffer.
tile | tile where we start |
track | track at which ends we will update signals |
owner | owner whose signals we will update |
Definition at line 592 of file signal.cpp.
References _globset, _last_owner, DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_SW, INVALID_OWNER, SIG_GLOB_UPDATE, and UpdateSignalsInBuffer().
Referenced by ChangeOwnershipOfCompanyItems(), CmdBuildRailStation(), CmdBuildSingleRail(), CmdBuildSingleSignal(), CmdRemoveSingleRail(), CmdRemoveSingleSignal(), RemoveFromRailBaseStation(), and SetSignalsOnBothDir().
|
inlinestatic |
Perform some operations before adding data into Todo set The new and reverse direction is removed from _globset, because we are sure it doesn't need to be checked again Also, remove reverse direction from _tbdset This is the 'core' part so the graph searching won't enter any tile twice.
t1 | tile we are entering |
d1 | direction (tile side) we are entering |
t2 | tile we are leaving |
d2 | direction (tile side) we are leaving |
Definition at line 213 of file signal.cpp.
References _globset, and _tbdset.
Referenced by MaybeAddToTodoSet().
Search signal block.
owner | owner whose signals we are updating |
Definition at line 269 of file signal.cpp.
References _enterdir_to_trackbits, _enterdir_to_trackdirbits, _tbdset, _tbuset, DIAGDIR_BEGIN, DIAGDIR_END, DiagDirToAxis(), EnsureNoTrainOnTrackBits(), CommandCost::Failed(), FindFirstBit(), GetCrossingRoadAxis(), GetOtherTunnelBridgeEnd(), GetRailDepotDirection(), GetRailStationAxis(), GetSignalStateByTrackdir(), GetTileOwner(), GetTileType(), GetTrackBits(), GetTunnelBridgeDirection(), GetTunnelBridgeTransportType(), HasAtMostOneBit(), HasSignalOnTrack(), HasSignalOnTrackdir(), HasSignals(), HasStationRail(), HasVehicleOnPos(), INVALID_DIAGDIR, INVALID_TILE, IsLevelCrossing(), IsOnewaySignal(), IsRailDepot(), IsStationTileBlocked(), IsValidDiagDirection(), MaybeAddToTodoSet(), MP_RAILWAY, MP_ROAD, MP_STATION, MP_TUNNELBRIDGE, ReverseDiagDir(), ReverseTrackdir(), SF_ENTER, SF_ENTER2, SF_EXIT, SF_EXIT2, SF_FULL, SF_GREEN, SF_GREEN2, SF_PBS, SF_SPLIT, SF_TRAIN, SIGNAL_STATE_GREEN, TileOffsByDiagDir(), TRACK_BIT_HORZ, TRACK_BIT_NONE, TRACK_BIT_VERT, TrackBitsToTrack(), TrainOnTileEnum(), and TRANSPORT_RAIL.
Referenced by UpdateSignalsInBuffer().
|
inlinestatic |
Perform some operations before adding data into Todo set The new and reverse direction is removed from Global set, because we are sure it doesn't need to be checked again Also, remove reverse direction from Todo set This is the 'core' part so the graph searching won't enter any tile twice.
t1 | tile we are entering |
d1 | direction (tile side) we are entering |
t2 | tile we are leaving |
d2 | direction (tile side) we are leaving |
Definition at line 237 of file signal.cpp.
References _tbdset, and CheckAddToTodoSet().
Referenced by ExploreSegment().
|
inlinestatic |
Reset all sets after one set overflowed.
Definition at line 467 of file signal.cpp.
References _globset, _tbdset, and _tbuset.
Referenced by UpdateSignalsInBuffer().
Update signals at segments that are at both ends of given (existent or non-existent) track.
tile | tile where we start |
track | track at which ends we will update signals |
owner | owner whose signals we will update |
Definition at line 668 of file signal.cpp.
References _globset, AddTrackToSignalBuffer(), and UpdateSignalsInBuffer().
Referenced by DeleteLastWagon().
Check whether there is a train on rail, not in a depot.
Definition at line 192 of file signal.cpp.
References SpecializedVehicle< T, Type >::From(), TRACK_BIT_DEPOT, BaseVehicle::type, and VEH_TRAIN.
Referenced by ExploreSegment().
|
static |
Update signals around segment in _tbuset.
flags | info about segment |
Definition at line 413 of file signal.cpp.
References _globset, _tbuset, GetRailReservationTrackBits(), GetSignalStateByTrackdir(), HasSignalOnTrackdir(), INVALID_TILE, INVALID_TRACKDIR, MarkTileDirtyByTile(), ReverseTrackdir(), SetSignalStateByTrackdir(), SF_ENTER2, SF_EXIT, SF_EXIT2, SF_GREEN, SF_GREEN2, SF_SPLIT, SF_TRAIN, SIGNAL_STATE_GREEN, SIGNAL_STATE_RED, SIGTYPE_COMBO, TRACK_BIT_NONE, TrackdirToExitdir(), TrackdirToTrack(), and TrackToTrackBits().
Referenced by UpdateSignalsInBuffer().
void UpdateSignalsInBuffer | ( | ) |
Update signals in buffer Called from 'outside'.
Definition at line 576 of file signal.cpp.
References _globset, _last_owner, INVALID_OWNER, and UpdateSignalsInBuffer().
Referenced by AddSideToSignalBuffer(), AddTrackToSignalBuffer(), ChangeOwnershipOfCompanyItems(), DoFloodTile(), FreeTrainTrackReservation(), CommandHelperBase::InternalExecuteProcessResult(), SetSignalsOnBothDir(), UpdateSignalsInBuffer(), and UpdateSignalsOnSegment().
|
static |
Updates blocks in _globset buffer.
owner | company whose signals we are updating |
Definition at line 482 of file signal.cpp.
References _enterdir_to_trackbits, _globset, _tbdset, _tbuset, ExploreSegment(), GetOtherTunnelBridgeEnd(), GetRailDepotDirection(), GetTileTrackStatus(), GetTileType(), GetTunnelBridgeDirection(), GetTunnelBridgeTransportType(), INVALID_DIAGDIR, INVALID_TILE, IsRailDepot(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), MP_RAILWAY, MP_ROAD, MP_STATION, MP_TUNNELBRIDGE, ResetSets(), ReverseDiagDir(), SF_EXIT, SF_FULL, SF_GREEN, SF_PBS, SF_TRAIN, SIGSEG_FREE, SIGSEG_FULL, SIGSEG_PBS, TileOffsByDiagDir(), TRACK_BIT_NONE, TrackStatusToTrackBits(), TRANSPORT_RAIL, and UpdateSignalsAroundSegment().
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.
tile | tile where we start |
side | side of tile |
owner | owner whose signals we will update |
Definition at line 650 of file signal.cpp.
References _globset, and UpdateSignalsInBuffer().
Referenced by CheckTrainStayInDepot(), DeleteLastWagon(), ReverseTrainDirection(), TrainController(), and VehicleEnterDepot().
|
static |
incidating trackbits with given enterdir
Definition at line 32 of file signal.cpp.
Referenced by ExploreSegment(), and UpdateSignalsInBuffer().
|
static |
incidating trackdirbits with given enterdir
Definition at line 40 of file signal.cpp.
Referenced by ExploreSegment().
|
static |
last owner whose track was put into _globset
Definition at line 569 of file signal.cpp.
Referenced by AddSideToSignalBuffer(), AddTrackToSignalBuffer(), and UpdateSignalsInBuffer().
|
static |
number of open blocks (block can be opened more times until detected)
Definition at line 26 of file signal.cpp.
|
static |
how many items need to be in _globset to force update
Definition at line 27 of file signal.cpp.
Referenced by AddSideToSignalBuffer(), and AddTrackToSignalBuffer().
|
static |
number of intersections - open nodes in current block
Definition at line 25 of file signal.cpp.
|
static |
these are the maximums used for updating signal blocks
number of signals entering to block
Definition at line 24 of file signal.cpp.