From e3f8ff78b883f66ea7d9d1da498243a34e61ad59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Thu, 25 Nov 2021 23:25:04 -0800 Subject: [PATCH] Move entity serialisation functions (#16003) --- src/openrct2/entity/Balloon.cpp | 10 + src/openrct2/entity/Duck.cpp | 10 + src/openrct2/entity/Entity.cpp | 281 +--------------------------- src/openrct2/entity/EntityBase.h | 2 + src/openrct2/entity/Fountain.cpp | 13 ++ src/openrct2/entity/Litter.cpp | 9 + src/openrct2/entity/MoneyEffect.cpp | 13 ++ src/openrct2/entity/Particle.cpp | 41 ++++ src/openrct2/peep/Guest.cpp | 57 ++++++ src/openrct2/peep/Peep.cpp | 44 +++++ src/openrct2/peep/Peep.h | 2 + src/openrct2/peep/Staff.cpp | 15 ++ src/openrct2/ride/Vehicle.cpp | 64 +++++++ 13 files changed, 287 insertions(+), 274 deletions(-) diff --git a/src/openrct2/entity/Balloon.cpp b/src/openrct2/entity/Balloon.cpp index 46c37af892..e94a96f17e 100644 --- a/src/openrct2/entity/Balloon.cpp +++ b/src/openrct2/entity/Balloon.cpp @@ -11,6 +11,7 @@ #include "../Game.h" #include "../audio/audio.h" +#include "../core/DataSerialiser.h" #include "../network/network.h" #include "../scenario/Scenario.h" #include "../util/Util.h" @@ -96,3 +97,12 @@ void Balloon::Create(const CoordsXYZ& balloonPos, int32_t colour, bool isPopped) balloon->colour = colour; balloon->popped = (isPopped ? 1 : 0); } + +void Balloon::Serialise(DataSerialiser& stream) +{ + EntityBase::Serialise(stream); + stream << frame; + stream << popped; + stream << time_to_move; + stream << colour; +} diff --git a/src/openrct2/entity/Duck.cpp b/src/openrct2/entity/Duck.cpp index fc20164eaf..17e989bb33 100644 --- a/src/openrct2/entity/Duck.cpp +++ b/src/openrct2/entity/Duck.cpp @@ -10,6 +10,7 @@ #include "../Game.h" #include "../audio/audio.h" +#include "../core/DataSerialiser.h" #include "../localisation/Date.h" #include "../scenario/Scenario.h" #include "../sprites.h" @@ -352,3 +353,12 @@ void Duck::RemoveAll() duck->Remove(); } } + +void Duck::Serialise(DataSerialiser& stream) +{ + EntityBase::Serialise(stream); + stream << frame; + stream << target_x; + stream << target_y; + stream << state; +} diff --git a/src/openrct2/entity/Entity.cpp b/src/openrct2/entity/Entity.cpp index 2ff4271df1..36b314bd85 100644 --- a/src/openrct2/entity/Entity.cpp +++ b/src/openrct2/entity/Entity.cpp @@ -19,279 +19,12 @@ #include "MoneyEffect.h" #include "Particle.h" -static void EntityBaseSerialise(EntityBase& base, DataSerialiser& stream) +void EntityBase::Serialise(DataSerialiser& stream) { - stream << base.Type; - stream << base.sprite_index; - stream << base.x; - stream << base.y; - stream << base.z; - stream << base.sprite_direction; -} - -void Litter::Serialise(DataSerialiser& stream) -{ - EntityBaseSerialise(*this, stream); - stream << SubType; - stream << creationTick; -} - -void Balloon::Serialise(DataSerialiser& stream) -{ - EntityBaseSerialise(*this, stream); - stream << frame; - stream << popped; - stream << time_to_move; - stream << colour; -} - -void Duck::Serialise(DataSerialiser& stream) -{ - EntityBaseSerialise(*this, stream); - stream << frame; - stream << target_x; - stream << target_y; - stream << state; -} - -void MoneyEffect::Serialise(DataSerialiser& stream) -{ - EntityBaseSerialise(*this, stream); - stream << frame; - stream << MoveDelay; - stream << NumMovements; - stream << Vertical; - stream << Value; - stream << OffsetX; - stream << Wiggle; -} - -void VehicleCrashParticle::Serialise(DataSerialiser& stream) -{ - EntityBaseSerialise(*this, stream); - stream << frame; - stream << time_to_live; - stream << colour; - stream << crashed_sprite_base; - stream << velocity_x; - stream << velocity_y; - stream << velocity_z; - stream << acceleration_x; - stream << acceleration_y; - stream << acceleration_z; -} - -void ExplosionFlare::Serialise(DataSerialiser& stream) -{ - EntityBaseSerialise(*this, stream); - stream << frame; -} - -void ExplosionCloud::Serialise(DataSerialiser& stream) -{ - EntityBaseSerialise(*this, stream); - stream << frame; -} - -void CrashSplashParticle::Serialise(DataSerialiser& stream) -{ - EntityBaseSerialise(*this, stream); - stream << frame; -} - -void SteamParticle::Serialise(DataSerialiser& stream) -{ - EntityBaseSerialise(*this, stream); - stream << frame; - stream << time_to_move; -} - -void JumpingFountain::Serialise(DataSerialiser& stream) -{ - EntityBaseSerialise(*this, stream); - stream << frame; - stream << FountainType; - stream << NumTicksAlive; - stream << FountainFlags; - stream << TargetX; - stream << TargetY; - stream << Iteration; -} - -static void PeepBaseSerialise(Peep& base, DataSerialiser& stream) -{ - EntityBaseSerialise(base, stream); - if (stream.IsLoading()) - { - base.Name = nullptr; - } - stream << base.NextLoc; - stream << base.NextFlags; - stream << base.State; - stream << base.SubState; - stream << base.SpriteType; - stream << base.TshirtColour; - stream << base.TrousersColour; - stream << base.DestinationX; - stream << base.DestinationY; - stream << base.DestinationTolerance; - stream << base.Var37; - stream << base.Energy; - stream << base.EnergyTarget; - stream << base.Mass; - // stream << base.WindowInvalidateFlags; - stream << base.CurrentRide; - stream << base.CurrentRideStation; - stream << base.CurrentTrain; - stream << base.CurrentCar; - stream << base.CurrentSeat; - stream << base.SpecialSprite; - stream << base.ActionSpriteType; - stream << base.NextActionSpriteType; - stream << base.ActionSpriteImageOffset; - stream << base.Action; - stream << base.ActionFrame; - stream << base.StepProgress; - stream << base.PeepDirection; - stream << base.InteractionRideIndex; - stream << base.Id; - stream << base.PathCheckOptimisation; - stream << base.PathfindGoal; - stream << base.PathfindHistory; - stream << base.WalkingFrameNum; - stream << base.PeepFlags; -} - -void Guest::Serialise(DataSerialiser& stream) -{ - PeepBaseSerialise(*this, stream); - stream << GuestNumRides; - stream << GuestNextInQueue; - stream << ParkEntryTime; - stream << GuestHeadingToRideId; - stream << GuestIsLostCountdown; - stream << GuestTimeOnRide; - stream << PaidToEnter; - stream << PaidOnRides; - stream << PaidOnFood; - stream << PaidOnDrink; - stream << PaidOnSouvenirs; - stream << OutsideOfPark; - stream << Happiness; - stream << HappinessTarget; - stream << Nausea; - stream << NauseaTarget; - stream << Hunger; - stream << Thirst; - stream << Toilet; - stream << TimeToConsume; - stream << Intensity; - stream << NauseaTolerance; - stream << TimeInQueue; - stream << CashInPocket; - stream << CashSpent; - stream << Photo1RideRef; - stream << Photo2RideRef; - stream << Photo3RideRef; - stream << Photo4RideRef; - stream << RejoinQueueTimeout; - stream << PreviousRide; - stream << PreviousRideTimeOut; - stream << Thoughts; - stream << LitterCount; - stream << DisgustingCount; - stream << AmountOfFood; - stream << AmountOfDrinks; - stream << AmountOfSouvenirs; - stream << VandalismSeen; - stream << VoucherType; - stream << VoucherRideId; - stream << SurroundingsThoughtTimeout; - stream << Angriness; - stream << TimeLost; - stream << DaysInQueue; - stream << BalloonColour; - stream << UmbrellaColour; - stream << HatColour; - stream << FavouriteRide; - stream << FavouriteRideRating; - stream << ItemFlags; -} - -void Staff::Serialise(DataSerialiser& stream) -{ - PeepBaseSerialise(*this, stream); - stream << AssignedStaffType; - stream << MechanicTimeSinceCall; - stream << HireDate; - stream << StaffOrders; - stream << StaffMowingTimeout; - stream << StaffLawnsMown; - stream << StaffGardensWatered; - stream << StaffLitterSwept; - stream << StaffBinsEmptied; -} - -void Vehicle::Serialise(DataSerialiser& stream) -{ - EntityBaseSerialise(*this, stream); - stream << SubType; - stream << Pitch; - stream << bank_rotation; - stream << remaining_distance; - stream << velocity; - stream << acceleration; - stream << ride; - stream << vehicle_type; - stream << colours; - stream << track_progress; - stream << TrackTypeAndDirection; - stream << TrackLocation; - stream << next_vehicle_on_train; - stream << prev_vehicle_on_ride; - stream << next_vehicle_on_ride; - stream << var_44; - stream << mass; - stream << update_flags; - stream << SwingSprite; - stream << current_station; - stream << SwingPosition; - stream << SwingSpeed; - stream << status; - stream << sub_state; - stream << peep; - stream << peep_tshirt_colours; - stream << num_seats; - stream << num_peeps; - stream << next_free_seat; - stream << restraints_position; - stream << spin_speed; - stream << sound2_flags; - stream << spin_sprite; - stream << sound1_id; - stream << sound1_volume; - stream << sound2_id; - stream << sound2_volume; - stream << sound_vector_factor; - stream << var_C0; - stream << speed; - stream << powered_acceleration; - stream << dodgems_collision_direction; - stream << animation_frame; - stream << animationState; - stream << scream_sound_id; - stream << TrackSubposition; - stream << var_CE; - stream << var_CF; - stream << lost_time_out; - stream << vertical_drop_countdown; - stream << var_D3; - stream << mini_golf_current_animation; - stream << mini_golf_flags; - stream << ride_subtype; - stream << colours_extended; - stream << seat_rotation; - stream << target_seat_rotation; - stream << BoatLocation; - stream << IsCrashedVehicle; + stream << Type; + stream << sprite_index; + stream << x; + stream << y; + stream << z; + stream << sprite_direction; } diff --git a/src/openrct2/entity/EntityBase.h b/src/openrct2/entity/EntityBase.h index 254b58aee8..4e0c1004f3 100644 --- a/src/openrct2/entity/EntityBase.h +++ b/src/openrct2/entity/EntityBase.h @@ -68,4 +68,6 @@ struct EntityBase { return Is() ? reinterpret_cast(this) : nullptr; } + + void Serialise(class DataSerialiser& stream); }; diff --git a/src/openrct2/entity/Fountain.cpp b/src/openrct2/entity/Fountain.cpp index 9d804d7057..28be2ad737 100644 --- a/src/openrct2/entity/Fountain.cpp +++ b/src/openrct2/entity/Fountain.cpp @@ -10,6 +10,7 @@ #include "Fountain.h" #include "../Game.h" +#include "../core/DataSerialiser.h" #include "../scenario/Scenario.h" #include "../world/Footpath.h" #include "../world/Map.h" @@ -379,3 +380,15 @@ void JumpingFountain::CreateNext(const CoordsXYZ& newLoc, int32_t direction) con } JumpingFountain::Create(newType, newLoc, direction >> 1, newFlags, Iteration); } + +void JumpingFountain::Serialise(DataSerialiser& stream) +{ + EntityBase::Serialise(stream); + stream << frame; + stream << FountainType; + stream << NumTicksAlive; + stream << FountainFlags; + stream << TargetX; + stream << TargetY; + stream << Iteration; +} diff --git a/src/openrct2/entity/Litter.cpp b/src/openrct2/entity/Litter.cpp index 9ddecf9700..9c6d32c5eb 100644 --- a/src/openrct2/entity/Litter.cpp +++ b/src/openrct2/entity/Litter.cpp @@ -2,6 +2,7 @@ #include "../Cheats.h" #include "../Game.h" +#include "../core/DataSerialiser.h" #include "../localisation/StringIds.h" #include "../world/Map.h" #include "EntityList.h" @@ -130,3 +131,11 @@ uint32_t Litter::GetAge() const { return gCurrentTicks - creationTick; } + +void Litter::Serialise(DataSerialiser& stream) +{ + EntityBase::Serialise(stream); + + stream << SubType; + stream << creationTick; +} diff --git a/src/openrct2/entity/MoneyEffect.cpp b/src/openrct2/entity/MoneyEffect.cpp index 10327bdc6b..3eef69df90 100644 --- a/src/openrct2/entity/MoneyEffect.cpp +++ b/src/openrct2/entity/MoneyEffect.cpp @@ -9,6 +9,7 @@ #include "MoneyEffect.h" #include "../OpenRCT2.h" +#include "../core/DataSerialiser.h" #include "../drawing/Drawing.h" #include "../interface/Viewport.h" #include "../interface/Window.h" @@ -152,3 +153,15 @@ std::pair MoneyEffect::GetStringId() const return std::make_pair(stringId, outValue); } + +void MoneyEffect::Serialise(DataSerialiser& stream) +{ + EntityBase::Serialise(stream); + stream << frame; + stream << MoveDelay; + stream << NumMovements; + stream << Vertical; + stream << Value; + stream << OffsetX; + stream << Wiggle; +} diff --git a/src/openrct2/entity/Particle.cpp b/src/openrct2/entity/Particle.cpp index a1690662e4..f2182c3072 100644 --- a/src/openrct2/entity/Particle.cpp +++ b/src/openrct2/entity/Particle.cpp @@ -9,6 +9,7 @@ #include "Particle.h" #include "../audio/audio.h" +#include "../core/DataSerialiser.h" #include "../paint/sprite/Paint.Sprite.h" #include "../scenario/Scenario.h" #include "EntityRegistry.h" @@ -113,6 +114,21 @@ void VehicleCrashParticle::Update() } } +void VehicleCrashParticle::Serialise(DataSerialiser& stream) +{ + EntityBase::Serialise(stream); + stream << frame; + stream << time_to_live; + stream << colour; + stream << crashed_sprite_base; + stream << velocity_x; + stream << velocity_y; + stream << velocity_z; + stream << acceleration_x; + stream << acceleration_y; + stream << acceleration_z; +} + /** * * rct2: 0x00673699 @@ -144,6 +160,12 @@ void CrashSplashParticle::Update() } } +void CrashSplashParticle::Serialise(DataSerialiser& stream) +{ + EntityBase::Serialise(stream); + stream << frame; +} + /** * * rct2: 0x006734B2 @@ -187,6 +209,13 @@ void SteamParticle::Update() } } +void SteamParticle::Serialise(DataSerialiser& stream) +{ + EntityBase::Serialise(stream); + stream << frame; + stream << time_to_move; +} + /** * * rct2: 0x0067363D @@ -218,6 +247,12 @@ void ExplosionCloud::Update() } } +void ExplosionCloud::Serialise(DataSerialiser& stream) +{ + EntityBase::Serialise(stream); + stream << frame; +} + /** * * rct2: 0x0067366B @@ -248,3 +283,9 @@ void ExplosionFlare::Update() EntityRemove(this); } } + +void ExplosionFlare::Serialise(DataSerialiser& stream) +{ + EntityBase::Serialise(stream); + stream << frame; +} diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index cf7da6bcc8..e263a19ac6 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -14,6 +14,7 @@ #include "../OpenRCT2.h" #include "../audio/audio.h" #include "../config/Config.h" +#include "../core/DataSerialiser.h" #include "../core/Guard.hpp" #include "../core/Numerics.hpp" #include "../entity/Balloon.h" @@ -7484,3 +7485,59 @@ void Guest::RemoveRideFromMemory(ride_id_t rideId) lastEntry.item = PeepThoughtItemNone; } } + +void Guest::Serialise(DataSerialiser& stream) +{ + Peep::Serialise(stream); + stream << GuestNumRides; + stream << GuestNextInQueue; + stream << ParkEntryTime; + stream << GuestHeadingToRideId; + stream << GuestIsLostCountdown; + stream << GuestTimeOnRide; + stream << PaidToEnter; + stream << PaidOnRides; + stream << PaidOnFood; + stream << PaidOnDrink; + stream << PaidOnSouvenirs; + stream << OutsideOfPark; + stream << Happiness; + stream << HappinessTarget; + stream << Nausea; + stream << NauseaTarget; + stream << Hunger; + stream << Thirst; + stream << Toilet; + stream << TimeToConsume; + stream << Intensity; + stream << NauseaTolerance; + stream << TimeInQueue; + stream << CashInPocket; + stream << CashSpent; + stream << Photo1RideRef; + stream << Photo2RideRef; + stream << Photo3RideRef; + stream << Photo4RideRef; + stream << RejoinQueueTimeout; + stream << PreviousRide; + stream << PreviousRideTimeOut; + stream << Thoughts; + stream << LitterCount; + stream << DisgustingCount; + stream << AmountOfFood; + stream << AmountOfDrinks; + stream << AmountOfSouvenirs; + stream << VandalismSeen; + stream << VoucherType; + stream << VoucherRideId; + stream << SurroundingsThoughtTimeout; + stream << Angriness; + stream << TimeLost; + stream << DaysInQueue; + stream << BalloonColour; + stream << UmbrellaColour; + stream << HatColour; + stream << FavouriteRide; + stream << FavouriteRideRating; + stream << ItemFlags; +} diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index cc5af343f6..e10cb1eec1 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -2631,3 +2631,47 @@ CoordsXY Peep::GetDestination() const { return CoordsXY{ DestinationX, DestinationY }; } + +void Peep::Serialise(DataSerialiser& stream) +{ + EntityBase::Serialise(stream); + if (stream.IsLoading()) + { + Name = nullptr; + } + stream << NextLoc; + stream << NextFlags; + stream << State; + stream << SubState; + stream << SpriteType; + stream << TshirtColour; + stream << TrousersColour; + stream << DestinationX; + stream << DestinationY; + stream << DestinationTolerance; + stream << Var37; + stream << Energy; + stream << EnergyTarget; + stream << Mass; + // stream << base.WindowInvalidateFlags; + stream << CurrentRide; + stream << CurrentRideStation; + stream << CurrentTrain; + stream << CurrentCar; + stream << CurrentSeat; + stream << SpecialSprite; + stream << ActionSpriteType; + stream << NextActionSpriteType; + stream << ActionSpriteImageOffset; + stream << Action; + stream << ActionFrame; + stream << StepProgress; + stream << PeepDirection; + stream << InteractionRideIndex; + stream << Id; + stream << PathCheckOptimisation; + stream << PathfindGoal; + stream << PathfindHistory; + stream << WalkingFrameNum; + stream << PeepFlags; +} diff --git a/src/openrct2/peep/Peep.h b/src/openrct2/peep/Peep.h index bff1a61d31..abca1b86b2 100644 --- a/src/openrct2/peep/Peep.h +++ b/src/openrct2/peep/Peep.h @@ -408,6 +408,8 @@ public: // Peep void SetDestination(const CoordsXY& coords, int32_t tolerance); [[nodiscard]] CoordsXY GetDestination() const; + void Serialise(class DataSerialiser& stream); + // TODO: Make these private again when done refactoring public: // Peep [[nodiscard]] bool CheckForPath(); diff --git a/src/openrct2/peep/Staff.cpp b/src/openrct2/peep/Staff.cpp index 097d9de871..f781cb199c 100644 --- a/src/openrct2/peep/Staff.cpp +++ b/src/openrct2/peep/Staff.cpp @@ -16,6 +16,7 @@ #include "../actions/StaffSetOrdersAction.h" #include "../audio/audio.h" #include "../config/Config.h" +#include "../core/DataSerialiser.h" #include "../entity/EntityRegistry.h" #include "../interface/Viewport.h" #include "../localisation/Date.h" @@ -2670,3 +2671,17 @@ money32 GetStaffWage(StaffType type) return MONEY(55, 00); } } + +void Staff::Serialise(DataSerialiser& stream) +{ + Peep::Serialise(stream); + stream << AssignedStaffType; + stream << MechanicTimeSinceCall; + stream << HireDate; + stream << StaffOrders; + stream << StaffMowingTimeout; + stream << StaffLawnsMown; + stream << StaffGardensWatered; + stream << StaffLitterSwept; + stream << StaffBinsEmptied; +} diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index fe87e7d7a9..cf8d78c677 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -9788,3 +9788,67 @@ void Vehicle::EnableCollisionsForTrain() vehicle->ClearUpdateFlag(VEHICLE_UPDATE_FLAG_COLLISION_DISABLED); } } + +void Vehicle::Serialise(DataSerialiser& stream) +{ + EntityBase::Serialise(stream); + stream << SubType; + stream << Pitch; + stream << bank_rotation; + stream << remaining_distance; + stream << velocity; + stream << acceleration; + stream << ride; + stream << vehicle_type; + stream << colours; + stream << track_progress; + stream << TrackTypeAndDirection; + stream << TrackLocation; + stream << next_vehicle_on_train; + stream << prev_vehicle_on_ride; + stream << next_vehicle_on_ride; + stream << var_44; + stream << mass; + stream << update_flags; + stream << SwingSprite; + stream << current_station; + stream << SwingPosition; + stream << SwingSpeed; + stream << status; + stream << sub_state; + stream << peep; + stream << peep_tshirt_colours; + stream << num_seats; + stream << num_peeps; + stream << next_free_seat; + stream << restraints_position; + stream << spin_speed; + stream << sound2_flags; + stream << spin_sprite; + stream << sound1_id; + stream << sound1_volume; + stream << sound2_id; + stream << sound2_volume; + stream << sound_vector_factor; + stream << var_C0; + stream << speed; + stream << powered_acceleration; + stream << dodgems_collision_direction; + stream << animation_frame; + stream << animationState; + stream << scream_sound_id; + stream << TrackSubposition; + stream << var_CE; + stream << var_CF; + stream << lost_time_out; + stream << vertical_drop_countdown; + stream << var_D3; + stream << mini_golf_current_animation; + stream << mini_golf_flags; + stream << ride_subtype; + stream << colours_extended; + stream << seat_rotation; + stream << target_seat_rotation; + stream << BoatLocation; + stream << IsCrashedVehicle; +}