From 3e511f2ce73f28b1aabdce1bf86e84b323546e86 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Sat, 22 Feb 2025 12:28:07 +0100 Subject: [PATCH] Codechange: remove ZeroedMemoryAllocator from GRFFile --- src/economy.cpp | 2 +- src/economy_type.h | 2 +- src/newgrf.cpp | 4 +--- src/newgrf.h | 41 ++++++++++++++++++++--------------------- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/economy.cpp b/src/economy.cpp index 12fe4c3079..adc2227edb 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -886,7 +886,7 @@ static void HandleEconomyFluctuations() */ void ResetPriceBaseMultipliers() { - memset(_price_base_multiplier, 0, sizeof(_price_base_multiplier)); + _price_base_multiplier.fill(0); } /** diff --git a/src/economy_type.h b/src/economy_type.h index 07c60b75d1..73ed746e47 100644 --- a/src/economy_type.h +++ b/src/economy_type.h @@ -172,7 +172,7 @@ enum Price : uint8_t { DECLARE_INCREMENT_DECREMENT_OPERATORS(Price) typedef Money Prices[PR_END]; ///< Prices of everything. @see Price -typedef int8_t PriceMultipliers[PR_END]; +using PriceMultipliers = std::array; /** Types of expenses. */ enum ExpensesType : uint8_t { diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 7e20b20585..153bbce7ae 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -9213,9 +9213,7 @@ GRFFile::GRFFile(const GRFConfig &config) this->traininfo_vehicle_width = TRAININFO_DEFAULT_VEHICLE_WIDTH; /* Mark price_base_multipliers as 'not set' */ - for (Price i = PR_BEGIN; i < PR_END; i++) { - this->price_base_multipliers[i] = INVALID_PRICE_MODIFIER; - } + this->price_base_multipliers.fill(INVALID_PRICE_MODIFIER); /* Initialise rail type map with default rail types */ this->railtype_map.fill(INVALID_RAILTYPE); diff --git a/src/newgrf.h b/src/newgrf.h index 481b7d5c0a..0c360e9082 100644 --- a/src/newgrf.h +++ b/src/newgrf.h @@ -18,7 +18,6 @@ #include "newgrf_callbacks.h" #include "newgrf_text_type.h" #include "core/bitmath_func.hpp" -#include "core/alloc_type.hpp" #include "core/mem_func.hpp" /** @@ -109,13 +108,13 @@ struct GRFLabel { }; /** Dynamic data of a loaded NewGRF */ -struct GRFFile : ZeroedMemoryAllocator { - std::string filename; - uint32_t grfid; - uint8_t grf_version; +struct GRFFile { + std::string filename{}; + uint32_t grfid = 0; + uint8_t grf_version = 0; - uint sound_offset; - uint16_t num_sounds; + uint sound_offset = 0; + uint16_t num_sounds = 0; std::vector> stations; std::vector> housespec; @@ -126,34 +125,34 @@ struct GRFFile : ZeroedMemoryAllocator { std::vector> airtspec; std::vector> roadstops; - std::vector param; + std::vector param{}; - std::vector labels; ///< List of labels + std::vector labels{}; ///< List of labels - std::vector cargo_list; ///< Cargo translation table (local ID -> label) + std::vector cargo_list{}; ///< Cargo translation table (local ID -> label) std::array cargo_map{}; ///< Inverse cargo translation table (CargoType -> local ID) - std::vector badge_list; ///< Badge translation table (local index -> global index) - std::unordered_map badge_map; + std::vector badge_list{}; ///< Badge translation table (local index -> global index) + std::unordered_map badge_map{}; - std::vector railtype_list; ///< Railtype translation table + std::vector railtype_list{}; ///< Railtype translation table std::array railtype_map{}; - std::vector roadtype_list; ///< Roadtype translation table (road) + std::vector roadtype_list{}; ///< Roadtype translation table (road) std::array roadtype_map{}; - std::vector tramtype_list; ///< Roadtype translation table (tram) + std::vector tramtype_list{}; ///< Roadtype translation table (tram) std::array tramtype_map{}; - CanalProperties canal_local_properties[CF_END]; ///< Canal properties as set by this NewGRF + std::array canal_local_properties{}; ///< Canal properties as set by this NewGRF - std::unordered_map language_map; ///< Mappings related to the languages. + std::unordered_map language_map{}; ///< Mappings related to the languages. - int traininfo_vehicle_pitch; ///< Vertical offset for drawing train images in depot GUI and vehicle details - uint traininfo_vehicle_width; ///< Width (in pixels) of a 8/8 train vehicle in depot GUI and vehicle details + int traininfo_vehicle_pitch = 0; ///< Vertical offset for drawing train images in depot GUI and vehicle details + uint traininfo_vehicle_width = 0; ///< Width (in pixels) of a 8/8 train vehicle in depot GUI and vehicle details - uint32_t grf_features; ///< Bitset of GrfSpecFeature the grf uses - PriceMultipliers price_base_multipliers; ///< Price base multipliers as set by the grf. + uint32_t grf_features = 0; ///< Bitset of GrfSpecFeature the grf uses + PriceMultipliers price_base_multipliers{}; ///< Price base multipliers as set by the grf. GRFFile(const struct GRFConfig &config);