From 9c53fe252d8b645cdc6a095fc5314ea8faa38051 Mon Sep 17 00:00:00 2001 From: frutiemax Date: Fri, 27 Aug 2021 17:44:33 -0400 Subject: [PATCH] Part of #13874: ZehMatt review changes --- src/openrct2-ui/windows/RideConstruction.cpp | 4 +-- src/openrct2/ride/Ride.cpp | 8 +++--- src/openrct2/ride/RideConstruction.cpp | 2 +- src/openrct2/ride/TrackData.cpp | 26 ++++++++++---------- src/openrct2/ride/TrackData.h | 2 +- src/openrct2/ride/TrackDesign.cpp | 12 ++++----- src/openrct2/world/TileInspector.cpp | 2 +- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 36530f15be..660e44d6b9 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -2349,7 +2349,7 @@ static void window_ride_construction_draw_track_piece( return; const auto& teDescriptor = GetTrackElementDescriptor(trackType); - auto trackBlock = teDescriptor.Block; + const auto* trackBlock = teDescriptor.Block; while ((trackBlock + 1)->index != 0xFF) trackBlock++; @@ -2404,7 +2404,7 @@ static void sub_6CBCE2( gMapSize = MAXIMUM_MAP_SIZE_TECHNICAL; const auto& teDescriptor = GetTrackElementDescriptor(trackType); - auto trackBlock = teDescriptor.Block; + const auto* trackBlock = teDescriptor.Block; while (trackBlock->index != 255) { auto quarterTile = trackBlock->var_08.Rotate(trackDirection); diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index b55da43d9e..b3df84e1bc 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -531,7 +531,7 @@ bool track_block_get_next(CoordsXYE* input, CoordsXYE* output, int32_t* z, int32 if (ride == nullptr) return false; - auto trackBlock = teDescriptor.Block; + const auto* trackBlock = teDescriptor.Block; if (trackBlock == nullptr) return false; @@ -600,7 +600,7 @@ bool track_block_get_previous_from_zero( continue; const auto& teDesc = GetTrackElementDescriptor(trackElement->GetTrackType()); - auto nextTrackBlock = teDesc.Block; + const auto* nextTrackBlock = teDesc.Block; if (nextTrackBlock == nullptr) continue; auto nextTrackCoordinate = teDesc.Coordinates; @@ -636,7 +636,7 @@ bool track_block_get_previous_from_zero( outTrackBeginEnd->begin_z = tileElement->GetBaseZ(); const auto& teDescriptor = GetTrackElementDescriptor(trackElement->GetTrackType()); - auto nextTrackBlock2 = teDescriptor.Block; + const auto* nextTrackBlock2 = teDescriptor.Block; if (nextTrackBlock2 == nullptr) continue; @@ -677,7 +677,7 @@ bool track_block_get_previous(const CoordsXYE& trackPos, track_begin_end* outTra if (ride == nullptr) return false; - auto trackBlock = teDescriptor.Block; + const auto* trackBlock = teDescriptor.Block; if (trackBlock == nullptr) return false; diff --git a/src/openrct2/ride/RideConstruction.cpp b/src/openrct2/ride/RideConstruction.cpp index 5b3bb6a432..980b0412c4 100644 --- a/src/openrct2/ride/RideConstruction.cpp +++ b/src/openrct2/ride/RideConstruction.cpp @@ -395,7 +395,7 @@ std::optional sub_6C683D( // Possibly z should be & 0xF8 const auto& teDescriptor = GetTrackElementDescriptor(type); - auto trackBlock = teDescriptor.Block; + const auto* trackBlock = teDescriptor.Block; if (trackBlock == nullptr) return std::nullopt; diff --git a/src/openrct2/ride/TrackData.cpp b/src/openrct2/ride/TrackData.cpp index 0ab32b5984..4777b5faf9 100644 --- a/src/openrct2/ride/TrackData.cpp +++ b/src/openrct2/ride/TrackData.cpp @@ -16,7 +16,7 @@ #include // clang-format off -const static rct_track_coordinates TrackCoordinates[TrackElemType::Count] = { +static constexpr rct_track_coordinates TrackCoordinates[TrackElemType::Count] = { { 0, 0, 0, 0, 0, 0 }, // ELEM_FLAT { 0, 0, 0, 0, 0, 0 }, // ELEM_END_STATION { 0, 0, 0, 0, 0, 0 }, // ELEM_BEGIN_STATION @@ -287,7 +287,7 @@ const static rct_track_coordinates TrackCoordinates[TrackElemType::Count] = { }; /** rct2: 0x0099BA64 */ -const static uint8_t TrackSequenceProperties[][MaxSequencesPerPiece] = { +static constexpr uint8_t TrackSequenceProperties[][MaxSequencesPerPiece] = { { 0 }, /* TrackElemType::EndStation */ { TRACK_SEQUENCE_FLAG_DIRECTION_1 | TRACK_SEQUENCE_FLAG_DIRECTION_3 | TRACK_SEQUENCE_FLAG_ORIGIN | TRACK_SEQUENCE_FLAG_DISALLOW_DOORS, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* TrackElemType::BeginStation */ { TRACK_SEQUENCE_FLAG_DIRECTION_1 | TRACK_SEQUENCE_FLAG_DIRECTION_3 | TRACK_SEQUENCE_FLAG_ORIGIN | TRACK_SEQUENCE_FLAG_DISALLOW_DOORS, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, @@ -559,7 +559,7 @@ const static uint8_t TrackSequenceProperties[][MaxSequencesPerPiece] = { #define TRACK_BLOCK_END { 255, 255, 255, 255, 255, {255, 255}, 255 } -static constexpr const rct_preview_track TrackBlocks000[] = { +static constexpr rct_preview_track TrackBlocks000[] = { { 0, 0, 0, 0, 0, { 0b1111, 0 }, 0 }, TRACK_BLOCK_END }; @@ -2545,7 +2545,7 @@ static constexpr const rct_preview_track TrackBlocksFlatTrack3x3[] = { }; // rct2: 0x00994638 -const static rct_preview_track *TrackBlocks[TrackElemType::Count] = { +static constexpr std::array TrackBlocks = { TrackBlocks000, TrackBlocks001, TrackBlocks002, @@ -2816,7 +2816,7 @@ const static rct_preview_track *TrackBlocks[TrackElemType::Count] = { TrackBlocksFlatTrack3x3, }; -const static uint8_t TrackPieceLengths[TrackElemType::Count] = { +static constexpr uint8_t TrackPieceLengths[TrackElemType::Count] = { 32, // TrackElemType::Flat 32, // TrackElemType::EndStation 32, // TrackElemType::BeginStation @@ -3087,7 +3087,7 @@ const static uint8_t TrackPieceLengths[TrackElemType::Count] = { }; // rct2: 0x00998C95 -const static track_curve_chain gTrackCurveChain[TrackElemType::Count] = { +static constexpr track_curve_chain gTrackCurveChain[TrackElemType::Count] = { { TRACK_CURVE_NONE, TRACK_CURVE_NONE }, { RideConstructionSpecialPieceSelected | TrackElemType::EndStation, RideConstructionSpecialPieceSelected | TrackElemType::EndStation }, { RideConstructionSpecialPieceSelected | TrackElemType::EndStation, RideConstructionSpecialPieceSelected | TrackElemType::EndStation }, @@ -3503,7 +3503,7 @@ const track_descriptor gTrackDescriptors[142] = { }; /** rct2: 0x00993D1C */ -const static track_type_t AlternativeTrackTypes[TrackElemType::Count] = { +static constexpr track_type_t AlternativeTrackTypes[TrackElemType::Count] = { TrackElemType::FlatCovered, // TrackElemType::Flat TrackElemType::None, TrackElemType::None, @@ -3774,7 +3774,7 @@ const static track_type_t AlternativeTrackTypes[TrackElemType::Count] = { }; /** rct2: 0x0099DA34 */ -const static money32 TrackPricing[TrackElemType::Count] = { +static constexpr money32 TrackPricing[TrackElemType::Count] = { 65536, // TrackElemType::Flat 98304, // TrackElemType::EndStation 98304, // TrackElemType::BeginStation @@ -4045,7 +4045,7 @@ const static money32 TrackPricing[TrackElemType::Count] = { }; /** rct2: 0x0099EA1C */ -const static track_type_t TrackElementMirrorMap[TrackElemType::Count] = { +static constexpr track_type_t TrackElementMirrorMap[TrackElemType::Count] = { TrackElemType::Flat, TrackElemType::EndStation, TrackElemType::BeginStation, @@ -4316,7 +4316,7 @@ const static track_type_t TrackElementMirrorMap[TrackElemType::Count] = { }; /** rct2: 0x00999694 */ -const static uint32_t TrackHeightMarkerPositions[TrackElemType::Count] = { +static constexpr uint32_t TrackHeightMarkerPositions[TrackElemType::Count] = { (1 << 0), // TrackElemType::Flat (1 << 0), // TrackElemType::EndStation (1 << 0), // TrackElemType::BeginStation @@ -4587,7 +4587,7 @@ const static uint32_t TrackHeightMarkerPositions[TrackElemType::Count] = { }; /** rct2: 0x00999A94 */ -const static uint8_t TrackSequenceElementAllowedWallEdges[TrackElemType::Count][MaxSequencesPerPiece] = { +static constexpr uint8_t TrackSequenceElementAllowedWallEdges[TrackElemType::Count][MaxSequencesPerPiece] = { { 0b1010, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // TrackElemType::Flat { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // TrackElemType::EndStation { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // TrackElemType::BeginStation @@ -4858,7 +4858,7 @@ const static uint8_t TrackSequenceElementAllowedWallEdges[TrackElemType::Count][ }; /** rct2: 0x0099423C */ -const static uint16_t TrackFlags[TrackElemType::Count] = { +static constexpr uint16_t TrackFlags[TrackElemType::Count] = { /* TrackElemType::Flat */ TRACK_ELEM_FLAG_ALLOW_LIFT_HILL, /* TrackElemType::EndStation */ 0, /* TrackElemType::BeginStation */ 0, @@ -5160,7 +5160,7 @@ namespace OpenRCT2 _trackElementDescriptors.push_back(desc); } } - const TrackElementDescriptor& GetTrackElementDescriptor(const uint32_t& type) + const TrackElementDescriptor& GetTrackElementDescriptor(const uint32_t type) { return _trackElementDescriptors[type]; } diff --git a/src/openrct2/ride/TrackData.h b/src/openrct2/ride/TrackData.h index 9e41660b5c..0b43a74426 100644 --- a/src/openrct2/ride/TrackData.h +++ b/src/openrct2/ride/TrackData.h @@ -77,6 +77,6 @@ namespace OpenRCT2 namespace TrackMetaData { void Init(); - const TrackElementDescriptor& GetTrackElementDescriptor(const uint32_t& type); + const TrackElementDescriptor& GetTrackElementDescriptor(const uint32_t type); } // namespace TrackMetaData } // namespace OpenRCT2 diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index 5c22e095aa..a8d51989ed 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -185,7 +185,7 @@ rct_string_id TrackDesign::CreateTrackDesignTrack(const Ride& ride) const auto& teDescriptor = GetTrackElementDescriptor(trackElement.element->AsTrack()->GetTrackType()); const rct_track_coordinates* trackCoordinates = &teDescriptor.Coordinates; - auto trackBlock = teDescriptor.Block; + const auto* trackBlock = teDescriptor.Block; // Used in the following loop to know when we have // completed all of the elements and are back at the // start. @@ -1650,13 +1650,13 @@ static std::optional track_design_place_ride(TrackDesign* td6, const Co } } - const rct_track_coordinates* track_coordinates = &teDescriptor.Coordinates; + const rct_track_coordinates& track_coordinates = teDescriptor.Coordinates; auto offsetAndRotatedTrack = CoordsXY{ newCoords } - + CoordsXY{ track_coordinates->x, track_coordinates->y }.Rotate(rotation); + + CoordsXY{ track_coordinates.x, track_coordinates.y }.Rotate(rotation); - newCoords = { offsetAndRotatedTrack, newCoords.z - track_coordinates->z_begin + track_coordinates->z_end }; - rotation = (rotation + track_coordinates->rotation_end - track_coordinates->rotation_begin) & 3; - if (track_coordinates->rotation_end & (1 << 2)) + newCoords = { offsetAndRotatedTrack, newCoords.z - track_coordinates.z_begin + track_coordinates.z_end }; + rotation = (rotation + track_coordinates.rotation_end - track_coordinates.rotation_begin) & 3; + if (track_coordinates.rotation_end & (1 << 2)) { rotation |= (1 << 2); } diff --git a/src/openrct2/world/TileInspector.cpp b/src/openrct2/world/TileInspector.cpp index f5e2632bce..cf1a998b22 100644 --- a/src/openrct2/world/TileInspector.cpp +++ b/src/openrct2/world/TileInspector.cpp @@ -856,7 +856,7 @@ namespace OpenRCT2::TileInspector return std::make_unique(GameActions::Status::Unknown, STR_NONE); const auto& teDescriptor = GetTrackElementDescriptor(type); - auto trackBlock = teDescriptor.Block; + const auto* trackBlock = teDescriptor.Block; trackBlock += trackElement->AsTrack()->GetSequenceIndex(); uint8_t originDirection = trackElement->GetDirection();