diff options
author | Peter Nelson <peter1138@openttd.org> | 2021-05-01 18:07:47 +0100 |
---|---|---|
committer | PeterN <peter@fuzzle.org> | 2021-05-02 17:15:27 +0100 |
commit | bd1a20f6eee6758f6a812af18fbe5b41b491b5c4 (patch) | |
tree | 02d7a3f6a4aebae631c323d0e6493116c060d678 /src/newgrf_station.h | |
parent | 1f159f79de7428cbaa6133ec9cf06ce559980ea6 (diff) | |
download | openttd-bd1a20f6eee6758f6a812af18fbe5b41b491b5c4.tar.xz |
Codechange: Use std::vector for NewGRF station platform layouts.
This avoids the need to custom memory management and additional members.
This also resolves use-after-free if modifying copied layouts, so presumably nobody has ever done that.
Diffstat (limited to 'src/newgrf_station.h')
-rw-r--r-- | src/newgrf_station.h | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/newgrf_station.h b/src/newgrf_station.h index fac5d64dd..4c4a5831b 100644 --- a/src/newgrf_station.h +++ b/src/newgrf_station.h @@ -109,12 +109,13 @@ enum StationRandomTrigger { SRT_PATH_RESERVATION, ///< Trigger platform when train reserves path. }; -/* Station layout for given dimensions - it is a two-dimensional array - * where index is computed as (x * platforms) + platform. */ -typedef byte *StationLayout; - /** Station specification. */ struct StationSpec { + StationSpec() : cls_id(STAT_CLASS_DFLT), name(0), + disallowed_platforms(0), disallowed_lengths(0), tiles(0), + renderdata(nullptr), cargo_threshold(0), cargo_triggers(0), + callback_mask(0), flags(0), pylons(0), wires(0), blocked(0), + animation({0, 0, 0, 0}) {} /** * Properties related the the grf file. * NUM_CARGO real cargo plus three pseudo cargo sprite groups. @@ -165,10 +166,15 @@ struct StationSpec { AnimationInfo animation; - byte lengths; - byte *platforms; - StationLayout **layouts; - bool copied_layouts; + /** + * Custom platform layouts. + * This is a 2D array containing an array of tiles. + * 1st layer is platform lengths. + * 2nd layer is tracks (width). + * These can be sparsely populated, and the upper limit is not defined but + * limited to 255. + */ + std::vector<std::vector<std::vector<byte>>> layouts; }; /** Struct containing information relating to station classes. */ |