MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / UpdateSignalsInBuffer

Function UpdateSignalsInBuffer

src/signal.cpp:479–563  ·  view source on GitHub ↗

* Updates blocks in _globset buffer * * @param owner company whose signals we are updating * @return state of the first block from _globset * @pre Company::IsValidID(owner) */

Source from the content-addressed store, hash-verified

477 * @pre Company::IsValidID(owner)
478 */
479static SigSegState UpdateSignalsInBuffer(Owner owner)
480{
481 assert(Company::IsValidID(owner));
482
483 bool first = true; // first block?
484 SigSegState state = SIGSEG_FREE; // value to return
485
486 TileIndex tile = INVALID_TILE; // Stop GCC from complaining about a possibly uninitialized variable (issue #8280).
487 DiagDirection dir = INVALID_DIAGDIR;
488
489 while (_globset.Get(&tile, &dir)) {
490 assert(_tbuset.IsEmpty());
491 assert(_tbdset.IsEmpty());
492
493 /* After updating signal, data stored are always MP_RAILWAY with signals.
494 * Other situations happen when data are from outside functions -
495 * modification of railbits (including both rail building and removal),
496 * train entering/leaving block, train leaving depot...
497 */
498 switch (GetTileType(tile)) {
499 case MP_TUNNELBRIDGE:
500 /* 'optimization assert' - do not try to update signals when it is not needed */
501 assert(GetTunnelBridgeTransportType(tile) == TRANSPORT_RAIL);
502 assert(dir == INVALID_DIAGDIR || dir == ReverseDiagDir(GetTunnelBridgeDirection(tile)));
503 _tbdset.Add(tile, INVALID_DIAGDIR); // we can safely start from wormhole centre
504 _tbdset.Add(GetOtherTunnelBridgeEnd(tile), INVALID_DIAGDIR);
505 break;
506
507 case MP_RAILWAY:
508 if (IsRailDepot(tile)) {
509 /* 'optimization assert' do not try to update signals in other cases */
510 assert(dir == INVALID_DIAGDIR || dir == GetRailDepotDirection(tile));
511 _tbdset.Add(tile, INVALID_DIAGDIR); // start from depot inside
512 break;
513 }
514 [[fallthrough]];
515
516 case MP_STATION:
517 case MP_ROAD:
518 if ((TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_RAIL, 0)) & _enterdir_to_trackbits[dir]) != TRACK_BIT_NONE) {
519 /* only add to set when there is some 'interesting' track */
520 _tbdset.Add(tile, dir);
521 _tbdset.Add(tile + TileOffsByDiagDir(dir), ReverseDiagDir(dir));
522 break;
523 }
524 [[fallthrough]];
525
526 default:
527 /* jump to next tile */
528 tile = tile + TileOffsByDiagDir(dir);
529 dir = ReverseDiagDir(dir);
530 if ((TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_RAIL, 0)) & _enterdir_to_trackbits[dir]) != TRACK_BIT_NONE) {
531 _tbdset.Add(tile, dir);
532 break;
533 }
534 /* happens when removing a rail that wasn't connected at one or both sides */
535 continue; // continue the while() loop
536 }

Callers 9

DoFloodTileFunction · 0.85
AddTrackToSignalBufferFunction · 0.85
AddSideToSignalBufferFunction · 0.85
UpdateSignalsOnSegmentFunction · 0.85
SetSignalsOnBothDirFunction · 0.85
DisasterClearSquareFunction · 0.85

Calls 15

GetTileTypeFunction · 0.85
ReverseDiagDirFunction · 0.85
GetTunnelBridgeDirectionFunction · 0.85
GetOtherTunnelBridgeEndFunction · 0.85
IsRailDepotFunction · 0.85
GetRailDepotDirectionFunction · 0.85
TrackStatusToTrackBitsFunction · 0.85
GetTileTrackStatusFunction · 0.85
TileOffsByDiagDirFunction · 0.85
ExploreSegmentFunction · 0.85
ResetSetsFunction · 0.85

Tested by

no test coverage detected