diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 43e2e663fd..ad1b327588 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -115,7 +115,7 @@ public: int skip_sprites; ///< Number of pseudo sprites to skip before processing the next one. (-1 to skip to end of file) /* Currently referenceable spritegroups */ - const SpriteGroup *spritegroups[MAX_SPRITEGROUP + 1]; + std::array spritegroups{}; /** Clear temporary data before processing the next file in the current loading stage */ void ClearDataForNextFile() @@ -127,7 +127,7 @@ public: this->spritesets[i].clear(); } - memset(this->spritegroups, 0, sizeof(this->spritegroups)); + this->spritegroups = {}; } /** @@ -354,10 +354,10 @@ static ReferenceThroughBaseContainer> _gted; /// * Contains the GRF ID of the owner of a vehicle if it has been reserved. * GRM for vehicles is only used if dynamic engine allocation is disabled, * so 256 is the number of original engines. */ -static uint32_t _grm_engines[256]; +static std::array _grm_engines{}; /** Contains the GRF ID of the owner of a cargo if it has been reserved */ -static uint32_t _grm_cargoes[NUM_CARGO * 2]; +static std::array _grm_cargoes{}; struct GRFLocation { uint32_t grfid; @@ -7687,7 +7687,7 @@ static uint32_t GetPatchVariable(uint8_t param) } -static uint32_t PerformGRM(uint32_t *grm, uint16_t num_ids, uint16_t count, uint8_t op, uint8_t target, const char *type) +static uint32_t PerformGRM(std::span grm, uint16_t count, uint8_t op, uint8_t target, const char *type) { uint start = 0; uint size = 0; @@ -7700,7 +7700,7 @@ static uint32_t PerformGRM(uint32_t *grm, uint16_t num_ids, uint16_t count, uint /* With an operation of 2 or 3, we want to reserve a specific block of IDs */ if (op == 2 || op == 3) start = _cur.grffile->GetParam(target); - for (uint i = start; i < num_ids; i++) { + for (uint i = start; i < std::size(grm); i++) { if (grm[i] == 0) { size++; } else { @@ -7819,7 +7819,7 @@ static void ParamSet(ByteReader &buf) case 0x02: // Ships case 0x03: // Aircraft if (!_settings_game.vehicle.dynamic_engines) { - src1 = PerformGRM(&_grm_engines[_engine_offsets[feature]], _engine_counts[feature], count, op, target, "vehicles"); + src1 = PerformGRM({std::begin(_grm_engines) + _engine_offsets[feature], _engine_counts[feature]}, count, op, target, "vehicles"); if (_cur.skip_sprites == -1) return; } else { /* GRM does not apply for dynamic engine allocation. */ @@ -7856,7 +7856,7 @@ static void ParamSet(ByteReader &buf) case 0x0B: // Cargo /* There are two ranges: one for cargo IDs and one for cargo bitmasks */ - src1 = PerformGRM(_grm_cargoes, NUM_CARGO * 2, count, op, target, "cargoes"); + src1 = PerformGRM(_grm_cargoes, count, op, target, "cargoes"); if (_cur.skip_sprites == -1) return; break; @@ -9082,8 +9082,8 @@ void ResetNewGRFData() } /* Reset GRM reservations */ - memset(&_grm_engines, 0, sizeof(_grm_engines)); - memset(&_grm_cargoes, 0, sizeof(_grm_cargoes)); + _grm_engines = {}; + _grm_cargoes = {}; /* Reset generic feature callback lists */ ResetGenericCallbacks();