From 5ff78e48c7b62d7165a3a206e267264b8b2ae965 Mon Sep 17 00:00:00 2001 From: Richard Fine Date: Mon, 26 Aug 2019 11:25:57 +0100 Subject: [PATCH] Reduce usage of GetDirectionWithOffset() GetDirectionWithOffset(2) is the same thing as 'direction_reverse(GetDirection())', and the latter is more readable. --- src/openrct2/actions/WallPlaceAction.hpp | 2 +- src/openrct2/paint/tile_element/Paint.TileElement.cpp | 2 +- src/openrct2/peep/Guest.cpp | 6 +++--- src/openrct2/peep/GuestPathfinding.cpp | 2 +- src/openrct2/ride/Ride.cpp | 2 +- src/openrct2/world/Footpath.cpp | 4 ++-- src/openrct2/world/TileElement.cpp | 6 +++--- src/openrct2/world/TileElement.h | 6 +++--- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/openrct2/actions/WallPlaceAction.hpp b/src/openrct2/actions/WallPlaceAction.hpp index cf581f64f1..ebeb0cef5c 100644 --- a/src/openrct2/actions/WallPlaceAction.hpp +++ b/src/openrct2/actions/WallPlaceAction.hpp @@ -557,7 +557,7 @@ private: { if (!(TrackCoordinates[trackType].rotation_begin & 4)) { - direction = trackElement->GetDirectionWithOffset(2); + direction = direction_reverse(trackElement->GetDirection()); if (direction == _edge) { const rct_preview_track* trackBlock = &TrackBlocks[trackType][sequence]; diff --git a/src/openrct2/paint/tile_element/Paint.TileElement.cpp b/src/openrct2/paint/tile_element/Paint.TileElement.cpp index 619c421b4b..730a4e5409 100644 --- a/src/openrct2/paint/tile_element/Paint.TileElement.cpp +++ b/src/openrct2/paint/tile_element/Paint.TileElement.cpp @@ -248,7 +248,7 @@ static void sub_68B3FB(paint_session* session, int32_t x, int32_t y) if ((session->ViewFlags & VIEWPORT_FLAG_CLIP_VIEW) && (tile_element->base_height > gClipHeight)) continue; - int32_t direction = tile_element->GetDirectionWithOffset(rotation); + Direction direction = tile_element->GetDirectionWithOffset(rotation); int32_t height = tile_element->base_height * 8; // If we are on a new height level, look through elements on the diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index 56d59dd9ad..9a713e3c42 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -6472,7 +6472,7 @@ static bool peep_find_ride_to_look_at(Peep* peep, uint8_t edge, uint8_t* rideToV } if (tileElement->GetType() != TILE_ELEMENT_TYPE_WALL) continue; - if (tileElement->GetDirectionWithOffset(2) != edge) + if (direction_reverse(tileElement->GetDirection()) != edge) continue; auto wallEntry = tileElement->AsWall()->GetEntry(); if (wallEntry == nullptr || (wallEntry->wall.flags2 & WALL_SCENERY_2_IS_OPAQUE)) @@ -6590,7 +6590,7 @@ static bool peep_find_ride_to_look_at(Peep* peep, uint8_t edge, uint8_t* rideToV } if (tileElement->GetType() != TILE_ELEMENT_TYPE_WALL) continue; - if (tileElement->GetDirectionWithOffset(2) != edge) + if (direction_reverse(tileElement->GetDirection()) != edge) continue; auto wallEntry = tileElement->AsWall()->GetEntry(); if (wallEntry == nullptr || (wallEntry->wall.flags2 & WALL_SCENERY_2_IS_OPAQUE)) @@ -6706,7 +6706,7 @@ static bool peep_find_ride_to_look_at(Peep* peep, uint8_t edge, uint8_t* rideToV } if (tileElement->GetType() != TILE_ELEMENT_TYPE_WALL) continue; - if (tileElement->GetDirectionWithOffset(2) != edge) + if (direction_reverse(tileElement->GetDirection()) != edge) continue; auto wallEntry = tileElement->AsWall()->GetEntry(); if (wallEntry == nullptr || (wallEntry->wall.flags2 & WALL_SCENERY_2_IS_OPAQUE)) diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index 5429852da1..0155d5729b 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -1740,7 +1740,7 @@ static void get_ride_queue_end(TileCoordsXYZ& loc) if (!found) return; - Direction direction = tileElement->GetDirectionWithOffset(2); + Direction direction = direction_reverse(tileElement->GetDirection()); TileElement* lastPathElement = nullptr; TileElement* firstPathElement = nullptr; diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 9d9703c4c7..f182d21ea8 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -7078,7 +7078,7 @@ void sub_6CB945(Ride* ride) uint8_t trackType = trackElement->AsTrack()->GetTrackType(); uint8_t trackSequence = trackElement->AsTrack()->GetSequenceIndex(); - uint8_t direction = (tileElement->GetDirection() - trackElement->GetDirectionWithOffset(2)) & 3; + Direction direction = (tileElement->GetDirection() - direction_reverse(trackElement->GetDirection())) & 3; if (!(TrackSequenceProperties[trackType][trackSequence] & (1 << direction))) { diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 3298c5a8a3..93bf634e30 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -1198,7 +1198,7 @@ void footpath_update_queue_chains() if (tileElement->AsEntrance()->GetRideIndex() != rideIndex) continue; - uint8_t direction = tileElement->GetDirectionWithOffset(2); + Direction direction = direction_reverse(tileElement->GetDirection()); footpath_chain_ride_queue(rideIndex, i, location.x << 5, location.y << 5, tileElement, direction); } while (!(tileElement++)->IsLastForTile()); } @@ -1877,7 +1877,7 @@ void footpath_update_queue_entrance_banner(int32_t x, int32_t y, TileElement* ti if (tileElement->AsEntrance()->GetEntranceType() == ENTRANCE_TYPE_RIDE_ENTRANCE) { footpath_queue_chain_push(tileElement->AsEntrance()->GetRideIndex()); - footpath_chain_ride_queue(255, 0, x, y, tileElement, tileElement->GetDirectionWithOffset(2)); + footpath_chain_ride_queue(255, 0, x, y, tileElement, direction_reverse(tileElement->GetDirection())); } break; } diff --git a/src/openrct2/world/TileElement.cpp b/src/openrct2/world/TileElement.cpp index a9c75c643a..a514a9cbb9 100644 --- a/src/openrct2/world/TileElement.cpp +++ b/src/openrct2/world/TileElement.cpp @@ -28,18 +28,18 @@ void TileElementBase::SetType(uint8_t newType) this->type |= (newType & TILE_ELEMENT_TYPE_MASK); } -uint8_t TileElementBase::GetDirection() const +Direction TileElementBase::GetDirection() const { return this->type & TILE_ELEMENT_DIRECTION_MASK; } -void TileElementBase::SetDirection(uint8_t direction) +void TileElementBase::SetDirection(Direction direction) { this->type &= ~TILE_ELEMENT_DIRECTION_MASK; this->type |= (direction & TILE_ELEMENT_DIRECTION_MASK); } -uint8_t TileElementBase::GetDirectionWithOffset(uint8_t offset) const +Direction TileElementBase::GetDirectionWithOffset(uint8_t offset) const { return ((this->type & TILE_ELEMENT_DIRECTION_MASK) + offset) & TILE_ELEMENT_DIRECTION_MASK; } diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index 2e83797dd5..e921505757 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -67,9 +67,9 @@ struct TileElementBase uint8_t GetType() const; void SetType(uint8_t newType); - uint8_t GetDirection() const; - void SetDirection(uint8_t direction); - uint8_t GetDirectionWithOffset(uint8_t offset) const; + Direction GetDirection() const; + void SetDirection(Direction direction); + Direction GetDirectionWithOffset(uint8_t offset) const; bool IsLastForTile() const; void SetLastForTile(bool on); bool IsGhost() const;