mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Store station layout tiles as std::span.
Using std::span provides both the start and end of the list, which allows validating that the requested layout is in range.
This commit is contained in:
parent
6e98c5c26a
commit
52ad5d86f7
|
@ -2885,7 +2885,9 @@ static CommandCost RemoveDock(TileIndex tile, DoCommandFlag flags)
|
|||
|
||||
const DrawTileSprites *GetStationTileLayout(StationType st, uint8_t gfx)
|
||||
{
|
||||
return &_station_display_datas[st][gfx];
|
||||
const auto layouts = _station_display_datas[st];
|
||||
if (gfx < layouts.size()) return layouts.data() + gfx;
|
||||
return layouts.data();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,7 +28,7 @@ static const StationID INVALID_STATION = 0xFFFF;
|
|||
typedef SmallStack<StationID, StationID, INVALID_STATION, 8, 0xFFFD> StationIDStack;
|
||||
|
||||
/** Station types */
|
||||
enum StationType {
|
||||
enum StationType : uint8_t {
|
||||
STATION_RAIL,
|
||||
STATION_AIRPORT,
|
||||
STATION_TRUCK,
|
||||
|
@ -37,6 +37,7 @@ enum StationType {
|
|||
STATION_DOCK,
|
||||
STATION_BUOY,
|
||||
STATION_WAYPOINT,
|
||||
STATION_END,
|
||||
};
|
||||
|
||||
/** Types of RoadStops */
|
||||
|
|
|
@ -990,7 +990,7 @@ static const DrawTileSprites _station_display_datas_waypoint[] = {
|
|||
* As these are drawn/build like stations, they may use the same number of layouts. */
|
||||
static_assert(lengthof(_station_display_datas_rail) == lengthof(_station_display_datas_waypoint));
|
||||
|
||||
static const DrawTileSprites * const _station_display_datas[] = {
|
||||
static const std::array<std::span<const DrawTileSprites>, STATION_END> _station_display_datas = {{
|
||||
_station_display_datas_rail,
|
||||
_station_display_datas_airport,
|
||||
_station_display_datas_truck,
|
||||
|
@ -999,4 +999,4 @@ static const DrawTileSprites * const _station_display_datas[] = {
|
|||
_station_display_datas_dock,
|
||||
_station_display_datas_buoy,
|
||||
_station_display_datas_waypoint,
|
||||
};
|
||||
}};
|
||||
|
|
Loading…
Reference in New Issue