mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use std::array for temporary NewGRF loading data.
This allows initialisation without memset.pull/13787/head
parent
761c587940
commit
ec71f7a216
|
@ -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)
|
int skip_sprites; ///< Number of pseudo sprites to skip before processing the next one. (-1 to skip to end of file)
|
||||||
|
|
||||||
/* Currently referenceable spritegroups */
|
/* Currently referenceable spritegroups */
|
||||||
const SpriteGroup *spritegroups[MAX_SPRITEGROUP + 1];
|
std::array<const SpriteGroup *, MAX_SPRITEGROUP + 1> spritegroups{};
|
||||||
|
|
||||||
/** Clear temporary data before processing the next file in the current loading stage */
|
/** Clear temporary data before processing the next file in the current loading stage */
|
||||||
void ClearDataForNextFile()
|
void ClearDataForNextFile()
|
||||||
|
@ -127,7 +127,7 @@ public:
|
||||||
this->spritesets[i].clear();
|
this->spritesets[i].clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(this->spritegroups, 0, sizeof(this->spritegroups));
|
this->spritegroups = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -354,10 +354,10 @@ static ReferenceThroughBaseContainer<std::vector<GRFTempEngineData>> _gted; ///
|
||||||
* Contains the GRF ID of the owner of a vehicle if it has been reserved.
|
* 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,
|
* GRM for vehicles is only used if dynamic engine allocation is disabled,
|
||||||
* so 256 is the number of original engines. */
|
* so 256 is the number of original engines. */
|
||||||
static uint32_t _grm_engines[256];
|
static std::array<uint32_t, 256> _grm_engines{};
|
||||||
|
|
||||||
/** Contains the GRF ID of the owner of a cargo if it has been reserved */
|
/** 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<uint32_t, NUM_CARGO * 2> _grm_cargoes{};
|
||||||
|
|
||||||
struct GRFLocation {
|
struct GRFLocation {
|
||||||
uint32_t grfid;
|
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<uint32_t> grm, uint16_t count, uint8_t op, uint8_t target, const char *type)
|
||||||
{
|
{
|
||||||
uint start = 0;
|
uint start = 0;
|
||||||
uint size = 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 */
|
/* 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);
|
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) {
|
if (grm[i] == 0) {
|
||||||
size++;
|
size++;
|
||||||
} else {
|
} else {
|
||||||
|
@ -7819,7 +7819,7 @@ static void ParamSet(ByteReader &buf)
|
||||||
case 0x02: // Ships
|
case 0x02: // Ships
|
||||||
case 0x03: // Aircraft
|
case 0x03: // Aircraft
|
||||||
if (!_settings_game.vehicle.dynamic_engines) {
|
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;
|
if (_cur.skip_sprites == -1) return;
|
||||||
} else {
|
} else {
|
||||||
/* GRM does not apply for dynamic engine allocation. */
|
/* GRM does not apply for dynamic engine allocation. */
|
||||||
|
@ -7856,7 +7856,7 @@ static void ParamSet(ByteReader &buf)
|
||||||
|
|
||||||
case 0x0B: // Cargo
|
case 0x0B: // Cargo
|
||||||
/* There are two ranges: one for cargo IDs and one for cargo bitmasks */
|
/* 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;
|
if (_cur.skip_sprites == -1) return;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -9082,8 +9082,8 @@ void ResetNewGRFData()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reset GRM reservations */
|
/* Reset GRM reservations */
|
||||||
memset(&_grm_engines, 0, sizeof(_grm_engines));
|
_grm_engines = {};
|
||||||
memset(&_grm_cargoes, 0, sizeof(_grm_cargoes));
|
_grm_cargoes = {};
|
||||||
|
|
||||||
/* Reset generic feature callback lists */
|
/* Reset generic feature callback lists */
|
||||||
ResetGenericCallbacks();
|
ResetGenericCallbacks();
|
||||||
|
|
Loading…
Reference in New Issue