From 5c29967d61da1e8b44557e207692bacc15beebfd Mon Sep 17 00:00:00 2001 From: Michael Steenbeek <1478678+Gymnasiast@users.noreply.github.com> Date: Sat, 28 Sep 2024 03:51:04 +0200 Subject: [PATCH] Use FlagHolder for lift+inverted flags (#22839) --- src/openrct2-ui/windows/RideConstruction.cpp | 50 ++++++++++++-------- src/openrct2-ui/windows/Window.h | 3 -- src/openrct2/actions/TrackPlaceAction.cpp | 14 +++--- src/openrct2/actions/TrackPlaceAction.h | 7 ++- src/openrct2/ride/Ride.h | 3 -- src/openrct2/ride/RideConstruction.h | 7 +++ src/openrct2/ride/TrackDesign.cpp | 6 +-- 7 files changed, 51 insertions(+), 39 deletions(-) diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 549fc37e22..9d764c8ec6 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -62,8 +62,11 @@ namespace OpenRCT2::Ui::Windows static RideConstructionState _rideConstructionState2; static bool WindowRideConstructionUpdateState( - int32_t* trackType, int32_t* trackDirection, RideId* rideIndex, int32_t* _liftHillAndAlternativeState, + int32_t* trackType, int32_t* trackDirection, RideId* rideIndex, SelectedLiftAndInverted* _liftHillAndAlternativeState, CoordsXYZ* trackPos, int32_t* properties); + money64 PlaceProvisionalTrackPiece( + RideId rideIndex, int32_t trackType, int32_t trackDirection, SelectedLiftAndInverted liftHillAndAlternativeState, + const CoordsXYZ& trackPos); static constexpr StringId WINDOW_TITLE = STR_RIDE_CONSTRUCTION_WINDOW_TITLE; static constexpr int32_t WH = 394; @@ -1569,7 +1572,8 @@ namespace OpenRCT2::Ui::Windows return; RideId rideIndex; - int32_t trackType, trackDirection, liftHillAndInvertedState; + int32_t trackType, trackDirection; + SelectedLiftAndInverted liftHillAndInvertedState{}; if (WindowRideConstructionUpdateState( &trackType, &trackDirection, &rideIndex, &liftHillAndInvertedState, nullptr, nullptr)) return; @@ -2215,7 +2219,8 @@ namespace OpenRCT2::Ui::Windows void Construct() { RideId rideIndex; - int32_t trackType, trackDirection, liftHillAndAlternativeState, properties; + int32_t trackType, trackDirection, properties; + SelectedLiftAndInverted liftHillAndAlternativeState{}; CoordsXYZ trackPos{}; _currentTrackPrice = kMoney64Undefined; @@ -2587,8 +2592,8 @@ namespace OpenRCT2::Ui::Windows } void DrawTrackPiece( - DrawPixelInfo& dpi, RideId rideIndex, int32_t trackType, int32_t trackDirection, int32_t liftHillAndInvertedState, - int32_t widgetWidth, int32_t widgetHeight) + DrawPixelInfo& dpi, RideId rideIndex, int32_t trackType, int32_t trackDirection, + SelectedLiftAndInverted liftHillAndInvertedState, int32_t widgetWidth, int32_t widgetHeight) { auto currentRide = GetRide(rideIndex); if (currentRide == nullptr) @@ -2623,8 +2628,8 @@ namespace OpenRCT2::Ui::Windows } void DrawTrackPieceHelper( - DrawPixelInfo& dpi, RideId rideIndex, int32_t trackType, int32_t trackDirection, int32_t liftHillAndInvertedState, - const CoordsXY& originCoords, int32_t originZ) + DrawPixelInfo& dpi, RideId rideIndex, int32_t trackType, int32_t trackDirection, + SelectedLiftAndInverted liftHillAndInvertedState, const CoordsXY& originCoords, int32_t originZ) { TileElement tempSideTrackTileElement{ 0x80, 0x8F, 128, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; TileElement tempTrackTileElement{}; @@ -2646,12 +2651,12 @@ namespace OpenRCT2::Ui::Windows // Setup non changing parts of the temporary track tile element tempTrackTileElement.SetType(TileElementType::Track); tempTrackTileElement.SetDirection(trackDirection); - tempTrackTileElement.AsTrack()->SetHasChain((liftHillAndInvertedState & CONSTRUCTION_LIFT_HILL_SELECTED) != 0); + tempTrackTileElement.AsTrack()->SetHasChain(liftHillAndInvertedState.has(LiftHillAndInverted::liftHill)); tempTrackTileElement.SetLastForTile(true); tempTrackTileElement.AsTrack()->SetTrackType(trackType); tempTrackTileElement.AsTrack()->SetRideType(currentRide->type); tempTrackTileElement.AsTrack()->SetHasCableLift(false); - tempTrackTileElement.AsTrack()->SetInverted((liftHillAndInvertedState & CONSTRUCTION_INVERTED_TRACK_SELECTED) != 0); + tempTrackTileElement.AsTrack()->SetInverted(liftHillAndInvertedState.has(LiftHillAndInverted::inverted)); tempTrackTileElement.AsTrack()->SetColourScheme(RideColourScheme::main); // Skipping seat rotation, should not be necessary for a temporary piece. tempTrackTileElement.AsTrack()->SetRideIndex(rideIndex); @@ -3096,7 +3101,8 @@ namespace OpenRCT2::Ui::Windows void UpdateGhostTrackAndArrow() { RideId rideIndex; - int32_t direction, type, liftHillAndAlternativeState; + int32_t direction, type; + SelectedLiftAndInverted liftHillAndAlternativeState{}; CoordsXYZ trackPos{}; if (_currentTrackSelectionFlags & TRACK_SELECTION_FLAG_TRACK_PLACE_ACTION_QUEUED) @@ -3252,7 +3258,8 @@ namespace OpenRCT2::Ui::Windows gMapSelectionTiles.push_back(*mapCoords); RideId rideIndex; - int32_t trackType, trackDirection, liftHillAndAlternativeState; + int32_t trackType, trackDirection; + SelectedLiftAndInverted liftHillAndAlternativeState{}; if (WindowRideConstructionUpdateState( &trackType, &trackDirection, &rideIndex, &liftHillAndAlternativeState, nullptr, nullptr)) { @@ -4654,7 +4661,7 @@ namespace OpenRCT2::Ui::Windows * rct2: 0x006CA162 */ money64 PlaceProvisionalTrackPiece( - RideId rideIndex, int32_t trackType, int32_t trackDirection, int32_t liftHillAndAlternativeState, + RideId rideIndex, int32_t trackType, int32_t trackDirection, SelectedLiftAndInverted liftHillAndAlternativeState, const CoordsXYZ& trackPos) { auto ride = GetRide(rideIndex); @@ -4830,12 +4837,13 @@ namespace OpenRCT2::Ui::Windows * @return (CF) */ static bool WindowRideConstructionUpdateState( - int32_t* _trackType, int32_t* _trackDirection, RideId* _rideIndex, int32_t* _liftHillAndInvertedState, + int32_t* _trackType, int32_t* _trackDirection, RideId* _rideIndex, SelectedLiftAndInverted* _liftHillAndInvertedState, CoordsXYZ* _trackPos, int32_t* _properties) { RideId rideIndex; uint8_t trackDirection; - uint16_t x, y, liftHillAndInvertedState, properties; + uint16_t x, y, properties; + SelectedLiftAndInverted liftHillAndInvertedState{}; auto updated_element = WindowRideConstructionUpdateStateGetTrackElement(); if (!std::get<0>(updated_element)) @@ -4844,16 +4852,15 @@ namespace OpenRCT2::Ui::Windows } track_type_t trackType = std::get<1>(updated_element); - liftHillAndInvertedState = 0; rideIndex = _currentRideIndex; if (_currentTrackHasLiftHill) { - liftHillAndInvertedState |= CONSTRUCTION_LIFT_HILL_SELECTED; + liftHillAndInvertedState.set(LiftHillAndInverted::liftHill); } if (_currentTrackAlternative.has(AlternativeTrackFlag::inverted)) { - liftHillAndInvertedState |= CONSTRUCTION_INVERTED_TRACK_SELECTED; + liftHillAndInvertedState.set(LiftHillAndInverted::inverted); } auto ride = GetRide(rideIndex); @@ -4900,7 +4907,7 @@ namespace OpenRCT2::Ui::Windows { trackType = alternativeType; if (!GetGameState().Cheats.EnableChainLiftOnAllTrack) - liftHillAndInvertedState &= ~CONSTRUCTION_LIFT_HILL_SELECTED; + liftHillAndInvertedState.unset(LiftHillAndInverted::liftHill); } } @@ -4951,12 +4958,12 @@ namespace OpenRCT2::Ui::Windows if (turnOffLiftHill && !GetGameState().Cheats.EnableChainLiftOnAllTrack) { - liftHillAndInvertedState &= ~CONSTRUCTION_LIFT_HILL_SELECTED; + liftHillAndInvertedState.unset(LiftHillAndInverted::liftHill); _currentTrackHasLiftHill = false; if (trackType == TrackElemType::LeftCurvedLiftHill || trackType == TrackElemType::RightCurvedLiftHill) { - liftHillAndInvertedState |= CONSTRUCTION_LIFT_HILL_SELECTED; + liftHillAndInvertedState.set(LiftHillAndInverted::liftHill); } } @@ -4990,7 +4997,8 @@ namespace OpenRCT2::Ui::Windows if (_currentTrackSelectionFlags & TRACK_SELECTION_FLAG_TRACK) { RideId rideIndex; - int32_t direction, type, liftHillAndAlternativeState; + int32_t direction, type; + SelectedLiftAndInverted liftHillAndAlternativeState{}; CoordsXYZ trackPos; if (WindowRideConstructionUpdateState( &type, &direction, &rideIndex, &liftHillAndAlternativeState, &trackPos, nullptr)) diff --git a/src/openrct2-ui/windows/Window.h b/src/openrct2-ui/windows/Window.h index f024440b89..aaf44d7a81 100644 --- a/src/openrct2-ui/windows/Window.h +++ b/src/openrct2-ui/windows/Window.h @@ -199,9 +199,6 @@ namespace OpenRCT2::Ui::Windows WindowBase* RideConstructionOpen(); void WindowRideConstructionUpdateActiveElementsImpl(); void WindowRideConstructionUpdateEnabledTrackPieces(); - money64 PlaceProvisionalTrackPiece( - RideId rideIndex, int32_t trackType, int32_t trackDirection, int32_t liftHillAndAlternativeState, - const CoordsXYZ& trackPos); void RideRestoreProvisionalTrackPiece(); void RideRemoveProvisionalTrackPiece(); diff --git a/src/openrct2/actions/TrackPlaceAction.cpp b/src/openrct2/actions/TrackPlaceAction.cpp index 6891ecdf0a..0e2cd1e04b 100644 --- a/src/openrct2/actions/TrackPlaceAction.cpp +++ b/src/openrct2/actions/TrackPlaceAction.cpp @@ -29,7 +29,7 @@ using namespace OpenRCT2::TrackMetaData; TrackPlaceAction::TrackPlaceAction( RideId rideIndex, int32_t trackType, ride_type_t rideType, const CoordsXYZD& origin, int32_t brakeSpeed, int32_t colour, - int32_t seatRotation, int32_t liftHillAndAlternativeState, bool fromTrackDesign) + int32_t seatRotation, SelectedLiftAndInverted liftHillAndAlternativeState, bool fromTrackDesign) : _rideIndex(rideIndex) , _trackType(trackType) , _rideType(rideType) @@ -52,7 +52,7 @@ void TrackPlaceAction::AcceptParameters(GameActionParameterVisitor& visitor) visitor.Visit("brakeSpeed", _brakeSpeed); visitor.Visit("colour", _colour); visitor.Visit("seatRotation", _seatRotation); - visitor.Visit("trackPlaceFlags", _trackPlaceFlags); + visitor.Visit("trackPlaceFlags", _trackPlaceFlags.holder); visitor.Visit("isFromTrackDesign", _fromTrackDesign); } @@ -66,7 +66,7 @@ void TrackPlaceAction::Serialise(DataSerialiser& stream) GameAction::Serialise(stream); stream << DS_TAG(_rideIndex) << DS_TAG(_trackType) << DS_TAG(_rideType) << DS_TAG(_origin) << DS_TAG(_brakeSpeed) - << DS_TAG(_colour) << DS_TAG(_seatRotation) << DS_TAG(_trackPlaceFlags); + << DS_TAG(_colour) << DS_TAG(_seatRotation) << DS_TAG(_trackPlaceFlags.holder); } GameActions::Result TrackPlaceAction::Query() const @@ -161,7 +161,7 @@ GameActions::Result TrackPlaceAction::Query() const } } // Backwards steep lift hills are allowed, even on roller coasters that do not support forwards steep lift hills. - if ((_trackPlaceFlags & CONSTRUCTION_LIFT_HILL_SELECTED) && !rtd.SupportsTrackGroup(TrackGroup::liftHillSteep) + if (_trackPlaceFlags.has(LiftHillAndInverted::liftHill) && !rtd.SupportsTrackGroup(TrackGroup::liftHillSteep) && !gameState.Cheats.EnableChainLiftOnAllTrack) { const auto& ted = GetTrackElementDescriptor(_trackType); @@ -578,7 +578,7 @@ GameActions::Result TrackPlaceAction::Execute() const trackElement->SetClearanceZ(clearanceZ); trackElement->SetDirection(_origin.direction); - trackElement->SetHasChain(_trackPlaceFlags & CONSTRUCTION_LIFT_HILL_SELECTED); + trackElement->SetHasChain(_trackPlaceFlags.has(LiftHillAndInverted::liftHill)); trackElement->SetSequenceIndex(blockIndex); trackElement->SetRideIndex(_rideIndex); trackElement->SetTrackType(_trackType); @@ -619,7 +619,7 @@ GameActions::Result TrackPlaceAction::Execute() const trackElement->SetSeatRotation(_seatRotation); } - if (_trackPlaceFlags & CONSTRUCTION_INVERTED_TRACK_SELECTED) + if (_trackPlaceFlags.has(LiftHillAndInverted::inverted)) { trackElement->SetInverted(true); } @@ -722,7 +722,7 @@ GameActions::Result TrackPlaceAction::Execute() const case TrackElemType::Up60ToFlat: case TrackElemType::DiagUp25ToFlat: case TrackElemType::DiagUp60ToFlat: - if (!(_trackPlaceFlags & CONSTRUCTION_LIFT_HILL_SELECTED)) + if (!_trackPlaceFlags.has(LiftHillAndInverted::liftHill)) break; [[fallthrough]]; case TrackElemType::CableLiftHill: diff --git a/src/openrct2/actions/TrackPlaceAction.h b/src/openrct2/actions/TrackPlaceAction.h index 7142eb1ecc..c38d7589ed 100644 --- a/src/openrct2/actions/TrackPlaceAction.h +++ b/src/openrct2/actions/TrackPlaceAction.h @@ -9,8 +9,11 @@ #pragma once +#include "../ride/RideConstruction.h" #include "GameAction.h" +using namespace OpenRCT2; + struct TrackPlaceActionResult { uint8_t GroundFlags{ 0 }; @@ -26,14 +29,14 @@ private: int32_t _brakeSpeed{}; int32_t _colour{}; int32_t _seatRotation{}; - int32_t _trackPlaceFlags{}; + SelectedLiftAndInverted _trackPlaceFlags{}; bool _fromTrackDesign{}; public: TrackPlaceAction() = default; TrackPlaceAction( RideId rideIndex, int32_t trackType, ride_type_t rideType, const CoordsXYZD& origin, int32_t brakeSpeed, int32_t colour, - int32_t seatRotation, int32_t liftHillAndAlternativeState, bool fromTrackDesign); + int32_t seatRotation, SelectedLiftAndInverted liftHillAndAlternativeState, bool fromTrackDesign); void AcceptParameters(GameActionParameterVisitor& visitor) override; diff --git a/src/openrct2/ride/Ride.h b/src/openrct2/ride/Ride.h index ad3ca37c3c..0b90738aee 100644 --- a/src/openrct2/ride/Ride.h +++ b/src/openrct2/ride/Ride.h @@ -898,9 +898,6 @@ constexpr uint16_t kTurnMask2Elements = 0x00E0; constexpr uint16_t kTurnMask3Elements = 0x0700; constexpr uint16_t kTurnMask4PlusElements = 0xF800; -constexpr uint32_t CONSTRUCTION_LIFT_HILL_SELECTED = 1 << 0; -constexpr uint32_t CONSTRUCTION_INVERTED_TRACK_SELECTED = 1 << 1; - Ride* GetRide(RideId index); struct RideManager diff --git a/src/openrct2/ride/RideConstruction.h b/src/openrct2/ride/RideConstruction.h index 5f52f0d24d..82fd5bcb25 100644 --- a/src/openrct2/ride/RideConstruction.h +++ b/src/openrct2/ride/RideConstruction.h @@ -47,6 +47,13 @@ namespace OpenRCT2 inverted, // Flying RC, Lay-down RC, Multi-dimension RC }; using SelectedAlternative = FlagHolder; + + enum class LiftHillAndInverted : uint8_t + { + liftHill, + inverted, + }; + using SelectedLiftAndInverted = FlagHolder; } // namespace OpenRCT2 extern money64 _currentTrackPrice; diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index a03cdba1d2..6b6e398538 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -1594,14 +1594,14 @@ static GameActions::Result TrackDesignPlaceRide( // di int16_t tempZ = newCoords.z - trackCoordinates->zBegin; - int32_t liftHillAndAlternativeState = 0; + SelectedLiftAndInverted liftHillAndAlternativeState{}; if (track.HasFlag(TrackDesignTrackElementFlag::hasChain)) { - liftHillAndAlternativeState |= 1; + liftHillAndAlternativeState.set(LiftHillAndInverted::liftHill); } if (track.HasFlag(TrackDesignTrackElementFlag::isInverted)) { - liftHillAndAlternativeState |= 2; + liftHillAndAlternativeState.set(LiftHillAndInverted::inverted); } uint8_t flags = GAME_COMMAND_FLAG_APPLY;