OpenTTD
signal.cpp
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 #include "stdafx.h"
11 #include "debug.h"
12 #include "station_map.h"
13 #include "tunnelbridge_map.h"
14 #include "vehicle_func.h"
15 #include "viewport_func.h"
16 #include "train.h"
17 #include "company_base.h"
18 
19 #include "safeguards.h"
20 
21 
23 static const uint SIG_TBU_SIZE = 64;
24 static const uint SIG_TBD_SIZE = 256;
25 static const uint SIG_GLOB_SIZE = 128;
26 static const uint SIG_GLOB_UPDATE = 64;
27 
28 assert_compile(SIG_GLOB_UPDATE <= SIG_GLOB_SIZE);
29 
36 };
37 
44 };
45 
51 template <typename Tdir, uint items>
52 struct SmallSet {
53 private:
54  uint n; // actual number of units
55  bool overflowed; // did we try to overflow the set?
56  const char *name; // name, used for debugging purposes...
57 
59  struct SSdata {
60  TileIndex tile;
61  Tdir dir;
62  } data[items];
63 
64 public:
66  SmallSet(const char *name) : n(0), overflowed(false), name(name) { }
67 
69  void Reset()
70  {
71  this->n = 0;
72  this->overflowed = false;
73  }
74 
79  bool Overflowed()
80  {
81  return this->overflowed;
82  }
83 
88  bool IsEmpty()
89  {
90  return this->n == 0;
91  }
92 
97  bool IsFull()
98  {
99  return this->n == lengthof(data);
100  }
101 
106  uint Items()
107  {
108  return this->n;
109  }
110 
111 
118  bool Remove(TileIndex tile, Tdir dir)
119  {
120  for (uint i = 0; i < this->n; i++) {
121  if (this->data[i].tile == tile && this->data[i].dir == dir) {
122  this->data[i] = this->data[--this->n];
123  return true;
124  }
125  }
126 
127  return false;
128  }
129 
136  bool IsIn(TileIndex tile, Tdir dir)
137  {
138  for (uint i = 0; i < this->n; i++) {
139  if (this->data[i].tile == tile && this->data[i].dir == dir) return true;
140  }
141 
142  return false;
143  }
144 
152  bool Add(TileIndex tile, Tdir dir)
153  {
154  if (this->IsFull()) {
155  overflowed = true;
156  DEBUG(misc, 0, "SignalSegment too complex. Set %s is full (maximum %d)", name, items);
157  return false; // set is full
158  }
159 
160  this->data[this->n].tile = tile;
161  this->data[this->n].dir = dir;
162  this->n++;
163 
164  return true;
165  }
166 
173  bool Get(TileIndex *tile, Tdir *dir)
174  {
175  if (this->n == 0) return false;
176 
177  this->n--;
178  *tile = this->data[this->n].tile;
179  *dir = this->data[this->n].dir;
180 
181  return true;
182  }
183 };
184 
185 static SmallSet<Trackdir, SIG_TBU_SIZE> _tbuset("_tbuset");
188 
189 
191 static Vehicle *TrainOnTileEnum(Vehicle *v, void *)
192 {
193  if (v->type != VEH_TRAIN || Train::From(v)->track == TRACK_BIT_DEPOT) return nullptr;
194 
195  return v;
196 }
197 
198 
213 {
214  _globset.Remove(t1, d1); // it can be in Global but not in Todo
215  _globset.Remove(t2, d2); // remove in all cases
216 
217  assert(!_tbdset.IsIn(t1, d1)); // it really shouldn't be there already
218 
219  if (_tbdset.Remove(t2, d2)) return false;
220 
221  return true;
222 }
223 
224 
239 {
240  if (!CheckAddToTodoSet(t1, d1, t2, d2)) return true;
241 
242  return _tbdset.Add(t1, d1);
243 }
244 
245 
247 enum SigFlags {
248  SF_NONE = 0,
249  SF_TRAIN = 1 << 0,
250  SF_EXIT = 1 << 1,
251  SF_EXIT2 = 1 << 2,
252  SF_GREEN = 1 << 3,
253  SF_GREEN2 = 1 << 4,
254  SF_FULL = 1 << 5,
255  SF_PBS = 1 << 6,
256 };
257 
259 
260 
261 
268 {
269  SigFlags flags = SF_NONE;
270 
271  TileIndex tile;
272  DiagDirection enterdir;
273 
274  while (_tbdset.Get(&tile, &enterdir)) {
275  TileIndex oldtile = tile; // tile we are leaving
276  DiagDirection exitdir = enterdir == INVALID_DIAGDIR ? INVALID_DIAGDIR : ReverseDiagDir(enterdir); // expected new exit direction (for straight line)
277 
278  switch (GetTileType(tile)) {
279  case MP_RAILWAY: {
280  if (GetTileOwner(tile) != owner) continue; // do not propagate signals on others' tiles (remove for tracksharing)
281 
282  if (IsRailDepot(tile)) {
283  if (enterdir == INVALID_DIAGDIR) { // from 'inside' - train just entered or left the depot
284  if (!(flags & SF_TRAIN) && HasVehicleOnPos(tile, nullptr, &TrainOnTileEnum)) flags |= SF_TRAIN;
285  exitdir = GetRailDepotDirection(tile);
286  tile += TileOffsByDiagDir(exitdir);
287  enterdir = ReverseDiagDir(exitdir);
288  break;
289  } else if (enterdir == GetRailDepotDirection(tile)) { // entered a depot
290  if (!(flags & SF_TRAIN) && HasVehicleOnPos(tile, nullptr, &TrainOnTileEnum)) flags |= SF_TRAIN;
291  continue;
292  } else {
293  continue;
294  }
295  }
296 
297  assert(IsValidDiagDirection(enterdir));
298  TrackBits tracks = GetTrackBits(tile); // trackbits of tile
299  TrackBits tracks_masked = (TrackBits)(tracks & _enterdir_to_trackbits[enterdir]); // only incidating trackbits
300 
301  if (tracks == TRACK_BIT_HORZ || tracks == TRACK_BIT_VERT) { // there is exactly one incidating track, no need to check
302  tracks = tracks_masked;
303  /* If no train detected yet, and there is not no train -> there is a train -> set the flag */
304  if (!(flags & SF_TRAIN) && EnsureNoTrainOnTrackBits(tile, tracks).Failed()) flags |= SF_TRAIN;
305  } else {
306  if (tracks_masked == TRACK_BIT_NONE) continue; // no incidating track
307  if (!(flags & SF_TRAIN) && HasVehicleOnPos(tile, nullptr, &TrainOnTileEnum)) flags |= SF_TRAIN;
308  }
309 
310  if (HasSignals(tile)) { // there is exactly one track - not zero, because there is exit from this tile
311  Track track = TrackBitsToTrack(tracks_masked); // mask TRACK_BIT_X and Y too
312  if (HasSignalOnTrack(tile, track)) { // now check whole track, not trackdir
313  SignalType sig = GetSignalType(tile, track);
314  Trackdir trackdir = (Trackdir)FindFirstBit((tracks * 0x101) & _enterdir_to_trackdirbits[enterdir]);
315  Trackdir reversedir = ReverseTrackdir(trackdir);
316  /* add (tile, reversetrackdir) to 'to-be-updated' set when there is
317  * ANY conventional signal in REVERSE direction
318  * (if it is a presignal EXIT and it changes, it will be added to 'to-be-done' set later) */
319  if (HasSignalOnTrackdir(tile, reversedir)) {
320  if (IsPbsSignal(sig)) {
321  flags |= SF_PBS;
322  } else if (!_tbuset.Add(tile, reversedir)) {
323  return flags | SF_FULL;
324  }
325  }
326  if (HasSignalOnTrackdir(tile, trackdir) && !IsOnewaySignal(tile, track)) flags |= SF_PBS;
327 
328  /* if it is a presignal EXIT in OUR direction and we haven't found 2 green exits yes, do special check */
329  if (!(flags & SF_GREEN2) && IsPresignalExit(tile, track) && HasSignalOnTrackdir(tile, trackdir)) { // found presignal exit
330  if (flags & SF_EXIT) flags |= SF_EXIT2; // found two (or more) exits
331  flags |= SF_EXIT; // found at least one exit - allow for compiler optimizations
332  if (GetSignalStateByTrackdir(tile, trackdir) == SIGNAL_STATE_GREEN) { // found green presignal exit
333  if (flags & SF_GREEN) flags |= SF_GREEN2;
334  flags |= SF_GREEN;
335  }
336  }
337 
338  continue;
339  }
340  }
341 
342  for (DiagDirection dir = DIAGDIR_BEGIN; dir < DIAGDIR_END; dir++) { // test all possible exit directions
343  if (dir != enterdir && (tracks & _enterdir_to_trackbits[dir])) { // any track incidating?
344  TileIndex newtile = tile + TileOffsByDiagDir(dir); // new tile to check
345  DiagDirection newdir = ReverseDiagDir(dir); // direction we are entering from
346  if (!MaybeAddToTodoSet(newtile, newdir, tile, dir)) return flags | SF_FULL;
347  }
348  }
349 
350  continue; // continue the while() loop
351  }
352 
353  case MP_STATION:
354  if (!HasStationRail(tile)) continue;
355  if (GetTileOwner(tile) != owner) continue;
356  if (DiagDirToAxis(enterdir) != GetRailStationAxis(tile)) continue; // different axis
357  if (IsStationTileBlocked(tile)) continue; // 'eye-candy' station tile
358 
359  if (!(flags & SF_TRAIN) && HasVehicleOnPos(tile, nullptr, &TrainOnTileEnum)) flags |= SF_TRAIN;
360  tile += TileOffsByDiagDir(exitdir);
361  break;
362 
363  case MP_ROAD:
364  if (!IsLevelCrossing(tile)) continue;
365  if (GetTileOwner(tile) != owner) continue;
366  if (DiagDirToAxis(enterdir) == GetCrossingRoadAxis(tile)) continue; // different axis
367 
368  if (!(flags & SF_TRAIN) && HasVehicleOnPos(tile, nullptr, &TrainOnTileEnum)) flags |= SF_TRAIN;
369  tile += TileOffsByDiagDir(exitdir);
370  break;
371 
372  case MP_TUNNELBRIDGE: {
373  if (GetTileOwner(tile) != owner) continue;
374  if (GetTunnelBridgeTransportType(tile) != TRANSPORT_RAIL) continue;
376 
377  if (enterdir == INVALID_DIAGDIR) { // incoming from the wormhole
378  if (!(flags & SF_TRAIN) && HasVehicleOnPos(tile, nullptr, &TrainOnTileEnum)) flags |= SF_TRAIN;
379  enterdir = dir;
380  exitdir = ReverseDiagDir(dir);
381  tile += TileOffsByDiagDir(exitdir); // just skip to next tile
382  } else { // NOT incoming from the wormhole!
383  if (ReverseDiagDir(enterdir) != dir) continue;
384  if (!(flags & SF_TRAIN) && HasVehicleOnPos(tile, nullptr, &TrainOnTileEnum)) flags |= SF_TRAIN;
385  tile = GetOtherTunnelBridgeEnd(tile); // just skip to exit tile
386  enterdir = INVALID_DIAGDIR;
387  exitdir = INVALID_DIAGDIR;
388  }
389  }
390  break;
391 
392  default:
393  continue; // continue the while() loop
394  }
395 
396  if (!MaybeAddToTodoSet(tile, enterdir, oldtile, exitdir)) return flags | SF_FULL;
397  }
398 
399  return flags;
400 }
401 
402 
409 {
410  TileIndex tile;
411  Trackdir trackdir;
412 
413  while (_tbuset.Get(&tile, &trackdir)) {
414  assert(HasSignalOnTrackdir(tile, trackdir));
415 
416  SignalType sig = GetSignalType(tile, TrackdirToTrack(trackdir));
417  SignalState newstate = SIGNAL_STATE_GREEN;
418 
419  /* determine whether the new state is red */
420  if (flags & SF_TRAIN) {
421  /* train in the segment */
422  newstate = SIGNAL_STATE_RED;
423  } else {
424  /* is it a bidir combo? - then do not count its other signal direction as exit */
425  if (sig == SIGTYPE_COMBO && HasSignalOnTrackdir(tile, ReverseTrackdir(trackdir))) {
426  /* at least one more exit */
427  if ((flags & SF_EXIT2) &&
428  /* no green exit */
429  (!(flags & SF_GREEN) ||
430  /* only one green exit, and it is this one - so all other exits are red */
431  (!(flags & SF_GREEN2) && GetSignalStateByTrackdir(tile, ReverseTrackdir(trackdir)) == SIGNAL_STATE_GREEN))) {
432  newstate = SIGNAL_STATE_RED;
433  }
434  } else { // entry, at least one exit, no green exit
435  if (IsPresignalEntry(tile, TrackdirToTrack(trackdir)) && (flags & SF_EXIT) && !(flags & SF_GREEN)) newstate = SIGNAL_STATE_RED;
436  }
437  }
438 
439  /* only when the state changes */
440  if (newstate != GetSignalStateByTrackdir(tile, trackdir)) {
441  if (IsPresignalExit(tile, TrackdirToTrack(trackdir))) {
442  /* for pre-signal exits, add block to the global set */
443  DiagDirection exitdir = TrackdirToExitdir(ReverseTrackdir(trackdir));
444  _globset.Add(tile, exitdir); // do not check for full global set, first update all signals
445  }
446  SetSignalStateByTrackdir(tile, trackdir, newstate);
447  MarkTileDirtyByTile(tile);
448  }
449  }
450 
451 }
452 
453 
455 static inline void ResetSets()
456 {
457  _tbuset.Reset();
458  _tbdset.Reset();
459  _globset.Reset();
460 }
461 
462 
471 {
472  assert(Company::IsValidID(owner));
473 
474  bool first = true; // first block?
475  SigSegState state = SIGSEG_FREE; // value to return
476 
477  TileIndex tile;
478  DiagDirection dir;
479 
480  while (_globset.Get(&tile, &dir)) {
481  assert(_tbuset.IsEmpty());
482  assert(_tbdset.IsEmpty());
483 
484  /* After updating signal, data stored are always MP_RAILWAY with signals.
485  * Other situations happen when data are from outside functions -
486  * modification of railbits (including both rail building and removal),
487  * train entering/leaving block, train leaving depot...
488  */
489  switch (GetTileType(tile)) {
490  case MP_TUNNELBRIDGE:
491  /* 'optimization assert' - do not try to update signals when it is not needed */
493  assert(dir == INVALID_DIAGDIR || dir == ReverseDiagDir(GetTunnelBridgeDirection(tile)));
494  _tbdset.Add(tile, INVALID_DIAGDIR); // we can safely start from wormhole centre
496  break;
497 
498  case MP_RAILWAY:
499  if (IsRailDepot(tile)) {
500  /* 'optimization assert' do not try to update signals in other cases */
501  assert(dir == INVALID_DIAGDIR || dir == GetRailDepotDirection(tile));
502  _tbdset.Add(tile, INVALID_DIAGDIR); // start from depot inside
503  break;
504  }
505  FALLTHROUGH;
506 
507  case MP_STATION:
508  case MP_ROAD:
510  /* only add to set when there is some 'interesting' track */
511  _tbdset.Add(tile, dir);
512  _tbdset.Add(tile + TileOffsByDiagDir(dir), ReverseDiagDir(dir));
513  break;
514  }
515  FALLTHROUGH;
516 
517  default:
518  /* jump to next tile */
519  tile = tile + TileOffsByDiagDir(dir);
520  dir = ReverseDiagDir(dir);
522  _tbdset.Add(tile, dir);
523  break;
524  }
525  /* happens when removing a rail that wasn't connected at one or both sides */
526  continue; // continue the while() loop
527  }
528 
529  assert(!_tbdset.Overflowed()); // it really shouldn't overflow by these one or two items
530  assert(!_tbdset.IsEmpty()); // it wouldn't hurt anyone, but shouldn't happen too
531 
532  SigFlags flags = ExploreSegment(owner);
533 
534  if (first) {
535  first = false;
536  /* SIGSEG_FREE is set by default */
537  if (flags & SF_PBS) {
538  state = SIGSEG_PBS;
539  } else if ((flags & SF_TRAIN) || ((flags & SF_EXIT) && !(flags & SF_GREEN)) || (flags & SF_FULL)) {
540  state = SIGSEG_FULL;
541  }
542  }
543 
544  /* do not do anything when some buffer was full */
545  if (flags & SF_FULL) {
546  ResetSets(); // free all sets
547  break;
548  }
549 
551  }
552 
553  return state;
554 }
555 
556 
558 
559 
565 {
566  if (!_globset.IsEmpty()) {
568  _last_owner = INVALID_OWNER; // invalidate
569  }
570 }
571 
572 
580 void AddTrackToSignalBuffer(TileIndex tile, Track track, Owner owner)
581 {
582  static const DiagDirection _search_dir_1[] = {
584  };
585  static const DiagDirection _search_dir_2[] = {
587  };
588 
589  /* do not allow signal updates for two companies in one run */
590  assert(_globset.IsEmpty() || owner == _last_owner);
591 
592  _last_owner = owner;
593 
594  _globset.Add(tile, _search_dir_1[track]);
595  _globset.Add(tile, _search_dir_2[track]);
596 
597  if (_globset.Items() >= SIG_GLOB_UPDATE) {
598  /* too many items, force update */
599  UpdateSignalsInBuffer(_last_owner);
600  _last_owner = INVALID_OWNER;
601  }
602 }
603 
604 
613 {
614  /* do not allow signal updates for two companies in one run */
615  assert(_globset.IsEmpty() || owner == _last_owner);
616 
617  _last_owner = owner;
618 
619  _globset.Add(tile, side);
620 
621  if (_globset.Items() >= SIG_GLOB_UPDATE) {
622  /* too many items, force update */
623  UpdateSignalsInBuffer(_last_owner);
624  _last_owner = INVALID_OWNER;
625  }
626 }
627 
639 {
640  assert(_globset.IsEmpty());
641  _globset.Add(tile, side);
642 
643  return UpdateSignalsInBuffer(owner);
644 }
645 
646 
656 void SetSignalsOnBothDir(TileIndex tile, Track track, Owner owner)
657 {
658  assert(_globset.IsEmpty());
659 
660  AddTrackToSignalBuffer(tile, track, owner);
661  UpdateSignalsInBuffer(owner);
662 }
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...
Definition: signal.cpp:238
static TileType GetTileType(TileIndex tile)
Get the tiletype of a given tile.
Definition: tile_map.h:96
Owner
Enum for all companies/owners.
Definition: company_type.h:18
bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc)
Checks whether a vehicle is on a specific location.
Definition: vehicle.cpp:511
CommandCost EnsureNoTrainOnTrackBits(TileIndex tile, TrackBits track_bits)
Tests if a vehicle interacts with the specified track bits.
Definition: vehicle.cpp:599
Free and has no pre-signal exits or at least one green exit.
Definition: signal_func.h:50
presignal inter-block
Definition: signal_type.h:27
static bool HasSignalOnTrackdir(TileIndex tile, Trackdir trackdir)
Checks for the presence of signals along the given trackdir on the given rail tile.
Definition: rail_map.h:426
DECLARE_ENUM_AS_BIT_SET(GenderEthnicity) enum CompanyManagerFaceVariable
Bitgroups of the CompanyManagerFace variable.
void AddTrackToSignalBuffer(TileIndex tile, Track track, Owner owner)
Add track to signal update buffer.
Definition: signal.cpp:580
Definition of stuff that is very close to a company, like the company struct itself.
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...
Definition: signal.cpp:212
TrackdirBits
Enumeration of bitmasks for the TrackDirs.
Definition: track_type.h:101
static TransportType GetTunnelBridgeTransportType(TileIndex t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
bool IsEmpty()
Checks for empty set.
Definition: signal.cpp:88
Occupied by a train.
Definition: signal_func.h:51
Track upper, direction west.
Definition: track_type.h:112
SignalType
Type of signal, i.e.
Definition: signal_type.h:23
"Arrow" to the south-west
Definition: track_type.h:51
Maps accessors for stations.
SmallSet(const char *name)
Constructor - just set default values and &#39;name&#39;.
Definition: signal.cpp:66
An invalid owner.
Definition: company_type.h:29
static const uint SIG_GLOB_SIZE
number of open blocks (block can be opened more times until detected)
Definition: signal.cpp:25
static Owner _last_owner
last owner whose track was put into _globset
Definition: signal.cpp:557
bool Add(TileIndex tile, Tdir dir)
Adds tile & dir into the set, checks for full set Sets the &#39;overflowed&#39; flag if the set was full...
Definition: signal.cpp:152
Train vehicle type.
Definition: vehicle_type.h:24
Northwest.
static Track TrackdirToTrack(Trackdir trackdir)
Returns the Track that a given Trackdir represents.
Definition: track_func.h:270
Base for the train class.
static bool HasSignalOnTrack(TileIndex tile, Track track)
Checks for the presence of signals (either way) on the given track on the given rail tile...
Definition: rail_map.h:413
Used for iterations.
Functions related to debugging.
Trackdir
Enumeration for tracks and directions.
Definition: track_type.h:70
A tile with road (or tram tracks)
Definition: tile_type.h:43
SignalState
These are states in which a signal can be.
Definition: signal_type.h:44
static bool IsOnewaySignal(TileIndex t, Track track)
One-way signals can&#39;t be passed the &#39;wrong&#39; way.
Definition: rail_map.h:319
Functions related to vehicles.
void AddSideToSignalBuffer(TileIndex tile, DiagDirection side, Owner owner)
Add side of tile to signal update buffer.
Definition: signal.cpp:612
Vehicle data structure.
Definition: vehicle_base.h:210
static SmallSet< DiagDirection, SIG_TBD_SIZE > _tbdset("_tbdset")
set of open nodes in current signal block
static SigSegState UpdateSignalsInBuffer(Owner owner)
Updates blocks in _globset buffer.
Definition: signal.cpp:470
A railway.
Definition: tile_type.h:42
bool IsFull()
Checks for full set.
Definition: signal.cpp:97
void Reset()
Reset variables to default values.
Definition: signal.cpp:69
Flag for an invalid DiagDirection.
SigFlags
Current signal block state flags.
Definition: signal.cpp:247
static bool IsLevelCrossing(TileIndex t)
Return whether a tile is a level crossing.
Definition: road_map.h:84
"Arrow" to the north-east
Definition: track_type.h:49
static DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
Definition: track_func.h:447
static void SetSignalStateByTrackdir(TileIndex tile, Trackdir trackdir, SignalState state)
Sets the state of the signal along the given trackdir.
Definition: rail_map.h:449
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
static SmallSet< DiagDirection, SIG_GLOB_SIZE > _globset("_globset")
set of places to be updated in following runs
static const TrackdirBits _enterdir_to_trackdirbits[DIAGDIR_END]
incidating trackdirbits with given enterdir
Definition: signal.cpp:39
uint Items()
Reads the number of items.
Definition: signal.cpp:106
exitsignal found
Definition: signal.cpp:250
Functions related to (drawing on) viewports.
static bool HasStationRail(TileIndex t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint...
Definition: station_map.h:135
static Track TrackBitsToTrack(TrackBits tracks)
Converts TrackBits to Track.
Definition: track_func.h:201
two or more green exits found
Definition: signal.cpp:253
static SigFlags ExploreSegment(Owner owner)
Search signal block.
Definition: signal.cpp:267
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:341
Southeast.
Segment is a PBS segment.
Definition: signal_func.h:52
bool Remove(TileIndex tile, Tdir dir)
Tries to remove first instance of given tile and dir.
Definition: signal.cpp:118
Track right, direction north.
Definition: track_type.h:115
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:178
static DiagDirection GetRailDepotDirection(TileIndex t)
Returns the direction the depot is facing to.
Definition: rail_map.h:171
static DiagDirection ReverseDiagDir(DiagDirection d)
Returns the reverse direction of the given DiagDirection.
Left and right track.
Definition: track_type.h:48
Track left, direction south.
Definition: track_type.h:107
Definition of base types and functions in a cross-platform compatible way.
Track y-axis, direction south-east.
Definition: track_type.h:104
A number of safeguards to prevent using unsafe methods.
green exitsignal found
Definition: signal.cpp:252
static Axis GetRailStationAxis(TileIndex t)
Get the rail direction of a rail station.
Definition: station_map.h:337
static Axis GetCrossingRoadAxis(TileIndex t)
Get the road axis of a level crossing.
Definition: road_map.h:325
static bool IsValidDiagDirection(DiagDirection d)
Checks if an integer value is a valid DiagDirection.
static const uint SIG_TBD_SIZE
number of intersections - open nodes in current block
Definition: signal.cpp:24
TrackBits
Bitfield corresponding to Track.
Definition: track_type.h:38
static void ResetSets()
Reset all sets after one set overflowed.
Definition: signal.cpp:455
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Definition: viewport.cpp:1938
static const uint SIG_TBU_SIZE
these are the maximums used for updating signal blocks
Definition: signal.cpp:23
Set containing &#39;items&#39; items of &#39;tile and Tdir&#39; No tree structure is used because it would cause slow...
Definition: signal.cpp:52
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:40
Track left, direction north.
Definition: track_type.h:114
static SmallSet< Trackdir, SIG_TBU_SIZE > _tbuset("_tbuset")
set of signals that will be updated
static DiagDirection GetTunnelBridgeDirection(TileIndex t)
Get the direction pointing to the other end.
bool Failed() const
Did this command fail?
Definition: command_type.h:159
static Trackdir ReverseTrackdir(Trackdir trackdir)
Maps a trackdir to the reverse trackdir.
Definition: track_func.h:255
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
Returns information about trackdirs and signal states.
Definition: landscape.cpp:589
static bool HasSignals(TileIndex t)
Checks if a rail tile has signals.
Definition: rail_map.h:72
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:35
uint8 FindFirstBit(uint32 x)
Search the first set bit in a 32 bit variable.
static TrackBits GetTrackBits(TileIndex tile)
Gets the track bits of the given tile.
Definition: rail_map.h:136
Bitflag for a depot.
Definition: track_type.h:56
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
static TileIndex GetOtherTunnelBridgeEnd(TileIndex t)
Determines type of the wormhole and returns its other end.
Transport by train.
Element of set.
Definition: signal.cpp:59
No track.
Definition: track_type.h:39
Track lower, direction east.
Definition: track_type.h:106
static bool IsRailDepot(TileIndex t)
Is this rail tile a rail depot?
Definition: rail_map.h:95
bool IsStationTileBlocked(TileIndex tile)
Check whether a rail station tile is NOT traversable.
Tunnel entry/exit and bridge heads.
Definition: tile_type.h:50
static const TrackBits _enterdir_to_trackbits[DIAGDIR_END]
incidating trackbits with given enterdir
Definition: signal.cpp:31
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
Used for iterations.
Track
These are used to specify a single track.
Definition: track_type.h:19
bool Get(TileIndex *tile, Tdir *dir)
Reads the last added element into the set.
Definition: signal.cpp:173
bool Overflowed()
Returns value of &#39;overflowed&#39;.
Definition: signal.cpp:79
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...
Definition: signal.cpp:638
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:52
A tile of a station.
Definition: tile_type.h:46
"Arrow" to the south-east
Definition: track_type.h:50
bool IsIn(TileIndex tile, Tdir dir)
Tries to find given tile and dir in the set.
Definition: signal.cpp:136
static TrackBits TrackStatusToTrackBits(TrackStatus ts)
Returns the present-track-information of a TrackStatus.
Definition: track_func.h:371
SigSegState
State of the signal segment.
Definition: signal_func.h:49
Track x-axis, direction south-west.
Definition: track_type.h:110
Track y-axis, direction north-west.
Definition: track_type.h:111
The signal is red.
Definition: signal_type.h:45
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:280
train found in segment
Definition: signal.cpp:249
Functions that have tunnels and bridges in common.
void SetSignalsOnBothDir(TileIndex tile, Track track, Owner owner)
Update signals at segments that are at both ends of given (existent or non-existent) track...
Definition: signal.cpp:656
Track lower, direction west.
Definition: track_type.h:113
DiagDirection
Enumeration for diagonal directions.
Track upper, direction east.
Definition: track_type.h:105
Northeast, upper right on your monitor.
two or more exits found
Definition: signal.cpp:251
Track x-axis, direction north-east.
Definition: track_type.h:103
static SignalState GetSignalStateByTrackdir(TileIndex tile, Trackdir trackdir)
Gets the state of the signal along the given trackdir.
Definition: rail_map.h:438
static void UpdateSignalsAroundSegment(SigFlags flags)
Update signals around segment in _tbuset.
Definition: signal.cpp:408
static const uint SIG_GLOB_UPDATE
how many items need to be in _globset to force update
Definition: signal.cpp:26
"Arrow" to the north-west
Definition: track_type.h:52
static Vehicle * TrainOnTileEnum(Vehicle *v, void *)
Check whether there is a train on rail, not in a depot.
Definition: signal.cpp:191
pbs signal found
Definition: signal.cpp:255
Track right, direction south.
Definition: track_type.h:108
The signal is green.
Definition: signal_type.h:46
Southwest.
Upper and lower track.
Definition: track_type.h:47
some of buffers was full, do not continue
Definition: signal.cpp:254