signal.cpp File Reference

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 "functions.h"
#include "train.h"
#include "company_base.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  { SIG_TBU_SIZE = 64, SIG_TBD_SIZE = 256, SIG_GLOB_SIZE = 128, SIG_GLOB_UPDATE = 64 }
 

these are the maximums used for updating signal blocks

More...
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
}
 

Current signal block state flags.

More...

Functions

 assert_compile (SIG_GLOB_UPDATE<=SIG_GLOB_SIZE)
static VehicleTrainOnTileEnum (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 seaching 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 seaching 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 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

Detailed Description

functions related to rail signals updating

Definition in file signal.cpp.


Enumeration Type Documentation

anonymous enum

these are the maximums used for updating signal blocks

Enumerator:
SIG_TBU_SIZE 

number of signals entering to block

SIG_TBD_SIZE 

number of intersections - open nodes in current block

SIG_GLOB_SIZE 

number of open blocks (block can be opened more times until detected)

SIG_GLOB_UPDATE 

how many items need to be in _globset to force update

Definition at line 23 of file signal.cpp.

enum SigFlags

Current signal block state flags.

Enumerator:
SF_TRAIN 

train found in segment

SF_EXIT 

exitsignal found

SF_EXIT2 

two or more exits found

SF_GREEN 

green exitsignal found

SF_GREEN2 

two or more green exits found

SF_FULL 

some of buffers was full, do not continue

SF_PBS 

pbs signal found

Definition at line 249 of file signal.cpp.


Function Documentation

void AddSideToSignalBuffer ( TileIndex  tile,
DiagDirection  side,
Owner  owner 
)

Add side of tile to signal update buffer.

Parameters:
tile tile where we start
side side of tile
owner owner whose signals we will update

Definition at line 610 of file signal.cpp.

References _globset, _last_owner, INVALID_OWNER, SIG_GLOB_UPDATE, and UpdateSignalsInBuffer().

Referenced by CmdBuildBridge(), CmdBuildTrainDepot(), and CmdBuildTunnel().

void AddTrackToSignalBuffer ( TileIndex  tile,
Track  track,
Owner  owner 
)

Add track to signal update buffer.

Parameters:
tile tile where we start
track track at which ends we will update signals
owner owner whose signals we will update

Definition at line 578 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 CmdBuildRailStation(), CmdBuildSingleRail(), CmdBuildSingleSignal(), CmdRemoveSingleRail(), CmdRemoveSingleSignal(), RemoveFromRailBaseStation(), RemoveRailStation(), and SetSignalsOnBothDir().

static bool CheckAddToTodoSet ( TileIndex  t1,
DiagDirection  d1,
TileIndex  t2,
DiagDirection  d2 
) [inline, static]

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 seaching won't enter any tile twice.

Parameters:
t1 tile we are entering
d1 direction (tile side) we are entering
t2 tile we are leaving
d2 direction (tile side) we are leaving
Returns:
false iff reverse direction was in Todo set

Definition at line 214 of file signal.cpp.

References _globset, and _tbdset.

Referenced by MaybeAddToTodoSet().

static SigFlags ExploreSegment ( Owner  owner  )  [static]
static bool MaybeAddToTodoSet ( TileIndex  t1,
DiagDirection  d1,
TileIndex  t2,
DiagDirection  d2 
) [inline, static]

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 seaching won't enter any tile twice.

Parameters:
t1 tile we are entering
d1 direction (tile side) we are entering
t2 tile we are leaving
d2 direction (tile side) we are leaving
Returns:
false iff the Todo buffer would be overrun

Definition at line 240 of file signal.cpp.

References _tbdset, and CheckAddToTodoSet().

Referenced by ExploreSegment().

void SetSignalsOnBothDir ( TileIndex  tile,
Track  track,
Owner  owner 
)

Update signals at segments that are at both ends of given (existent or non-existent) track.

See also:
UpdateSignalsInBuffer()
Parameters:
tile tile where we start
track track at which ends we will update signals
owner owner whose signals we will update

Definition at line 654 of file signal.cpp.

References _globset, AddTrackToSignalBuffer(), and UpdateSignalsInBuffer().

Referenced by DeleteLastWagon().

static void UpdateSignalsAroundSegment ( SigFlags  flags  )  [static]
static SigSegState UpdateSignalsInBuffer ( Owner  owner  )  [static]
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.

See also:
UpdateSignalsInBuffer()
Parameters:
tile tile where we start
side side of tile
owner owner whose signals we will update
Returns:
the state of the signal segment

Definition at line 636 of file signal.cpp.

References _globset, and UpdateSignalsInBuffer().

Referenced by DeleteLastWagon().


Variable Documentation

const TrackBits _enterdir_to_trackbits[DIAGDIR_END] [static]
Initial value:

incidating trackbits with given enterdir

Definition at line 33 of file signal.cpp.

Referenced by ExploreSegment(), and UpdateSignalsInBuffer().

const TrackdirBits _enterdir_to_trackdirbits[DIAGDIR_END] [static]

Generated on Wed Mar 31 22:43:39 2010 for OpenTTD by  doxygen 1.6.1