Change: Store station blocked/wires/pylons flags in map. (#11337)

This stores three flags in unused map bits, and avoids having to look up
station graphics and custom station specs to determine blocked/wires/pylons
status.

This potentially affects rail pathfinding performance.

Savegame version is not bumped, as the flags can just be updated every
time.
This commit is contained in:
Peter Nelson
2023-09-30 12:30:25 +01:00
committed by GitHub
parent fd79d34ba9
commit b5dc9328f2
8 changed files with 124 additions and 51 deletions

View File

@@ -329,6 +329,78 @@ static inline bool IsHangarTile(Tile t)
return IsTileType(t, MP_STATION) && IsHangar(t);
}
/**
* Is tile \a t a blocked tile?
* @pre HasStationRail(t)
* @param t Tile to check
* @return \c true if the tile is blocked
*/
static inline bool IsStationTileBlocked(Tile t)
{
assert(HasStationRail(t));
return HasBit(t.m6(), 0);
}
/**
* Set the blocked state of the rail station
* @pre HasStationRail(t)
* @param t the station tile
* @param b the blocked state
*/
static inline void SetStationTileBlocked(Tile t, bool b)
{
assert(HasStationRail(t));
SB(t.m6(), 0, 1, b ? 1 : 0);
}
/**
* Can tile \a t have catenary wires?
* @pre HasStationRail(t)
* @param t Tile to check
* @return \c true if the tile can have catenary wires
*/
static inline bool CanStationTileHaveWires(Tile t)
{
assert(HasStationRail(t));
return HasBit(t.m6(), 6);
}
/**
* Set the catenary wires state of the rail station
* @pre HasStationRail(t)
* @param t the station tile
* @param b the catenary wires state
*/
static inline void SetStationTileHaveWires(Tile t, bool b)
{
assert(HasStationRail(t));
SB(t.m6(), 6, 1, b ? 1 : 0);
}
/**
* Can tile \a t have catenary pylons?
* @pre HasStationRail(t)
* @param t Tile to check
* @return \c true if the tile can have catenary pylons
*/
static inline bool CanStationTileHavePylons(Tile t)
{
assert(HasStationRail(t));
return HasBit(t.m6(), 7);
}
/**
* Set the catenary pylon state of the rail station
* @pre HasStationRail(t)
* @param t the station tile
* @param b the catenary pylons state
*/
static inline void SetStationTileHavePylons(Tile t, bool b)
{
assert(HasStationRail(t));
SB(t.m6(), 7, 1, b ? 1 : 0);
}
/**
* Get the rail direction of a rail station.
* @param t Tile to query
@@ -379,10 +451,10 @@ static inline TrackBits GetRailStationTrackBits(Tile t)
static inline bool IsCompatibleTrainStationTile(Tile test_tile, Tile station_tile)
{
assert(IsRailStationTile(station_tile));
return IsRailStationTile(test_tile) && IsCompatibleRail(GetRailType(test_tile), GetRailType(station_tile)) &&
return IsRailStationTile(test_tile) && !IsStationTileBlocked(test_tile) &&
IsCompatibleRail(GetRailType(test_tile), GetRailType(station_tile)) &&
GetRailStationAxis(test_tile) == GetRailStationAxis(station_tile) &&
GetStationIndex(test_tile) == GetStationIndex(station_tile) &&
!IsStationTileBlocked(test_tile);
GetStationIndex(test_tile) == GetStationIndex(station_tile);
}
/**