From 61aff3fa4940f6d9631311787cabc3a62284ab42 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Thu, 14 Nov 2024 19:05:18 +0000 Subject: [PATCH] Codechange: Limit industry default cargo label lists to original slot counts. (#13072) IndustrySpec and IndustryTileSpec cargo label lists are only used for original industries. Original industries can only have up to 2 inputs and 3 outputs. Therefore having space for 16 input/outputs slots is unnecessary This saves 216 bytes per industry type, and 164 bytes per industry tile type. --- src/industrytype.h | 8 +++++--- src/newgrf.cpp | 12 ++++++------ src/table/build_industry.h | 8 +++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/industrytype.h b/src/industrytype.h index b299851c10..d637d6a100 100644 --- a/src/industrytype.h +++ b/src/industrytype.h @@ -106,7 +106,6 @@ struct IndustrySpec { IndustryType conflicting[3]; ///< Industries this industry cannot be close to uint8_t check_proc; ///< Index to a procedure to check for conflicting circumstances std::array produced_cargo; - std::variant produced_cargo_label[INDUSTRY_NUM_OUTPUTS]; uint8_t production_rate[INDUSTRY_NUM_OUTPUTS]; /** * minimum amount of cargo transported to the stations. @@ -114,7 +113,6 @@ struct IndustrySpec { */ uint8_t minimal_cargo; std::array accepts_cargo; ///< 16 accepted cargoes. - std::variant accepts_cargo_label[INDUSTRY_NUM_INPUTS]; uint16_t input_cargo_multiplier[INDUSTRY_NUM_INPUTS][INDUSTRY_NUM_OUTPUTS]; ///< Input cargo multipliers (multiply amount of incoming cargo for the produced cargoes) IndustryLifeType life_type; ///< This is also known as Industry production flag, in newgrf specs uint8_t climate_availability; ///< Bitmask, giving landscape enums as bit position @@ -134,6 +132,9 @@ struct IndustrySpec { GRFFileProps grf_prop; ///< properties related to the grf file std::vector random_sounds; ///< Random sounds; + std::array, INDUSTRY_ORIGINAL_NUM_OUTPUTS> produced_cargo_label; ///< Cargo labels of produced cargo for default industries. + std::array, INDUSTRY_ORIGINAL_NUM_INPUTS> accepts_cargo_label; ///< Cargo labels of accepted cargo for default industries. + bool IsRawIndustry() const; bool IsProcessingIndustry() const; Money GetConstructionCost() const; @@ -147,7 +148,6 @@ struct IndustrySpec { */ struct IndustryTileSpec { std::array accepts_cargo; ///< Cargo accepted by this tile - std::array, INDUSTRY_NUM_INPUTS> accepts_cargo_label; std::array acceptance; ///< Level of acceptance per cargo type (signed, may be negative!) Slope slopes_refused; ///< slope pattern on which this tile cannot be built uint8_t anim_production; ///< Animation frame to start when goods are produced @@ -163,6 +163,8 @@ struct IndustryTileSpec { IndustryTileSpecialFlags special_flags; ///< Bitmask of extra flags used by the tile bool enabled; ///< entity still available (by default true).newgrf can disable it, though GRFFileProps grf_prop; ///< properties related to the grf file + + std::array, INDUSTRY_ORIGINAL_NUM_INPUTS> accepts_cargo_label; ///< Cargo labels of accepted cargo for default industry tiles. }; /* industry_cmd.cpp*/ diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 7795f20c73..f9ee7b788c 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -3380,7 +3380,7 @@ static ChangeInfoResult IndustrytilesChangeInfo(uint indtid, int numinfo, int pr tsp->accepts_cargo[i] = INVALID_CARGO; tsp->acceptance[i] = 0; } - tsp->accepts_cargo_label[i] = CT_INVALID; + if (i < std::size(tsp->accepts_cargo_label)) tsp->accepts_cargo_label[i] = CT_INVALID; } break; } @@ -3821,7 +3821,7 @@ static ChangeInfoResult IndustriesChangeInfo(uint indid, int numinfo, int prop, } else { indsp->produced_cargo[i] = INVALID_CARGO; } - indsp->produced_cargo_label[i] = CT_INVALID; + if (i < std::size(indsp->produced_cargo_label)) indsp->produced_cargo_label[i] = CT_INVALID; } break; } @@ -3840,7 +3840,7 @@ static ChangeInfoResult IndustriesChangeInfo(uint indid, int numinfo, int prop, } else { indsp->accepts_cargo[i] = INVALID_CARGO; } - indsp->accepts_cargo_label[i] = CT_INVALID; + if (i < std::size(indsp->accepts_cargo_label)) indsp->accepts_cargo_label[i] = CT_INVALID; } break; } @@ -9457,17 +9457,17 @@ static void FinaliseIndustriesArray() } /* Apply default cargo translation map for unset cargo slots */ - for (size_t i = 0; i < std::size(indsp.produced_cargo); ++i) { + for (size_t i = 0; i < std::size(indsp.produced_cargo_label); ++i) { if (!IsValidCargoID(indsp.produced_cargo[i])) indsp.produced_cargo[i] = GetCargoIDByLabel(GetActiveCargoLabel(indsp.produced_cargo_label[i])); } - for (size_t i = 0; i < std::size(indsp.accepts_cargo); ++i) { + for (size_t i = 0; i < std::size(indsp.accepts_cargo_label); ++i) { if (!IsValidCargoID(indsp.accepts_cargo[i])) indsp.accepts_cargo[i] = GetCargoIDByLabel(GetActiveCargoLabel(indsp.accepts_cargo_label[i])); } } for (auto &indtsp : _industry_tile_specs) { /* Apply default cargo translation map for unset cargo slots */ - for (size_t i = 0; i < indtsp.accepts_cargo.size(); ++i) { + for (size_t i = 0; i < std::size(indtsp.accepts_cargo_label); ++i) { if (!IsValidCargoID(indtsp.accepts_cargo[i])) indtsp.accepts_cargo[i] = GetCargoIDByLabel(GetActiveCargoLabel(indtsp.accepts_cargo_label[i])); } } diff --git a/src/table/build_industry.h b/src/table/build_industry.h index 116d3bad3f..92aba105c0 100644 --- a/src/table/build_industry.h +++ b/src/table/build_industry.h @@ -1129,13 +1129,12 @@ enum IndustryTypes { c1, c2, c3, proc, p1, r1, p2, r2, m, a1, im1, a2, im2, a3, im3, pr, clim, bev, in, intx, s1, s2, s3) \ {tbl, d, 0, pc, {c1, c2, c3}, proc, \ {INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO}, \ - {p1, p2, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID}, \ {r1, r2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, m, \ {INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO}, \ - {a1, a2, a3, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID}, \ {{im1, 0}, {im2, 0}, {im3, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, \ pr, clim, bev, col, in, intx, s1, s2, s3, STR_UNDEFINED, {ai1, ai2, ai3, ai4}, {ag1, ag2, ag3, ag4}, \ - 0, true, GRFFileProps(INVALID_INDUSTRYTYPE), snd} + 0, true, GRFFileProps(INVALID_INDUSTRYTYPE), snd, \ + {{p1, p2}}, {{a1, a2, a3}}} /* Format: tile table count and sounds table cost multiplier appear chances(4ingame, 4random) map colour @@ -1534,8 +1533,7 @@ static const IndustrySpec _origin_industry_specs[NEW_INDUSTRYOFFSET] = { */ #define MT(ca1, c1, ca2, c2, ca3, c3, sl, a1, a2, a3) { \ {INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO}, \ - {c1, c2, c3, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID}, \ - {ca1, ca2, ca3}, sl, a1, a2, a3, 0, {0, ANIM_STATUS_NO_ANIMATION, 2, 0}, INDTILE_SPECIAL_NONE, true, GRFFileProps(INVALID_INDUSTRYTILE) \ + {ca1, ca2, ca3}, sl, a1, a2, a3, 0, {0, ANIM_STATUS_NO_ANIMATION, 2, 0}, INDTILE_SPECIAL_NONE, true, GRFFileProps(INVALID_INDUSTRYTILE), {c1, c2, c3} \ } static const IndustryTileSpec _origin_industry_tile_specs[NEW_INDUSTRYTILEOFFSET] = { /* Coal Mine */