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.

(cherry picked from commit bd1a20f6ee)
This commit is contained in:
Peter Nelson
2021-05-01 18:07:47 +01:00
committed by Jonathan G Rennison
parent 2e6cadb005
commit 72bc8c7595
4 changed files with 44 additions and 76 deletions

View File

@@ -112,17 +112,17 @@ enum StationRandomTrigger {
};
enum StationSpecIntlFlags {
SSIF_COPIED_LAYOUTS, ///< Copied StationLayout **layouts.
SSIF_BRIDGE_HEIGHTS_SET, ///< byte bridge_height[8] is set.
SSIF_BRIDGE_HEIGHTS_SET, ///< byte bridge_height[8] is set.
SSIF_BRIDGE_DISALLOWED_PILLARS_SET, ///< byte bridge_disallowed_pillars[8] is set.
};
/* 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}), internal_flags(0) {}
/**
* Properties related the the grf file.
* NUM_CARGO real cargo plus three pseudo cargo sprite groups.
@@ -175,10 +175,17 @@ struct StationSpec {
AnimationInfo animation;
byte lengths;
byte *platforms;
StationLayout **layouts;
byte internal_flags; ///< Bitmask of internal spec flags (StationSpecIntlFlags)
/**
* 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. */