Add RideUpdate to RTD (#17752)

This commit is contained in:
frutiemax 2022-08-13 09:36:43 -04:00 committed by GitHub
parent a21d9183e6
commit 807e080d41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 42 additions and 24 deletions

View File

@ -1062,10 +1062,9 @@ void Ride::Update()
} }
// Ride specific updates // Ride specific updates
if (type == RIDE_TYPE_CHAIRLIFT) const auto& rtd = GetRideTypeDescriptor();
UpdateChairlift(); if (rtd.RideUpdate != nullptr)
else if (type == RIDE_TYPE_SPIRAL_SLIDE) rtd.RideUpdate(*this);
UpdateSpiralSlide();
ride_breakdown_update(this); ride_breakdown_update(this);
@ -1104,23 +1103,23 @@ void Ride::Update()
* *
* rct2: 0x006AC489 * rct2: 0x006AC489
*/ */
void Ride::UpdateChairlift() void UpdateChairlift(Ride& ride)
{ {
if (!(lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK)) if (!(ride.lifecycle_flags & RIDE_LIFECYCLE_ON_TRACK))
return; return;
if ((lifecycle_flags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN | RIDE_LIFECYCLE_CRASHED)) if ((ride.lifecycle_flags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN | RIDE_LIFECYCLE_CRASHED))
&& breakdown_reason_pending == 0) && ride.breakdown_reason_pending == 0)
return; return;
uint16_t old_chairlift_bullwheel_rotation = chairlift_bullwheel_rotation >> 14; uint16_t old_chairlift_bullwheel_rotation = ride.chairlift_bullwheel_rotation >> 14;
chairlift_bullwheel_rotation += speed * 2048; ride.chairlift_bullwheel_rotation += ride.speed * 2048;
if (old_chairlift_bullwheel_rotation == speed / 8) if (old_chairlift_bullwheel_rotation == ride.speed / 8)
return; return;
auto bullwheelLoc = ChairliftBullwheelLocation[0].ToCoordsXYZ(); auto bullwheelLoc = ride.ChairliftBullwheelLocation[0].ToCoordsXYZ();
map_invalidate_tile_zoom1({ bullwheelLoc, bullwheelLoc.z, bullwheelLoc.z + (4 * COORDS_Z_STEP) }); map_invalidate_tile_zoom1({ bullwheelLoc, bullwheelLoc.z, bullwheelLoc.z + (4 * COORDS_Z_STEP) });
bullwheelLoc = ChairliftBullwheelLocation[1].ToCoordsXYZ(); bullwheelLoc = ride.ChairliftBullwheelLocation[1].ToCoordsXYZ();
map_invalidate_tile_zoom1({ bullwheelLoc, bullwheelLoc.z, bullwheelLoc.z + (4 * COORDS_Z_STEP) }); map_invalidate_tile_zoom1({ bullwheelLoc, bullwheelLoc.z, bullwheelLoc.z + (4 * COORDS_Z_STEP) });
} }
@ -1196,19 +1195,20 @@ static constexpr const CoordsXY ride_spiral_slide_main_tile_offset[][4] = {
* *
* rct2: 0x006AC545 * rct2: 0x006AC545
*/ */
void Ride::UpdateSpiralSlide()
void UpdateSpiralSlide(Ride& ride)
{ {
if (gCurrentTicks & 3) if (gCurrentTicks & 3)
return; return;
if (slide_in_use == 0) if (ride.slide_in_use == 0)
return; return;
spiral_slide_progress++; ride.spiral_slide_progress++;
if (spiral_slide_progress >= 48) if (ride.spiral_slide_progress >= 48)
{ {
slide_in_use--; ride.slide_in_use--;
auto* peep = GetEntity<Guest>(slide_peep); auto* peep = GetEntity<Guest>(ride.slide_peep);
if (peep != nullptr) if (peep != nullptr)
{ {
auto destination = peep->GetDestination(); auto destination = peep->GetDestination();
@ -1221,12 +1221,12 @@ void Ride::UpdateSpiralSlide()
// Invalidate something related to station start // Invalidate something related to station start
for (int32_t i = 0; i < OpenRCT2::Limits::MaxStationsPerRide; i++) for (int32_t i = 0; i < OpenRCT2::Limits::MaxStationsPerRide; i++)
{ {
if (stations[i].Start.IsNull()) if (ride.stations[i].Start.IsNull())
continue; continue;
auto startLoc = stations[i].Start; auto startLoc = ride.stations[i].Start;
TileElement* tileElement = ride_get_station_start_track_element(this, StationIndex::FromUnderlying(i)); TileElement* tileElement = ride_get_station_start_track_element(&ride, StationIndex::FromUnderlying(i));
if (tileElement == nullptr) if (tileElement == nullptr)
continue; continue;

View File

@ -279,6 +279,10 @@ struct Ride
uint8_t current_issues; uint8_t current_issues;
uint32_t last_issue_time; uint32_t last_issue_time;
// TO-DO: those friend functions are temporary, find a way to not access the private fields
friend void UpdateSpiralSlide(Ride& ride);
friend void UpdateChairlift(Ride& ride);
private: private:
std::array<RideStation, OpenRCT2::Limits::MaxStationsPerRide> stations; std::array<RideStation, OpenRCT2::Limits::MaxStationsPerRide> stations;
@ -298,8 +302,6 @@ public:
private: private:
void Update(); void Update();
void UpdateChairlift();
void UpdateSpiralSlide();
void UpdateQueueLength(StationIndex stationIndex); void UpdateQueueLength(StationIndex stationIndex);
ResultWithMessage CreateVehicles(const CoordsXYE& element, bool isApplying); ResultWithMessage CreateVehicles(const CoordsXYE& element, bool isApplying);
void MoveTrainsToBlockBrakes(TrackElement* firstBlock); void MoveTrainsToBlockBrakes(TrackElement* firstBlock);
@ -396,6 +398,8 @@ public:
bool HasRecolourableShopItems() const; bool HasRecolourableShopItems() const;
bool HasStation() const; bool HasStation() const;
}; };
void UpdateSpiralSlide(Ride& ride);
void UpdateChairlift(Ride& ride);
#pragma pack(push, 1) #pragma pack(push, 1)

View File

@ -160,6 +160,7 @@ using RideMusicUpdateFunction = void (*)(Ride*);
using PeepUpdateRideLeaveEntranceFunc = void (*)(Guest*, Ride*, CoordsXYZD&); using PeepUpdateRideLeaveEntranceFunc = void (*)(Guest*, Ride*, CoordsXYZD&);
using StartRideMusicFunction = void (*)(const OpenRCT2::RideAudio::ViewportRideMusicInstance&); using StartRideMusicFunction = void (*)(const OpenRCT2::RideAudio::ViewportRideMusicInstance&);
using LightFXAddLightsMagicVehicleFunction = void (*)(const Vehicle* vehicle); using LightFXAddLightsMagicVehicleFunction = void (*)(const Vehicle* vehicle);
using RideUpdateFunction = void (*)(Ride& ride);
using RideUpdateMeasurementsSpecialElementsFunc = void (*)(Ride* ride, const track_type_t trackType); using RideUpdateMeasurementsSpecialElementsFunc = void (*)(Ride* ride, const track_type_t trackType);
using MusicTrackOffsetLengthFunc = std::pair<size_t, size_t> (*)(const Ride& ride); using MusicTrackOffsetLengthFunc = std::pair<size_t, size_t> (*)(const Ride& ride);
@ -228,6 +229,7 @@ struct RideTypeDescriptor
PeepUpdateRideLeaveEntranceFunc UpdateLeaveEntrance = PeepUpdateRideLeaveEntranceDefault; PeepUpdateRideLeaveEntranceFunc UpdateLeaveEntrance = PeepUpdateRideLeaveEntranceDefault;
RideConstructionWindowContext ConstructionWindowContext = RideConstructionWindowContext::Default; RideConstructionWindowContext ConstructionWindowContext = RideConstructionWindowContext::Default;
RideUpdateFunction RideUpdate = nullptr;
RideUpdateMeasurementsSpecialElementsFunc UpdateMeasurementsSpecialElements = RideUpdateMeasurementsSpecialElements_Default; RideUpdateMeasurementsSpecialElementsFunc UpdateMeasurementsSpecialElements = RideUpdateMeasurementsSpecialElements_Default;

View File

@ -61,6 +61,7 @@ constexpr const RideTypeDescriptor WaterCoasterRTD =
SET_FIELD(Classification, RideClassification::Ride), SET_FIELD(Classification, RideClassification::Ride),
SET_FIELD(UpdateLeaveEntrance, PeepUpdateRideLeaveEntranceDefault), SET_FIELD(UpdateLeaveEntrance, PeepUpdateRideLeaveEntranceDefault),
SET_FIELD(ConstructionWindowContext, RideConstructionWindowContext::Default), SET_FIELD(ConstructionWindowContext, RideConstructionWindowContext::Default),
SET_FIELD(RideUpdate, nullptr),
SET_FIELD(UpdateMeasurementsSpecialElements, RideUpdateMeasurementsSpecialElements_WaterCoaster), SET_FIELD(UpdateMeasurementsSpecialElements, RideUpdateMeasurementsSpecialElements_WaterCoaster),
}; };
// clang-format on // clang-format on

View File

@ -57,6 +57,7 @@ constexpr const RideTypeDescriptor CircusRTD =
SET_FIELD(Classification,RideClassification::Ride), SET_FIELD(Classification,RideClassification::Ride),
SET_FIELD(UpdateLeaveEntrance,PeepUpdateRideLeaveEntranceDefault), SET_FIELD(UpdateLeaveEntrance,PeepUpdateRideLeaveEntranceDefault),
SET_FIELD(ConstructionWindowContext, RideConstructionWindowContext::Default), SET_FIELD(ConstructionWindowContext, RideConstructionWindowContext::Default),
SET_FIELD(RideUpdate, nullptr),
SET_FIELD(UpdateMeasurementsSpecialElements, RideUpdateMeasurementsSpecialElements_Default), SET_FIELD(UpdateMeasurementsSpecialElements, RideUpdateMeasurementsSpecialElements_Default),
SET_FIELD(MusicTrackOffsetLength, OpenRCT2::RideAudio::RideMusicGetTrackOffsetLength_Circus), SET_FIELD(MusicTrackOffsetLength, OpenRCT2::RideAudio::RideMusicGetTrackOffsetLength_Circus),
}; };

View File

@ -59,6 +59,7 @@ constexpr const RideTypeDescriptor MiniGolfRTD =
SET_FIELD(Classification, RideClassification::Ride), SET_FIELD(Classification, RideClassification::Ride),
SET_FIELD(UpdateLeaveEntrance, PeepUpdateRideLeaveEntranceDefault), SET_FIELD(UpdateLeaveEntrance, PeepUpdateRideLeaveEntranceDefault),
SET_FIELD(ConstructionWindowContext, RideConstructionWindowContext::Default), SET_FIELD(ConstructionWindowContext, RideConstructionWindowContext::Default),
SET_FIELD(RideUpdate, nullptr),
SET_FIELD(UpdateMeasurementsSpecialElements, RideUpdateMeasurementsSpecialElements_MiniGolf), SET_FIELD(UpdateMeasurementsSpecialElements, RideUpdateMeasurementsSpecialElements_MiniGolf),
}; };
// clang-format on // clang-format on

View File

@ -59,5 +59,7 @@ constexpr const RideTypeDescriptor SpiralSlideRTD =
SET_FIELD(MusicUpdateFunction, DefaultMusicUpdate), SET_FIELD(MusicUpdateFunction, DefaultMusicUpdate),
SET_FIELD(Classification, RideClassification::Ride), SET_FIELD(Classification, RideClassification::Ride),
SET_FIELD(UpdateLeaveEntrance, PeepUpdateRideLeaveEntranceSpiralSlide), SET_FIELD(UpdateLeaveEntrance, PeepUpdateRideLeaveEntranceSpiralSlide),
SET_FIELD(ConstructionWindowContext, RideConstructionWindowContext::Default),
SET_FIELD(RideUpdate, UpdateSpiralSlide),
}; };
// clang-format on // clang-format on

View File

@ -57,5 +57,12 @@ constexpr const RideTypeDescriptor ChairliftRTD =
SET_FIELD(ColourKey, RideColourKey::Ride), SET_FIELD(ColourKey, RideColourKey::Ride),
SET_FIELD(Name, "chairlift"), SET_FIELD(Name, "chairlift"),
SET_FIELD(LightFXAddLightsMagicVehicle, LightFxAddLightsMagicVehicle_ChairLift), SET_FIELD(LightFXAddLightsMagicVehicle, LightFxAddLightsMagicVehicle_ChairLift),
SET_FIELD(StartRideMusic, OpenRCT2::RideAudio::DefaultStartRideMusicChannel),
SET_FIELD(DesignCreateMode, TrackDesignCreateMode::Default),
SET_FIELD(MusicUpdateFunction, DefaultMusicUpdate),
SET_FIELD(Classification, RideClassification::Ride),
SET_FIELD(UpdateLeaveEntrance, PeepUpdateRideLeaveEntranceDefault),
SET_FIELD(ConstructionWindowContext, RideConstructionWindowContext::Default),
SET_FIELD(RideUpdate, UpdateChairlift),
}; };
// clang-format on // clang-format on