From b3744f129f56c5aaa80cd0bdc874af7492ac062e Mon Sep 17 00:00:00 2001 From: frutiemax Date: Sat, 28 Aug 2021 18:57:46 -0400 Subject: [PATCH] Part of #13874: Avoid copies of ted --- src/openrct2/actions/TrackPlaceAction.cpp | 2 +- src/openrct2/ride/Ride.cpp | 24 +++++++++---------- src/openrct2/ride/RideConstruction.cpp | 28 +++++++++++------------ 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/openrct2/actions/TrackPlaceAction.cpp b/src/openrct2/actions/TrackPlaceAction.cpp index 96aab983f4..1763aba396 100644 --- a/src/openrct2/actions/TrackPlaceAction.cpp +++ b/src/openrct2/actions/TrackPlaceAction.cpp @@ -401,7 +401,7 @@ GameActions::Result::Ptr TrackPlaceAction::Execute() const uint32_t rideTypeFlags = ride->GetRideTypeDescriptor().Flags; const auto& ted = GetTrackElementDescriptor(_trackType); - auto wallEdges = ted.SequenceElementAllowedWallEdges; + const auto& wallEdges = ted.SequenceElementAllowedWallEdges; money32 cost = 0; const rct_preview_track* trackBlock = ted.Block; diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 877be528eb..7774faf789 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -481,11 +481,11 @@ bool track_block_get_next_from_zero( continue; const auto& ted = GetTrackElementDescriptor(trackElement->GetTrackType()); - auto nextTrackBlock = ted.Block; + const auto* nextTrackBlock = ted.Block; if (nextTrackBlock == nullptr) continue; - auto nextTrackCoordinate = ted.Coordinates; + const auto& nextTrackCoordinate = ted.Coordinates; uint8_t nextRotation = tileElement->GetDirectionWithOffset(nextTrackCoordinate.rotation_begin) | (nextTrackCoordinate.rotation_begin & TRACK_BLOCK_2); @@ -537,7 +537,7 @@ bool track_block_get_next(CoordsXYE* input, CoordsXYE* output, int32_t* z, int32 trackBlock += inputElement->GetSequenceIndex(); - auto trackCoordinate = ted.Coordinates; + const auto& trackCoordinate = ted.Coordinates; int32_t x = input->x; int32_t y = input->y; @@ -599,11 +599,11 @@ bool track_block_get_previous_from_zero( if (trackElement->GetRideIndex() != ride->id) continue; - const auto& teDesc = GetTrackElementDescriptor(trackElement->GetTrackType()); - const auto* nextTrackBlock = teDesc.Block; + const auto* ted = &GetTrackElementDescriptor(trackElement->GetTrackType()); + const auto* nextTrackBlock = ted->Block; if (nextTrackBlock == nullptr) continue; - auto nextTrackCoordinate = teDesc.Coordinates; + const auto& nextTrackCoordinate = ted->Coordinates; nextTrackBlock += trackElement->GetSequenceIndex(); if ((nextTrackBlock + 1)->index != 255) @@ -635,8 +635,8 @@ bool track_block_get_previous_from_zero( outTrackBeginEnd->begin_z = tileElement->GetBaseZ(); - const auto& ted = GetTrackElementDescriptor(trackElement->GetTrackType()); - const auto* nextTrackBlock2 = ted.Block; + ted = &GetTrackElementDescriptor(trackElement->GetTrackType()); + const auto* nextTrackBlock2 = ted->Block; if (nextTrackBlock2 == nullptr) continue; @@ -2822,8 +2822,8 @@ static bool ride_check_start_and_end_is_station(CoordsXYE* input) // Check back of the track track_get_back(input, &trackBack); auto trackType = trackBack.element->AsTrack()->GetTrackType(); - auto ted = GetTrackElementDescriptor(trackType); - if (!(ted.TrackSequenceProperties[0] & TRACK_SEQUENCE_FLAG_ORIGIN)) + const auto* ted = &GetTrackElementDescriptor(trackType); + if (!(ted->TrackSequenceProperties[0] & TRACK_SEQUENCE_FLAG_ORIGIN)) { return false; } @@ -2832,8 +2832,8 @@ static bool ride_check_start_and_end_is_station(CoordsXYE* input) // Check front of the track track_get_front(input, &trackFront); trackType = trackFront.element->AsTrack()->GetTrackType(); - ted = GetTrackElementDescriptor(trackType); - if (!(ted.TrackSequenceProperties[0] & TRACK_SEQUENCE_FLAG_ORIGIN)) + ted = &GetTrackElementDescriptor(trackType); + if (!(ted->TrackSequenceProperties[0] & TRACK_SEQUENCE_FLAG_ORIGIN)) { return false; } diff --git a/src/openrct2/ride/RideConstruction.cpp b/src/openrct2/ride/RideConstruction.cpp index 620761a8b4..0eae6e5656 100644 --- a/src/openrct2/ride/RideConstruction.cpp +++ b/src/openrct2/ride/RideConstruction.cpp @@ -630,7 +630,7 @@ void ride_construction_set_default_next_piece() TileElement* tileElement; _currentTrackPrice = MONEY32_UNDEFINED; - TrackElementDescriptor ted; + const TrackElementDescriptor* ted; switch (_rideConstructionState) { case RideConstructionState::Front: @@ -659,8 +659,8 @@ void ride_construction_set_default_next_piece() } } - ted = GetTrackElementDescriptor(trackType); - curve = ted.CurveChain.next; + ted = &GetTrackElementDescriptor(trackType); + curve = ted->CurveChain.next; bank = TrackDefinitions[trackType].bank_end; slope = TrackDefinitions[trackType].vangle_end; @@ -705,8 +705,8 @@ void ride_construction_set_default_next_piece() } } - ted = GetTrackElementDescriptor(trackType); - curve = ted.CurveChain.previous; + ted = &GetTrackElementDescriptor(trackType); + curve = ted->CurveChain.previous; bank = TrackDefinitions[trackType].bank_start; slope = TrackDefinitions[trackType].vangle_start; @@ -1439,7 +1439,7 @@ CoordsXYZD ride_get_entrance_or_exit_position_from_screen_position(const ScreenC */ void sub_6CB945(Ride* ride) { - TrackElementDescriptor ted; + const TrackElementDescriptor* ted; if (ride->type != RIDE_TYPE_MAZE) { for (StationIndex stationId = 0; stationId < MAX_STATIONS; ++stationId) @@ -1475,8 +1475,8 @@ void sub_6CB945(Ride* ride) if (tileElement->AsTrack()->GetSequenceIndex() != 0) continue; - ted = GetTrackElementDescriptor(tileElement->AsTrack()->GetTrackType()); - if (!(ted.TrackSequenceProperties[0] & TRACK_SEQUENCE_FLAG_ORIGIN)) + ted = &GetTrackElementDescriptor(tileElement->AsTrack()->GetTrackType()); + if (!(ted->TrackSequenceProperties[0] & TRACK_SEQUENCE_FLAG_ORIGIN)) continue; trackFound = true; @@ -1503,8 +1503,8 @@ void sub_6CB945(Ride* ride) continue; } - ted = GetTrackElementDescriptor(tileElement->AsTrack()->GetTrackType()); - const rct_preview_track* trackBlock = ted.Block; + ted = &GetTrackElementDescriptor(tileElement->AsTrack()->GetTrackType()); + const rct_preview_track* trackBlock = ted->Block; while ((++trackBlock)->index != 0xFF) { CoordsXYZ blockLocation = location + CoordsXYZ{ CoordsXY{ trackBlock->x, trackBlock->y }.Rotate(direction), 0 }; @@ -1520,8 +1520,8 @@ void sub_6CB945(Ride* ride) if (tileElement->GetType() != TILE_ELEMENT_TYPE_TRACK) continue; - ted = GetTrackElementDescriptor(tileElement->AsTrack()->GetTrackType()); - if (!(ted.TrackSequenceProperties[0] & TRACK_SEQUENCE_FLAG_ORIGIN)) + ted = &GetTrackElementDescriptor(tileElement->AsTrack()->GetTrackType()); + if (!(ted->TrackSequenceProperties[0] & TRACK_SEQUENCE_FLAG_ORIGIN)) continue; trackFound = true; @@ -1616,8 +1616,8 @@ void sub_6CB945(Ride* ride) Direction direction = (tileElement->GetDirection() - direction_reverse(trackElement->GetDirection())) & 3; - ted = GetTrackElementDescriptor(trackType); - if (!(ted.TrackSequenceProperties[trackSequence] & (1 << direction))) + ted = &GetTrackElementDescriptor(trackType); + if (!(ted->TrackSequenceProperties[trackSequence] & (1 << direction))) { continue; }