From 3f1778269217c1e0cf3da84062deb5fbca06ba80 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Tue, 18 Sep 2018 14:04:23 +0200 Subject: [PATCH] Move direct access to maze entry to struct methods --- src/openrct2/actions/MazeSetTrackAction.hpp | 22 ++++++++++----------- src/openrct2/peep/Guest.cpp | 2 +- src/openrct2/ride/Track.cpp | 19 ++++++++++++++++-- src/openrct2/ride/Track.h | 1 - src/openrct2/ride/TrackDesign.cpp | 2 +- src/openrct2/ride/TrackDesignSave.cpp | 2 +- src/openrct2/ride/gentle/Maze.cpp | 2 +- src/openrct2/world/Entrance.cpp | 14 ++++++------- src/openrct2/world/TileElement.h | 5 +++++ test/testpaint/Compat.cpp | 5 ----- 10 files changed, 44 insertions(+), 30 deletions(-) diff --git a/src/openrct2/actions/MazeSetTrackAction.hpp b/src/openrct2/actions/MazeSetTrackAction.hpp index 0f8254361d..03f36d817b 100644 --- a/src/openrct2/actions/MazeSetTrackAction.hpp +++ b/src/openrct2/actions/MazeSetTrackAction.hpp @@ -233,7 +233,7 @@ public: tileElement->AsTrack()->SetTrackType(TRACK_ELEM_MAZE); tileElement->AsTrack()->SetRideIndex(_rideIndex); - tileElement->properties.track.maze_entry = 0xFFFF; + tileElement->AsTrack()->SetMazeEntry(0xFFFF); if (flags & GAME_COMMAND_FLAG_GHOST) { @@ -259,12 +259,12 @@ public: { uint8_t segmentOffset = MazeGetSegmentBit(_x, _y); - tileElement->properties.track.maze_entry &= ~(1 << segmentOffset); + tileElement->AsTrack()->MazeEntrySubtract(1 << segmentOffset); if (!_initialPlacement) { segmentOffset = byte_993CE9[(_direction + segmentOffset)]; - tileElement->properties.track.maze_entry &= ~(1 << segmentOffset); + tileElement->AsTrack()->MazeEntrySubtract(1 << segmentOffset); uint8_t temp_edx = byte_993CFC[segmentOffset]; if (temp_edx != 0xFF) @@ -277,11 +277,11 @@ public: if (previousTileElement != nullptr) { - previousTileElement->properties.track.maze_entry &= ~(1 << temp_edx); + previousTileElement->AsTrack()->MazeEntrySubtract(1 << temp_edx); } else { - tileElement->properties.track.maze_entry |= (1 << segmentOffset); + tileElement->AsTrack()->MazeEntryAdd(1 << segmentOffset); } } } @@ -312,16 +312,16 @@ public: uint32_t segmentBit = MazeGetSegmentBit(previousSegmentX, previousSegmentY); - tileElement->properties.track.maze_entry |= (1 << segmentBit); + tileElement->AsTrack()->MazeEntryAdd(1 << segmentBit); segmentBit--; - tileElement->properties.track.maze_entry |= (1 << segmentBit); + tileElement->AsTrack()->MazeEntryAdd(1 << segmentBit); segmentBit = (segmentBit - 4) & 0x0F; - tileElement->properties.track.maze_entry |= (1 << segmentBit); + tileElement->AsTrack()->MazeEntryAdd(1 << segmentBit); segmentBit = (segmentBit + 3) & 0x0F; do { - tileElement->properties.track.maze_entry |= (1 << segmentBit); + tileElement->AsTrack()->MazeEntryAdd(1 << segmentBit); uint32_t direction1 = byte_993D0C[segmentBit]; uint16_t nextElementX = floor2(previousSegmentX, 32) + CoordsDirectionDelta[direction1].x; @@ -333,7 +333,7 @@ public: if (tmp_tileElement != nullptr) { uint8_t edx11 = byte_993CFC[segmentBit]; - tmp_tileElement->properties.track.maze_entry |= 1 << (edx11); + tmp_tileElement->AsTrack()->MazeEntryAdd(1 << (edx11)); } segmentBit--; @@ -344,7 +344,7 @@ public: map_invalidate_tile(floor2(_x, 32), floor2(_y, 32), tileElement->base_height * 8, tileElement->clearance_height * 8); - if ((tileElement->properties.track.maze_entry & 0x8888) == 0x8888) + if ((tileElement->AsTrack()->GetMazeEntry() & 0x8888) == 0x8888) { Ride* ride = get_ride(_rideIndex); tile_element_remove(tileElement); diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index ad277e3660..fd397c9aaa 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -4754,7 +4754,7 @@ void rct_peep::UpdateRideMazePathfinding() } while (!(tileElement++)->IsLastForTile()); - uint16_t mazeEntry = track_element_get_maze_entry(tileElement); + uint16_t mazeEntry = tileElement->AsTrack()->GetMazeEntry(); uint16_t openHedges = 0; // var_37 is 3, 7, 11 or 15 diff --git a/src/openrct2/ride/Track.cpp b/src/openrct2/ride/Track.cpp index ce04e20e4b..d390b97c3c 100644 --- a/src/openrct2/ride/Track.cpp +++ b/src/openrct2/ride/Track.cpp @@ -2221,9 +2221,24 @@ void TrackElement::DecrementPhotoTimeout() } } -uint16_t track_element_get_maze_entry(const rct_tile_element* tileElement) +uint16_t TrackElement::GetMazeEntry() const { - return tileElement->properties.track.maze_entry; + return mazeEntry; +} + +void TrackElement::SetMazeEntry(uint16_t newMazeEntry) +{ + mazeEntry = newMazeEntry; +} + +void TrackElement::MazeEntryAdd(uint16_t addVal) +{ + mazeEntry |= addVal; +} + +void TrackElement::MazeEntrySubtract(uint16_t subVal) +{ + mazeEntry &= ~subVal; } uint8_t TrackElement::GetTrackType() const diff --git a/src/openrct2/ride/Track.h b/src/openrct2/ride/Track.h index 9fbfdcde9f..65017bc652 100644 --- a/src/openrct2/ride/Track.h +++ b/src/openrct2/ride/Track.h @@ -559,4 +559,3 @@ void game_command_set_brakes_speed( int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp); bool track_element_is_booster(uint8_t rideType, uint8_t trackType); bool track_element_has_speed_setting(uint8_t trackType); -uint16_t track_element_get_maze_entry(const rct_tile_element* tileElement); diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index 0323fe92b0..b34edf6fe9 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -2108,7 +2108,7 @@ static money32 place_maze_design(uint8_t flags, uint8_t rideIndex, uint16_t maze tileElement->type = TILE_ELEMENT_TYPE_TRACK; tileElement->AsTrack()->SetTrackType(TRACK_ELEM_MAZE); tileElement->AsTrack()->SetRideIndex(rideIndex); - tileElement->properties.track.maze_entry = mazeEntry; + tileElement->AsTrack()->SetMazeEntry(mazeEntry); if (flags & GAME_COMMAND_FLAG_GHOST) { tileElement->flags |= TILE_ELEMENT_FLAG_GHOST; diff --git a/src/openrct2/ride/TrackDesignSave.cpp b/src/openrct2/ride/TrackDesignSave.cpp index 9674284610..07b51b8669 100644 --- a/src/openrct2/ride/TrackDesignSave.cpp +++ b/src/openrct2/ride/TrackDesignSave.cpp @@ -892,7 +892,7 @@ static bool track_design_save_to_td6_for_maze(uint8_t rideIndex, rct_track_td6* if (tileElement->AsTrack()->GetRideIndex() != rideIndex) continue; - maze->maze_entry = track_element_get_maze_entry(tileElement); + maze->maze_entry = tileElement->AsTrack()->GetMazeEntry(); maze->x = (x - startX) / 32; maze->y = (y - startY) / 32; maze++; diff --git a/src/openrct2/ride/gentle/Maze.cpp b/src/openrct2/ride/gentle/Maze.cpp index b57eba3b47..24c11fdc61 100644 --- a/src/openrct2/ride/gentle/Maze.cpp +++ b/src/openrct2/ride/gentle/Maze.cpp @@ -48,7 +48,7 @@ static void maze_paint_setup( paint_session* session, uint8_t rideIndex, uint8_t trackSequence, uint8_t direction, int32_t height, const rct_tile_element* tileElement) { - uint16_t maze_entry = track_element_get_maze_entry(tileElement); + uint16_t maze_entry = tileElement->AsTrack()->GetMazeEntry(); maze_entry = rol16(maze_entry, direction * 4); uint32_t rotation = session->CurrentRotation; diff --git a/src/openrct2/world/Entrance.cpp b/src/openrct2/world/Entrance.cpp index f8ee3635c3..cba0966b0b 100644 --- a/src/openrct2/world/Entrance.cpp +++ b/src/openrct2/world/Entrance.cpp @@ -565,9 +565,9 @@ void maze_entrance_hedge_replacement(int32_t x, int32_t y, rct_tile_element* til // Each maze element is split into 4 sections with 4 different walls uint8_t mazeSection = direction * 4; // Add the top outer wall - tileElement->properties.track.maze_entry |= (1 << ((mazeSection + 9) & 0x0F)); + tileElement->AsTrack()->MazeEntryAdd(1 << ((mazeSection + 9) & 0x0F)); // Add the bottom outer wall - tileElement->properties.track.maze_entry |= (1 << ((mazeSection + 12) & 0x0F)); + tileElement->AsTrack()->MazeEntryAdd(1 << ((mazeSection + 12) & 0x0F)); map_invalidate_tile(x, y, tileElement->base_height * 8, tileElement->clearance_height * 8); return; @@ -601,15 +601,15 @@ void maze_entrance_hedge_removal(int32_t x, int32_t y, rct_tile_element* tileEle // Each maze element is split into 4 sections with 4 different walls uint8_t mazeSection = direction * 4; // Remove the top outer wall - tileElement->properties.track.maze_entry &= ~(1 << ((mazeSection + 9) & 0x0F)); + tileElement->AsTrack()->MazeEntrySubtract(1 << ((mazeSection + 9) & 0x0F)); // Remove the bottom outer wall - tileElement->properties.track.maze_entry &= ~(1 << ((mazeSection + 12) & 0x0F)); + tileElement->AsTrack()->MazeEntrySubtract(1 << ((mazeSection + 12) & 0x0F)); // Remove the intersecting wall - tileElement->properties.track.maze_entry &= ~(1 << ((mazeSection + 10) & 0x0F)); + tileElement->AsTrack()->MazeEntrySubtract(1 << ((mazeSection + 10) & 0x0F)); // Remove the top hedge section - tileElement->properties.track.maze_entry &= ~(1 << ((mazeSection + 11) & 0x0F)); + tileElement->AsTrack()->MazeEntrySubtract(1 << ((mazeSection + 11) & 0x0F)); // Remove the bottom hedge section - tileElement->properties.track.maze_entry &= ~(1 << ((mazeSection + 15) & 0x0F)); + tileElement->AsTrack()->MazeEntrySubtract(1 << ((mazeSection + 15) & 0x0F)); map_invalidate_tile(x, y, tileElement->base_height * 8, tileElement->clearance_height * 8); return; diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index 957a483557..df4a42e7f8 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -287,6 +287,11 @@ public: uint8_t GetSeatRotation() const; void SetSeatRotation(uint8_t newSeatRotation); + uint16_t GetMazeEntry() const; + void SetMazeEntry(uint16_t newMazeEntry); + void MazeEntryAdd(uint16_t addVal); + void MazeEntrySubtract(uint16_t subVal); + bool IsTakingPhoto() const; void SetPhotoTimeout(); void DecrementPhotoTimeout(); diff --git a/test/testpaint/Compat.cpp b/test/testpaint/Compat.cpp index 50a78d872f..46ce48f0c0 100644 --- a/test/testpaint/Compat.cpp +++ b/test/testpaint/Compat.cpp @@ -194,11 +194,6 @@ bool is_csg_loaded() return false; } -uint16_t track_element_get_maze_entry(const rct_tile_element* tileElement) -{ - return tileElement->properties.track.maze_entry; -} - uint8_t TrackElement::GetTrackType() const { return trackType;