Codechange: Use member initialization of GRFFilePropsBase. (#12581)

Don't blame compilers for our sloppy initialisation.

Removes memset, and lengthof.
This commit is contained in:
Peter Nelson 2024-04-26 22:58:54 +01:00 committed by GitHub
parent 72c55128d2
commit bf8de188ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 16 deletions

View File

@ -308,25 +308,15 @@ bool Convert8bitBooleanCallback(const struct GRFFile *grffile, uint16_t cbid, ui
*/
template <size_t Tcnt>
struct GRFFilePropsBase {
GRFFilePropsBase() : local_id(0), grffile(nullptr)
{
/* The lack of some compilers to provide default constructors complying to the specs
* requires us to zero the stuff ourself. */
memset(spritegroup, 0, sizeof(spritegroup));
}
uint16_t local_id; ///< id defined by the grf file for this entity
const struct GRFFile *grffile; ///< grf file that introduced this entity
const struct SpriteGroup *spritegroup[Tcnt]; ///< pointer to the different sprites of the entity
uint16_t local_id = 0; ///< id defined by the grf file for this entity
const struct GRFFile *grffile = nullptr; ///< grf file that introduced this entity
std::array<const struct SpriteGroup *, Tcnt> spritegroup{}; ///< pointers to the different sprites of the entity
};
/** Data related to the handling of grf files. */
struct GRFFileProps : GRFFilePropsBase<1> {
/** Set all default data constructor for the props. */
GRFFileProps(uint16_t subst_id = 0) :
GRFFilePropsBase<1>(), subst_id(subst_id), override(subst_id)
{
}
constexpr GRFFileProps(uint16_t subst_id = 0) : subst_id(subst_id), override(subst_id) {}
uint16_t subst_id;
uint16_t override; ///< id of the entity been replaced by

View File

@ -53,7 +53,7 @@ const SpriteGroup *GetWagonOverrideSpriteSet(EngineID engine, CargoID cargo, Eng
void SetCustomEngineSprites(EngineID engine, uint8_t cargo, const SpriteGroup *group)
{
Engine *e = Engine::Get(engine);
assert(cargo < lengthof(e->grf_prop.spritegroup));
assert(cargo < std::size(e->grf_prop.spritegroup));
if (e->grf_prop.spritegroup[cargo] != nullptr) {
GrfMsg(6, "SetCustomEngineSprites: engine {} cargo {} already has group -- replacing", engine, cargo);
@ -1062,7 +1062,7 @@ VehicleResolverObject::VehicleResolverObject(EngineID engine_type, const Vehicle
if (this->root_spritegroup == nullptr) {
const Engine *e = Engine::Get(engine_type);
CargoID cargo = v != nullptr ? v->cargo_type : SpriteGroupCargo::SG_PURCHASE;
assert(cargo < lengthof(e->grf_prop.spritegroup));
assert(cargo < std::size(e->grf_prop.spritegroup));
this->root_spritegroup = e->grf_prop.spritegroup[cargo] != nullptr ? e->grf_prop.spritegroup[cargo] : e->grf_prop.spritegroup[SpriteGroupCargo::SG_DEFAULT];
}
}