Codechange: Shuffle members of Vehicle to reduce size.

This reduces space wasted due to member alignment.
This commit is contained in:
Peter Nelson 2024-03-14 20:40:33 +00:00 committed by Peter Nelson
parent 3fc7b3b9a0
commit 322ca6ef54
4 changed files with 16 additions and 18 deletions

View File

@ -113,10 +113,9 @@ struct RoadVehicle final : public GroundVehicle<RoadVehicle, VEH_ROAD> {
uint16_t crashed_ctr; ///< Animation counter when the vehicle has crashed. @see RoadVehIsCrashed
uint8_t reverse_ctr;
RoadType roadtype; //!< Roadtype of this vehicle.
RoadTypes compatible_roadtypes; //!< Roadtypes this consist is powered on.
RoadType roadtype; ///< NOSAVE: Roadtype of this vehicle.
VehicleID disaster_vehicle = INVALID_VEHICLE; ///< NOSAVE: Disaster vehicle targetting this vehicle.
RoadTypes compatible_roadtypes; ///< NOSAVE: Roadtypes this consist is powered on.
/** We don't want GCC to zero our struct! It already is zeroed and has an index! */
RoadVehicle() : GroundVehicleBase() {}

View File

@ -22,8 +22,8 @@ typedef std::deque<Trackdir> ShipPathCache;
* All ships have this type.
*/
struct Ship final : public SpecializedVehicle<Ship, VEH_SHIP> {
TrackBits state; ///< The "track" the ship is following.
ShipPathCache path; ///< Cached path.
TrackBits state; ///< The "track" the ship is following.
Direction rotation; ///< Visible direction.
int16_t rotation_x_pos; ///< NOSAVE: X Position before rotation.
int16_t rotation_y_pos; ///< NOSAVE: Y Position before rotation.

View File

@ -85,21 +85,20 @@ struct TrainCache {
* 'Train' is either a loco or a wagon.
*/
struct Train final : public GroundVehicle<Train, VEH_TRAIN> {
uint16_t flags;
uint16_t crash_anim_pos; ///< Crash animation counter.
uint16_t wait_counter; ///< Ticks waiting in front of a signal, ticks being stuck or a counter for forced proceeding through signals.
TrainCache tcache;
/* Link between the two ends of a multiheaded engine */
Train *other_multiheaded_part;
uint16_t crash_anim_pos; ///< Crash animation counter.
RailTypes compatible_railtypes;
RailType railtype;
uint16_t flags;
TrackBits track;
TrainForceProceeding force_proceed;
RailType railtype;
RailTypes compatible_railtypes;
/** Ticks waiting in front of a signal, ticks being stuck or a counter for forced proceeding through signals. */
uint16_t wait_counter;
/** We don't want GCC to zero our struct! It already is zeroed and has an index! */
Train() : GroundVehicleBase() {}

View File

@ -191,8 +191,8 @@ struct VehicleSpriteSeq {
struct MutableSpriteCache {
Direction last_direction; ///< Last direction we obtained sprites for
bool revalidate_before_draw; ///< We need to do a GetImage() and check bounds before drawing this sprite
Rect old_coord; ///< Co-ordinates from the last valid bounding box
bool is_viewport_candidate; ///< This vehicle can potentially be drawn on a viewport
Rect old_coord; ///< Co-ordinates from the last valid bounding box
VehicleSpriteSeq sprite_seq; ///< Vehicle appearance.
};
@ -327,26 +327,28 @@ public:
uint32_t motion_counter; ///< counter to occasionally play a vehicle sound.
uint8_t progress; ///< The percentage (if divided by 256) this vehicle already crossed the tile unit.
uint16_t random_bits; ///< Bits used for randomized variational spritegroups.
uint8_t waiting_triggers; ///< Triggers to be yet matched before rerandomizing the random bits.
uint16_t random_bits; ///< Bits used for randomized variational spritegroups.
StationID last_station_visited; ///< The last station we stopped at.
StationID last_loading_station; ///< Last station the vehicle has stopped at and could possibly leave from with any cargo loaded.
TimerGameTick::TickCounter last_loading_tick; ///< Last TimerGameTick::counter tick that the vehicle has stopped at a station and could possibly leave with any cargo loaded.
VehicleCargoList cargo; ///< The cargo this vehicle is carrying
CargoID cargo_type; ///< type of cargo this vehicle is carrying
uint8_t cargo_subtype; ///< Used for livery refits (NewGRF variations)
uint16_t cargo_cap; ///< total capacity
uint16_t refit_cap; ///< Capacity left over from before last refit.
VehicleCargoList cargo; ///< The cargo this vehicle is carrying
uint16_t cargo_age_counter; ///< Ticks till cargo is aged next.
int8_t trip_occupancy; ///< NOSAVE: Occupancy of vehicle of the current trip (updated after leaving a station).
uint8_t day_counter; ///< Increased by one for each day
uint8_t tick_counter; ///< Increased by one for each tick
uint8_t running_ticks; ///< Number of ticks this vehicle was not stopped this day
uint16_t load_unload_ticks; ///< Ticks to wait before starting next cycle.
uint8_t vehstatus; ///< Status
uint8_t subtype; ///< subtype (Filled with values from #AircraftSubType/#DisasterSubType/#EffectVehicleType/#GroundVehicleSubtypeFlags)
Order current_order; ///< The current order (+ status, like: loading)
union {
@ -354,13 +356,11 @@ public:
Order *old_orders; ///< Only used during conversion of old save games
};
uint16_t load_unload_ticks; ///< Ticks to wait before starting next cycle.
GroupID group_id; ///< Index of group Pool array
uint8_t subtype; ///< subtype (Filled with values from #AircraftSubType/#DisasterSubType/#EffectVehicleType/#GroundVehicleSubtypeFlags)
NewGRFCache grf_cache; ///< Cache of often used calculated NewGRF values
VehicleCache vcache; ///< Cache of often used vehicle values.
GroupID group_id; ///< Index of group Pool array
mutable MutableSpriteCache sprite_cache; ///< Cache of sprites and values related to recalculating them, see #MutableSpriteCache
/**