Compare commits

...

2 Commits

Author SHA1 Message Date
Peter Nelson bf8de188ec
Codechange: Use member initialization of GRFFilePropsBase. (#12581)
Don't blame compilers for our sloppy initialisation.

Removes memset, and lengthof.
2024-04-26 22:58:54 +01:00
Peter Nelson 72c55128d2
Codechange: Remove write-only spec_id from RoadStopSpec. (#12582)
Comment is incorrect about its value too.
2024-04-26 21:56:30 +01:00
4 changed files with 6 additions and 18 deletions

View File

@ -4846,7 +4846,6 @@ static ChangeInfoResult RoadStopChangeInfo(uint id, int numinfo, int prop, ByteR
uint32_t classid = buf->ReadDWord(); uint32_t classid = buf->ReadDWord();
rs->cls_id = RoadStopClass::Allocate(BSWAP32(classid)); rs->cls_id = RoadStopClass::Allocate(BSWAP32(classid));
rs->spec_id = id + i;
break; break;
} }

View File

@ -308,25 +308,15 @@ bool Convert8bitBooleanCallback(const struct GRFFile *grffile, uint16_t cbid, ui
*/ */
template <size_t Tcnt> template <size_t Tcnt>
struct GRFFilePropsBase { struct GRFFilePropsBase {
GRFFilePropsBase() : local_id(0), grffile(nullptr) 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
/* The lack of some compilers to provide default constructors complying to the specs std::array<const struct SpriteGroup *, Tcnt> spritegroup{}; ///< pointers to the different sprites of the entity
* 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
}; };
/** Data related to the handling of grf files. */ /** Data related to the handling of grf files. */
struct GRFFileProps : GRFFilePropsBase<1> { struct GRFFileProps : GRFFilePropsBase<1> {
/** Set all default data constructor for the props. */ /** Set all default data constructor for the props. */
GRFFileProps(uint16_t subst_id = 0) : constexpr GRFFileProps(uint16_t subst_id = 0) : subst_id(subst_id), override(subst_id) {}
GRFFilePropsBase<1>(), subst_id(subst_id), override(subst_id)
{
}
uint16_t subst_id; uint16_t subst_id;
uint16_t override; ///< id of the entity been replaced by 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) void SetCustomEngineSprites(EngineID engine, uint8_t cargo, const SpriteGroup *group)
{ {
Engine *e = Engine::Get(engine); 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) { if (e->grf_prop.spritegroup[cargo] != nullptr) {
GrfMsg(6, "SetCustomEngineSprites: engine {} cargo {} already has group -- replacing", engine, cargo); 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) { if (this->root_spritegroup == nullptr) {
const Engine *e = Engine::Get(engine_type); const Engine *e = Engine::Get(engine_type);
CargoID cargo = v != nullptr ? v->cargo_type : SpriteGroupCargo::SG_PURCHASE; 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]; this->root_spritegroup = e->grf_prop.spritegroup[cargo] != nullptr ? e->grf_prop.spritegroup[cargo] : e->grf_prop.spritegroup[SpriteGroupCargo::SG_DEFAULT];
} }
} }

View File

@ -127,7 +127,6 @@ struct RoadStopSpec {
*/ */
GRFFilePropsBase<NUM_CARGO + 3> grf_prop; GRFFilePropsBase<NUM_CARGO + 3> grf_prop;
RoadStopClassID cls_id; ///< The class to which this spec belongs. RoadStopClassID cls_id; ///< The class to which this spec belongs.
int spec_id; ///< The ID of this spec inside the class.
StringID name; ///< Name of this stop StringID name; ///< Name of this stop
RoadStopAvailabilityType stop_type = ROADSTOPTYPE_ALL; RoadStopAvailabilityType stop_type = ROADSTOPTYPE_ALL;