From 6a673cc7be1dca59b8aa5d0b7b2befb46a0ef437 Mon Sep 17 00:00:00 2001 From: Richard Fine Date: Mon, 26 Aug 2019 10:57:44 +0100 Subject: [PATCH 01/12] Introduce INVALID_DIRECTION constant --- src/openrct2/world/Location.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/openrct2/world/Location.hpp b/src/openrct2/world/Location.hpp index f05d28b534..99cfbce164 100644 --- a/src/openrct2/world/Location.hpp +++ b/src/openrct2/world/Location.hpp @@ -267,6 +267,8 @@ struct TileCoordsXYZ */ typedef uint8_t Direction; +const Direction INVALID_DIRECTION = 0xFF; + /** * Given a direction, return the direction that points the other way, * on the same axis. From 52b4717d85893cc996c10808894aa9296a3e634e Mon Sep 17 00:00:00 2001 From: Richard Fine Date: Mon, 26 Aug 2019 10:58:24 +0100 Subject: [PATCH 02/12] Use Direction type for PathElement SlopeDirection --- src/openrct2/world/Footpath.cpp | 8 ++++---- src/openrct2/world/TileElement.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index ed0e0edcdb..3298c5a8a3 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -1411,15 +1411,15 @@ void PathElement::SetSloped(bool isSloped) entryIndex |= FOOTPATH_PROPERTIES_FLAG_IS_SLOPED; } -uint8_t PathElement::GetSlopeDirection() const +Direction PathElement::GetSlopeDirection() const { - return entryIndex & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK; + return static_cast(entryIndex & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK); } -void PathElement::SetSlopeDirection(uint8_t newSlope) +void PathElement::SetSlopeDirection(Direction newSlope) { entryIndex &= ~FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK; - entryIndex |= newSlope & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK; + entryIndex |= static_cast(newSlope) & FOOTPATH_PROPERTIES_SLOPE_DIRECTION_MASK; } bool PathElement::IsQueue() const diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index f7f2acd843..2e83797dd5 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -203,8 +203,8 @@ public: bool IsSloped() const; void SetSloped(bool isSloped); - uint8_t GetSlopeDirection() const; - void SetSlopeDirection(uint8_t newSlope); + Direction GetSlopeDirection() const; + void SetSlopeDirection(Direction newSlope); ride_id_t GetRideIndex() const; void SetRideIndex(ride_id_t newRideIndex); From 06b2f66ba15a54e97573789e8d155aab0607ec1d Mon Sep 17 00:00:00 2001 From: Richard Fine Date: Mon, 26 Aug 2019 10:59:46 +0100 Subject: [PATCH 03/12] Use Direction type for peep::direction --- src/openrct2/peep/Peep.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2/peep/Peep.h b/src/openrct2/peep/Peep.h index 1a7cb375e8..0f99a1a7d4 100644 --- a/src/openrct2/peep/Peep.h +++ b/src/openrct2/peep/Peep.h @@ -615,7 +615,7 @@ struct Peep : rct_sprite_common union { uint8_t maze_last_edge; // 0x78 - uint8_t direction; // Direction ? + Direction direction; // Direction ? }; uint8_t interaction_ride_index; uint16_t time_in_queue; // 0x7A From 6449393d50890d2d7e2e2e883e09de0b83c5a6be Mon Sep 17 00:00:00 2001 From: Richard Fine Date: Mon, 26 Aug 2019 10:59:59 +0100 Subject: [PATCH 04/12] Use Direction type in a bunch of the pathfinding code --- src/openrct2/peep/GuestPathfinding.cpp | 62 +++++++++++++------------- src/openrct2/peep/Peep.h | 2 +- src/openrct2/peep/Staff.cpp | 4 +- test/tests/Pathfinding.cpp | 4 +- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index 36392ce5eb..5429852da1 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -33,7 +33,7 @@ static int32_t guest_surface_path_finding(Peep* peep); static struct { TileCoordsXYZ location; - uint8_t direction; + Direction direction; } _peepPathFindHistory[16]; enum @@ -105,9 +105,9 @@ static int32_t path_get_permitted_edges(PathElement* pathElement) * * rct2: 0x0069524E */ -static int32_t peep_move_one_tile(uint8_t direction, Peep* peep) +static int32_t peep_move_one_tile(Direction direction, Peep* peep) { - assert(direction <= 3); + assert(direction_valid(direction)); int16_t x = peep->next_x; int16_t y = peep->next_y; x += CoordsDirectionDelta[direction].x; @@ -139,13 +139,13 @@ static int32_t guest_surface_path_finding(Peep* peep) int16_t x = peep->next_x; int16_t y = peep->next_y; int16_t z = peep->next_z; - uint8_t randDirection = scenario_rand() & 3; + Direction randDirection = scenario_rand() & 3; if (!fence_in_the_way(x, y, z, z + 4, randDirection)) { x += CoordsDirectionDelta[randDirection].x; y += CoordsDirectionDelta[randDirection].y; - uint8_t backwardsDirection = direction_reverse(randDirection); + Direction backwardsDirection = direction_reverse(randDirection); if (!fence_in_the_way(x, y, z, z + 4, backwardsDirection)) { @@ -170,7 +170,7 @@ static int32_t guest_surface_path_finding(Peep* peep) { x += CoordsDirectionDelta[randDirection].x; y += CoordsDirectionDelta[randDirection].y; - uint8_t backwardsDirection = direction_reverse(randDirection); + Direction backwardsDirection = direction_reverse(randDirection); if (!fence_in_the_way(x, y, z, z + 4, backwardsDirection)) { @@ -190,7 +190,7 @@ static int32_t guest_surface_path_finding(Peep* peep) { x += CoordsDirectionDelta[randDirection].x; y += CoordsDirectionDelta[randDirection].y; - uint8_t backwardsDirection = direction_reverse(randDirection); + Direction backwardsDirection = direction_reverse(randDirection); if (!fence_in_the_way(x, y, z, z + 4, backwardsDirection)) { @@ -223,7 +223,7 @@ static int32_t guest_surface_path_finding(Peep* peep) * Returns the type of the next footpath tile a peep can get to from x,y,z / * inputTileElement in the given direction. */ -static uint8_t footpath_element_next_in_direction(TileCoordsXYZ loc, PathElement* pathElement, uint8_t chosenDirection) +static uint8_t footpath_element_next_in_direction(TileCoordsXYZ loc, PathElement* pathElement, Direction chosenDirection) { TileElement* nextTileElement; @@ -275,10 +275,10 @@ static uint8_t footpath_element_next_in_direction(TileCoordsXYZ loc, PathElement * * This is the recursive portion of footpath_element_destination_in_direction(). */ -static uint8_t footpath_element_dest_in_dir(TileCoordsXYZ loc, uint8_t chosenDirection, ride_id_t* outRideIndex, int32_t level) +static uint8_t footpath_element_dest_in_dir(TileCoordsXYZ loc, Direction chosenDirection, ride_id_t* outRideIndex, int32_t level) { TileElement* tileElement; - int32_t direction; + Direction direction; if (level > 25) return PATH_SEARCH_LIMIT_REACHED; @@ -393,7 +393,7 @@ static uint8_t footpath_element_dest_in_dir(TileCoordsXYZ loc, uint8_t chosenDir * width path, for example that leads from a ride exit back to the main path. */ static uint8_t footpath_element_destination_in_direction( - TileCoordsXYZ loc, PathElement* pathElement, uint8_t chosenDirection, ride_id_t* outRideIndex) + TileCoordsXYZ loc, PathElement* pathElement, Direction chosenDirection, ride_id_t* outRideIndex) { if (pathElement->IsSloped()) { @@ -423,7 +423,7 @@ static int32_t guest_path_find_aimless(Peep* peep, uint8_t edges) while (true) { - uint8_t direction = scenario_rand() & 3; + Direction direction = scenario_rand() & 3; // Otherwise go in a random direction allowed from the tile. if (edges & (1 << direction)) { @@ -596,7 +596,7 @@ static int32_t CalculateHeuristicPathingScore(TileCoordsXYZ loc1, TileCoordsXYZ */ static void peep_pathfind_heuristic_search( TileCoordsXYZ loc, Peep* peep, TileElement* currentTileElement, bool inPatrolArea, uint8_t counter, uint16_t* endScore, - int32_t test_edge, uint8_t* endJunctions, TileCoordsXYZ junctionList[16], uint8_t directionList[16], TileCoordsXYZ* endXYZ, + Direction test_edge, uint8_t* endJunctions, TileCoordsXYZ junctionList[16], uint8_t directionList[16], TileCoordsXYZ* endXYZ, uint8_t* endSteps) { uint8_t searchResult = PATH_SEARCH_FAILED; @@ -680,7 +680,7 @@ static void peep_pathfind_heuristic_search( case TILE_ELEMENT_TYPE_ENTRANCE: if (loc.z != tileElement->base_height) continue; - int32_t direction; + Direction direction; searchResult = PATH_SEARCH_OTHER; switch (tileElement->AsEntrance()->GetEntranceType()) { @@ -905,7 +905,7 @@ static void peep_pathfind_heuristic_search( #endif // defined(DEBUG_LEVEL_2) && DEBUG_LEVEL_2 /* Remove the reverse edge (i.e. the edge back to the previous map element.) */ - edges &= ~(1 << (test_edge ^ 2)); + edges &= ~(1 << direction_reverse(test_edge)); int32_t next_test_edge = bitscanforward(edges); @@ -1162,7 +1162,7 @@ static void peep_pathfind_heuristic_search( * * rct2: 0x0069A5F0 */ -int32_t peep_pathfind_choose_direction(TileCoordsXYZ loc, Peep* peep) +Direction peep_pathfind_choose_direction(TileCoordsXYZ loc, Peep* peep) { // The max number of thin junctions searched - a per-search-path limit. _peepPathFindMaxJunctions = peep_pathfind_get_max_number_junctions(peep); @@ -1231,7 +1231,7 @@ int32_t peep_pathfind_choose_direction(TileCoordsXYZ loc, Peep* peep) } while (!(dest_tile_element++)->IsLastForTile()); // Peep is not on a path. if (!found) - return -1; + return INVALID_DIRECTION; permitted_edges &= 0xF; uint8_t edges = permitted_edges; @@ -1302,7 +1302,7 @@ int32_t peep_pathfind_choose_direction(TileCoordsXYZ loc, Peep* peep) /* If this is a new goal for the peep. Store it and reset the peep's * pathfind_history. */ - if (peep->pathfind_goal.direction > 3 || peep->pathfind_goal.x != goal.x || peep->pathfind_goal.y != goal.y + if (!direction_valid(peep->pathfind_goal.direction) || peep->pathfind_goal.x != goal.x || peep->pathfind_goal.y != goal.y || peep->pathfind_goal.z != goal.z) { peep->pathfind_goal.x = goal.x; @@ -1322,7 +1322,7 @@ int32_t peep_pathfind_choose_direction(TileCoordsXYZ loc, Peep* peep) // Peep has tried all edges. if (edges == 0) - return -1; + return INVALID_DIRECTION; int32_t chosen_edge = bitscanforward(edges); @@ -1465,7 +1465,7 @@ int32_t peep_pathfind_choose_direction(TileCoordsXYZ loc, Peep* peep) log_verbose("Pathfind heuristic search failed."); } #endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 - return -1; + return INVALID_DIRECTION; } #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 if (gPathFindDebug) @@ -1578,9 +1578,9 @@ static int32_t guest_path_find_entering_park(Peep* peep, uint8_t edges) gPeepPathFindIgnoreForeignQueues = true; gPeepPathFindQueueRideIndex = RIDE_ID_NULL; - int32_t chosenDirection = peep_pathfind_choose_direction({ peep->next_x / 32, peep->next_y / 32, peep->next_z }, peep); + Direction chosenDirection = peep_pathfind_choose_direction({ peep->next_x / 32, peep->next_y / 32, peep->next_z }, peep); - if (chosenDirection == -1) + if (chosenDirection == INVALID_DIRECTION) return guest_path_find_aimless(peep, edges); else return peep_move_one_tile(chosenDirection, peep); @@ -1628,7 +1628,7 @@ static int32_t guest_path_find_leaving_park(Peep* peep, uint8_t edges) int16_t x = peepSpawn->x & 0xFFE0; int16_t y = peepSpawn->y & 0xFFE0; uint8_t z = peepSpawn->z / 8; - uint8_t direction = peepSpawn->direction; + Direction direction = peepSpawn->direction; gPeepPathFindGoalPosition = { x / 32, y / 32, z }; if (x == peep->next_x && y == peep->next_y) @@ -1639,7 +1639,7 @@ static int32_t guest_path_find_leaving_park(Peep* peep, uint8_t edges) gPeepPathFindIgnoreForeignQueues = true; gPeepPathFindQueueRideIndex = RIDE_ID_NULL; direction = peep_pathfind_choose_direction({ peep->next_x / 32, peep->next_y / 32, peep->next_z }, peep); - if (direction == 0xFF) + if (direction == INVALID_DIRECTION) return guest_path_find_aimless(peep, edges); else return peep_move_one_tile(direction, peep); @@ -1694,13 +1694,13 @@ static int32_t guest_path_find_park_entrance(Peep* peep, uint8_t edges) pathfind_logging_enable(peep); #endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 - int32_t chosenDirection = peep_pathfind_choose_direction({ peep->next_x / 32, peep->next_y / 32, peep->next_z }, peep); + Direction chosenDirection = peep_pathfind_choose_direction({ peep->next_x / 32, peep->next_y / 32, peep->next_z }, peep); #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 pathfind_logging_disable(); #endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 - if (chosenDirection == -1) + if (chosenDirection == INVALID_DIRECTION) return guest_path_find_aimless(peep, edges); else return peep_move_one_tile(chosenDirection, peep); @@ -1740,7 +1740,7 @@ static void get_ride_queue_end(TileCoordsXYZ& loc) if (!found) return; - uint8_t direction = tileElement->GetDirectionWithOffset(2); + Direction direction = tileElement->GetDirectionWithOffset(2); TileElement* lastPathElement = nullptr; TileElement* firstPathElement = nullptr; @@ -1889,7 +1889,7 @@ int32_t guest_path_finding(Guest* peep) /* If this tileElement is adjacent to any non-wide paths, * remove all of the edges to wide paths. */ uint8_t adjustedEdges = edges; - for (int32_t chosenDirection = 0; chosenDirection < 4; chosenDirection++) + for (Direction chosenDirection = 0; direction_valid(chosenDirection); chosenDirection++) { // If there is no path in that direction try another if (!(adjustedEdges & (1 << chosenDirection))) @@ -1906,7 +1906,7 @@ int32_t guest_path_finding(Guest* peep) edges = adjustedEdges; } - int8_t direction = direction_reverse(peep->direction); + int32_t direction = direction_reverse(peep->direction); // Check if in a dead end (i.e. only edge is where the peep came from) if (!(edges & ~(1 << direction))) { @@ -1971,7 +1971,7 @@ int32_t guest_path_finding(Guest* peep) if (!peep->HasFood() && (scenario_rand() & 0xFFFF) >= 2184) { uint8_t adjustedEdges = edges; - for (int32_t chosenDirection = 0; chosenDirection < 4; chosenDirection++) + for (Direction chosenDirection = 0; direction_valid(chosenDirection); chosenDirection++) { // If there is no path in that direction try another if (!(adjustedEdges & (1 << chosenDirection))) @@ -2134,7 +2134,7 @@ int32_t guest_path_finding(Guest* peep) direction = peep_pathfind_choose_direction({ peep->next_x / 32, peep->next_y / 32, peep->next_z }, peep); - if (direction == -1) + if (direction == INVALID_DIRECTION) { /* Heuristic search failed for all directions. * Reset the pathfind_goal - this means that the pathfind_history diff --git a/src/openrct2/peep/Peep.h b/src/openrct2/peep/Peep.h index 0f99a1a7d4..9e272e85ae 100644 --- a/src/openrct2/peep/Peep.h +++ b/src/openrct2/peep/Peep.h @@ -983,7 +983,7 @@ void peep_update_names(bool realNames); void guest_set_name(uint16_t spriteIndex, const char* name); -int32_t peep_pathfind_choose_direction(TileCoordsXYZ loc, Peep* peep); +Direction peep_pathfind_choose_direction(TileCoordsXYZ loc, Peep* peep); void peep_reset_pathfind_goal(Peep* peep); bool is_valid_path_z_and_direction(TileElement* tileElement, int32_t currentZ, int32_t currentDirection); diff --git a/src/openrct2/peep/Staff.cpp b/src/openrct2/peep/Staff.cpp index 152eb19293..89556e215e 100644 --- a/src/openrct2/peep/Staff.cpp +++ b/src/openrct2/peep/Staff.cpp @@ -847,14 +847,14 @@ static uint8_t staff_mechanic_direction_path(Peep* peep, uint8_t validDirections pathfind_logging_enable(peep); #endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 - int32_t pathfindDirection = peep_pathfind_choose_direction( + Direction pathfindDirection = peep_pathfind_choose_direction( { peep->next_x / 32, peep->next_y / 32, peep->next_z }, peep); #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 pathfind_logging_disable(); #endif // defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 - if (pathfindDirection == -1) + if (pathfindDirection == INVALID_DIRECTION) { /* Heuristic search failed for all directions. * Reset the pathfind_goal - this means that the pathfind_history diff --git a/test/tests/Pathfinding.cpp b/test/tests/Pathfinding.cpp index 8670952dd2..57a05cb9be 100644 --- a/test/tests/Pathfinding.cpp +++ b/test/tests/Pathfinding.cpp @@ -83,8 +83,8 @@ protected: // Pick the direction the peep should initially move in, given the goal position. // This will also store the goal position and initialize pathfinding data for the peep. gPeepPathFindGoalPosition = goal; - const int32_t moveDir = peep_pathfind_choose_direction(*pos, peep); - if (moveDir < 0) + const Direction moveDir = peep_pathfind_choose_direction(*pos, peep); + if (moveDir == INVALID_DIRECTION) { // Couldn't determine a direction to move off in return false; From 5ff78e48c7b62d7165a3a206e267264b8b2ae965 Mon Sep 17 00:00:00 2001 From: Richard Fine Date: Mon, 26 Aug 2019 11:25:57 +0100 Subject: [PATCH 05/12] 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; From 0e04dbeea1508cd30039109a867f9fa59bf0511b Mon Sep 17 00:00:00 2001 From: Richard Fine Date: Mon, 26 Aug 2019 14:15:44 +0100 Subject: [PATCH 06/12] Allow SwapBE to swap non-uint types If we want to have more semantically meaningful types (like Direction), it's useful to be able to support those in the DataSerializer too. Swapping bytes for entire structures is probably never going to make sense, but for types that are pure wrappers around integer types, we want to be able to swap them as if they were the integer they wrap. --- src/openrct2/core/Endianness.h | 8 ++++++- test/tests/Endianness.cpp | 43 ++++++++++++++++++++++++++++++++++ test/tests/tests.vcxproj | 1 + 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 test/tests/Endianness.cpp diff --git a/src/openrct2/core/Endianness.h b/src/openrct2/core/Endianness.h index 16d024cfbc..e0d065f512 100644 --- a/src/openrct2/core/Endianness.h +++ b/src/openrct2/core/Endianness.h @@ -17,6 +17,7 @@ template struct ByteSwapT template<> struct ByteSwapT<1> { + typedef uint8_t UIntType; static uint8_t SwapBE(uint8_t value) { return value; @@ -25,6 +26,7 @@ template<> struct ByteSwapT<1> template<> struct ByteSwapT<2> { + typedef uint16_t UIntType; static uint16_t SwapBE(uint16_t value) { return (uint16_t)((value << 8) | (value >> 8)); @@ -33,6 +35,7 @@ template<> struct ByteSwapT<2> template<> struct ByteSwapT<4> { + typedef uint32_t UIntType; static uint32_t SwapBE(uint32_t value) { return (uint32_t)(((value << 24) | ((value << 8) & 0x00FF0000) | ((value >> 8) & 0x0000FF00) | (value >> 24))); @@ -41,6 +44,7 @@ template<> struct ByteSwapT<4> template<> struct ByteSwapT<8> { + typedef uint64_t UIntType; static uint64_t SwapBE(uint64_t value) { value = (value & 0x00000000FFFFFFFF) << 32 | (value & 0xFFFFFFFF00000000) >> 32; @@ -52,5 +56,7 @@ template<> struct ByteSwapT<8> template static T ByteSwapBE(const T& value) { - return ByteSwapT::SwapBE(value); + typedef ByteSwapT ByteSwap; + typename ByteSwap::UIntType result = ByteSwap::SwapBE(reinterpret_cast(value)); + return *reinterpret_cast(&result); } diff --git a/test/tests/Endianness.cpp b/test/tests/Endianness.cpp new file mode 100644 index 0000000000..b673360797 --- /dev/null +++ b/test/tests/Endianness.cpp @@ -0,0 +1,43 @@ +#include "openrct2/core/Endianness.h" + +#include + +TEST(SwapBETest, ForUInt8_DoesNothing) +{ + uint8_t before = 0x12; + uint8_t after = ByteSwapBE(before); + ASSERT_EQ(before, after); +} + +TEST(SwapBETest, ForUInt16_SwapsBytes) +{ + uint16_t before = 0x1234; + uint16_t after = ByteSwapBE(before); + ASSERT_EQ(0x3412u, after); +} + +TEST(SwapBETest, ForUInt32_SwapsBytes) +{ + uint32_t before = 0x12345678; + uint32_t after = ByteSwapBE(before); + ASSERT_EQ(0x78563412u, after); +} + +TEST(SwapBETest, ForUInt64_SwapsBytes) +{ + uint64_t before = 0x1234567887654321; + uint64_t after = ByteSwapBE(before); + ASSERT_EQ(0x2143658778563412u, after); +} + +TEST(SwapBETest, ForCustomBlittableType_SwapsBytes) +{ + struct MyStruct + { + uint16_t value; + }; + + MyStruct before = { 0x1234 }; + MyStruct after = ByteSwapBE(before); + ASSERT_EQ(0x3412, after.value); +} diff --git a/test/tests/tests.vcxproj b/test/tests/tests.vcxproj index f4d448af46..cc19c85c7f 100644 --- a/test/tests/tests.vcxproj +++ b/test/tests/tests.vcxproj @@ -58,6 +58,7 @@ + From 9123fa74d3e4e342a2581abbc126ec5624521de3 Mon Sep 17 00:00:00 2001 From: Richard Fine Date: Mon, 26 Aug 2019 18:50:37 +0100 Subject: [PATCH 07/12] Add ALL_DIRECTIONS array --- src/openrct2/world/Location.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/openrct2/world/Location.hpp b/src/openrct2/world/Location.hpp index 99cfbce164..2e78283227 100644 --- a/src/openrct2/world/Location.hpp +++ b/src/openrct2/world/Location.hpp @@ -269,6 +269,11 @@ typedef uint8_t Direction; const Direction INVALID_DIRECTION = 0xFF; +/** + * Array of all valid cardinal directions, to make it easy to write range-based for loops like: for (Direction d : ALL_DIRECTIONS) + */ +constexpr Direction ALL_DIRECTIONS[] = { 0, 1, 2, 3 }; + /** * Given a direction, return the direction that points the other way, * on the same axis. From caa6ad71c761795bf256c4da884598ddbbacdd41 Mon Sep 17 00:00:00 2001 From: Richard Fine Date: Mon, 26 Aug 2019 18:50:50 +0100 Subject: [PATCH 08/12] Add direction_next and direction_prev helpers --- src/openrct2/world/Location.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/openrct2/world/Location.hpp b/src/openrct2/world/Location.hpp index 2e78283227..34fa4f1c21 100644 --- a/src/openrct2/world/Location.hpp +++ b/src/openrct2/world/Location.hpp @@ -288,6 +288,22 @@ constexpr Direction ALL_DIRECTIONS[] = { 0, 1, 2, 3 }; return dir < 4; } +/** + * Given a direction, return the next cardinal direction, wrapping around if necessary. (TODO: Figure out if this is CW or CCW) + */ +[[maybe_unused]] static constexpr Direction direction_next(Direction dir) +{ + return (dir + 1) & 0x03; +} + +/** + * Given a direction, return the previous cardinal direction, wrapping around if necessary. (TODO: Figure out if this is CW or CCW) + */ +[[maybe_unused]] static constexpr Direction direction_prev(Direction dir) +{ + return (dir - 1) & 0x03; +} + struct CoordsXYZD : public CoordsXYZ { Direction direction = 0; From bf3461e014ee9819bdc081fce4be3e76b44142b0 Mon Sep 17 00:00:00 2001 From: Richard Fine Date: Sun, 1 Sep 2019 15:40:10 +0100 Subject: [PATCH 09/12] Restrict FootpathPlaceAction more correctly direction_valid() restricts the direction to 0-3, not 0-15. As discussed on Gitter, this is more correct. --- src/openrct2/actions/FootpathPlaceAction.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2/actions/FootpathPlaceAction.hpp b/src/openrct2/actions/FootpathPlaceAction.hpp index 0474cbfc25..8380d794d4 100644 --- a/src/openrct2/actions/FootpathPlaceAction.hpp +++ b/src/openrct2/actions/FootpathPlaceAction.hpp @@ -88,7 +88,7 @@ public: return MakeResult(GA_ERROR::DISALLOWED, STR_CANT_BUILD_FOOTPATH_HERE, STR_TOO_HIGH); } - if (_direction != 0xFF && _direction > 15) + if (_direction != INVALID_DIRECTION && !direction_valid(_direction)) { log_error("Direction invalid. direction = %u", _direction); return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_CANT_BUILD_FOOTPATH_HERE); From 3131bfdc74ad62e31e730fc22308d274e4c2292f Mon Sep 17 00:00:00 2001 From: Richard Fine Date: Sun, 1 Sep 2019 15:49:53 +0100 Subject: [PATCH 10/12] Use INVALID_DIRECTION in a bunch of places --- src/openrct2/actions/FootpathPlaceAction.hpp | 6 +++--- src/openrct2/actions/WallPlaceAction.hpp | 2 +- src/openrct2/peep/Staff.cpp | 20 ++++++++++---------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/openrct2/actions/FootpathPlaceAction.hpp b/src/openrct2/actions/FootpathPlaceAction.hpp index 8380d794d4..ec765b0277 100644 --- a/src/openrct2/actions/FootpathPlaceAction.hpp +++ b/src/openrct2/actions/FootpathPlaceAction.hpp @@ -28,11 +28,11 @@ private: CoordsXYZ _loc; uint8_t _slope; uint8_t _type; - uint8_t _direction = 0xFF; + Direction _direction = INVALID_DIRECTION; public: FootpathPlaceAction() = default; - FootpathPlaceAction(CoordsXYZ loc, uint8_t slope, uint8_t type, uint8_t direction = 0xFF) + FootpathPlaceAction(CoordsXYZ loc, uint8_t slope, uint8_t type, Direction direction = INVALID_DIRECTION) : _loc(loc) , _slope(slope) , _type(type) @@ -127,7 +127,7 @@ public: if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST)) { - if (_direction != 0xFF && !gCheatsDisableClearanceChecks) + if (_direction != INVALID_DIRECTION && !gCheatsDisableClearanceChecks) { // It is possible, let's remove walls between the old and new piece of path auto zLow = _loc.z / 8; diff --git a/src/openrct2/actions/WallPlaceAction.hpp b/src/openrct2/actions/WallPlaceAction.hpp index ebeb0cef5c..6598dfeacd 100644 --- a/src/openrct2/actions/WallPlaceAction.hpp +++ b/src/openrct2/actions/WallPlaceAction.hpp @@ -54,7 +54,7 @@ DEFINE_GAME_ACTION(WallPlaceAction, GAME_COMMAND_PLACE_WALL, WallPlaceActionResu private: int32_t _wallType{ -1 }; CoordsXYZ _loc; - uint8_t _edge{ std::numeric_limits::max() }; + Direction _edge{ INVALID_DIRECTION }; int32_t _primaryColour; int32_t _secondaryColour; int32_t _tertiaryColour; diff --git a/src/openrct2/peep/Staff.cpp b/src/openrct2/peep/Staff.cpp index 89556e215e..f0f8d97dc8 100644 --- a/src/openrct2/peep/Staff.cpp +++ b/src/openrct2/peep/Staff.cpp @@ -514,15 +514,15 @@ static uint8_t staff_handyman_direction_to_uncut_grass(Peep* peep, uint8_t valid auto surfaceElement = map_get_surface_element_at({ peep->next_x, peep->next_y }); if (peep->next_z != surfaceElement->base_height) - return 0xFF; + return INVALID_DIRECTION; if (peep->GetNextIsSloped()) { if (surfaceElement->GetSlope() != PathSlopeToLandSlope[peep->GetNextDirection()]) - return 0xFF; + return INVALID_DIRECTION; } else if (surfaceElement->GetSlope() != TILE_ELEMENT_SLOPE_FLAT) - return 0xFF; + return INVALID_DIRECTION; } uint8_t chosenDirection = scenario_rand() & 0x3; @@ -553,7 +553,7 @@ static uint8_t staff_handyman_direction_to_uncut_grass(Peep* peep, uint8_t valid } } } - return 0xFF; + return INVALID_DIRECTION; } /** @@ -600,13 +600,13 @@ static bool staff_path_finding_handyman(Peep* peep) litterDirection = staff_handyman_direction_to_nearest_litter(peep); } - uint8_t direction = 0xFF; + Direction direction = INVALID_DIRECTION; if (litterDirection == 0xFF && (peep->staff_orders & STAFF_ORDERS_MOWING) && peep->staff_mowing_timeout >= 12) { direction = staff_handyman_direction_to_uncut_grass(peep, validDirections); } - if (direction == 0xFF) + if (direction == INVALID_DIRECTION) { if (peep->GetNextIsSurface()) { @@ -784,7 +784,7 @@ static uint8_t staff_mechanic_direction_path_rand(Peep* peep, uint8_t pathDirect */ static uint8_t staff_mechanic_direction_path(Peep* peep, uint8_t validDirections, PathElement* pathElement) { - uint8_t direction = 0xFF; + Direction direction = INVALID_DIRECTION; uint8_t pathDirections = pathElement->GetEdges(); pathDirections &= validDirections; @@ -878,7 +878,7 @@ static uint8_t staff_mechanic_direction_path(Peep* peep, uint8_t validDirections static bool staff_path_finding_mechanic(Peep* peep) { uint8_t validDirections = staff_get_valid_patrol_directions(peep, peep->next_x, peep->next_y); - uint8_t direction = 0xFF; + Direction direction = INVALID_DIRECTION; if (peep->GetNextIsSurface()) { direction = staff_mechanic_direction_surface(peep); @@ -919,7 +919,7 @@ static bool staff_path_finding_mechanic(Peep* peep) */ static uint8_t staff_direction_path(Peep* peep, uint8_t validDirections, PathElement* pathElement) { - uint8_t direction = 0xFF; + Direction direction = INVALID_DIRECTION; uint8_t pathDirections = pathElement->GetEdges(); if (peep->state != PEEP_STATE_ANSWERING && peep->state != PEEP_STATE_HEADING_TO_INSPECTION) { @@ -966,7 +966,7 @@ static bool staff_path_finding_misc(Peep* peep) { uint8_t validDirections = staff_get_valid_patrol_directions(peep, peep->next_x, peep->next_y); - uint8_t direction = 0xFF; + Direction direction = INVALID_DIRECTION; if (peep->GetNextIsSurface()) { direction = staff_direction_surface(peep, scenario_rand() & 3); From 31ce0f20f7640aa5e355671da5e914611c7bb133 Mon Sep 17 00:00:00 2001 From: Richard Fine Date: Sun, 1 Sep 2019 16:25:50 +0100 Subject: [PATCH 11/12] Use range-based for loops for checking all directions --- src/openrct2/actions/LandSetHeightAction.hpp | 2 +- src/openrct2/actions/RideDemolishAction.hpp | 2 +- src/openrct2/peep/GuestPathfinding.cpp | 14 +++++++------- src/openrct2/peep/Staff.cpp | 2 +- src/openrct2/world/Footpath.cpp | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/openrct2/actions/LandSetHeightAction.hpp b/src/openrct2/actions/LandSetHeightAction.hpp index 23cfd10774..e6f329542b 100644 --- a/src/openrct2/actions/LandSetHeightAction.hpp +++ b/src/openrct2/actions/LandSetHeightAction.hpp @@ -339,7 +339,7 @@ private: money32 GetSurfaceHeightChangeCost(SurfaceElement * surfaceElement) const { money32 cost{ 0 }; - for (int32_t i = 0; i < 4; i += 1) + for (Direction i : ALL_DIRECTIONS) { int32_t cornerHeight = tile_element_get_corner_height(surfaceElement, i); cornerHeight -= map_get_corner_height(_height, _style & TILE_ELEMENT_SURFACE_SLOPE_MASK, i); diff --git a/src/openrct2/actions/RideDemolishAction.hpp b/src/openrct2/actions/RideDemolishAction.hpp index 3919e7e793..533e4a58f2 100644 --- a/src/openrct2/actions/RideDemolishAction.hpp +++ b/src/openrct2/actions/RideDemolishAction.hpp @@ -332,7 +332,7 @@ private: { 16, 0 }, }; - for (uint8_t dir = 0; dir < 4; dir++) + for (Direction dir : ALL_DIRECTIONS) { const LocationXY16& off = DirOffsets[dir]; money32 removePrice = MazeRemoveTrack(x + off.x, y + off.y, z, dir); diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index 0155d5729b..31d2b67b16 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -344,23 +344,23 @@ static uint8_t footpath_element_dest_in_dir(TileCoordsXYZ loc, Direction chosenD edges &= ~(1 << direction_reverse(chosenDirection)); loc.z = tileElement->base_height; - for (direction = 0; direction < 4; direction++) + for (Direction dir : ALL_DIRECTIONS) { - if (!(edges & (1 << direction))) + if (!(edges & (1 << dir))) continue; - edges &= ~(1 << direction); + edges &= ~(1 << dir); if (edges != 0) return PATH_SEARCH_JUNCTION; if (tileElement->AsPath()->IsSloped()) { - if (tileElement->AsPath()->GetSlopeDirection() == direction) + if (tileElement->AsPath()->GetSlopeDirection() == dir) { loc.z += 2; } } - return footpath_element_dest_in_dir(loc, direction, outRideIndex, level + 1); + return footpath_element_dest_in_dir(loc, dir, outRideIndex, level + 1); } return PATH_SEARCH_DEAD_END; } @@ -1889,7 +1889,7 @@ int32_t guest_path_finding(Guest* peep) /* If this tileElement is adjacent to any non-wide paths, * remove all of the edges to wide paths. */ uint8_t adjustedEdges = edges; - for (Direction chosenDirection = 0; direction_valid(chosenDirection); chosenDirection++) + for (Direction chosenDirection : ALL_DIRECTIONS) { // If there is no path in that direction try another if (!(adjustedEdges & (1 << chosenDirection))) @@ -1971,7 +1971,7 @@ int32_t guest_path_finding(Guest* peep) if (!peep->HasFood() && (scenario_rand() & 0xFFFF) >= 2184) { uint8_t adjustedEdges = edges; - for (Direction chosenDirection = 0; direction_valid(chosenDirection); chosenDirection++) + for (Direction chosenDirection : ALL_DIRECTIONS) { // If there is no path in that direction try another if (!(adjustedEdges & (1 << chosenDirection))) diff --git a/src/openrct2/peep/Staff.cpp b/src/openrct2/peep/Staff.cpp index f0f8d97dc8..bbbb63fbbf 100644 --- a/src/openrct2/peep/Staff.cpp +++ b/src/openrct2/peep/Staff.cpp @@ -234,7 +234,7 @@ bool staff_can_ignore_wide_flag(Peep* staff, int32_t x, int32_t y, uint8_t z, Ti uint8_t total = 0; uint8_t pathcount = 0; uint8_t widecount = 0; - for (int32_t adjac_dir = 0; adjac_dir <= 3; adjac_dir++) + for (Direction adjac_dir : ALL_DIRECTIONS) { int32_t adjac_x = x + CoordsDirectionDelta[adjac_dir].x; int32_t adjac_y = y + CoordsDirectionDelta[adjac_dir].y; diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 93bf634e30..6a63bc6feb 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -741,7 +741,7 @@ static bool footpath_disconnect_queue_from_path(int32_t x, int32_t y, TileElemen return true; } - for (int32_t direction = 0; direction < 4; direction++) + for (Direction direction : ALL_DIRECTIONS) { if ((action < 0) && (direction == tileElement->AsPath()->GetSlopeDirection())) continue; @@ -980,7 +980,7 @@ void footpath_connect_edges(int32_t x, int32_t y, TileElement* tileElement, int3 neighbour_list_init(&neighbourList); footpath_update_queue_entrance_banner(x, y, tileElement); - for (int32_t direction = 0; direction < 4; direction++) + for (Direction direction : ALL_DIRECTIONS) { loc_6A6C85(x, y, direction, tileElement, flags, true, &neighbourList); } From 92f50efedc135adde181d75d223e4e42b55ed4e0 Mon Sep 17 00:00:00 2001 From: Richard Fine Date: Sun, 1 Sep 2019 19:10:27 +0100 Subject: [PATCH 12/12] Formatting fixes --- src/openrct2/peep/GuestPathfinding.cpp | 7 ++++--- src/openrct2/peep/Peep.h | 2 +- src/openrct2/world/Location.hpp | 9 ++++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index 31d2b67b16..fe97345d05 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -275,7 +275,8 @@ static uint8_t footpath_element_next_in_direction(TileCoordsXYZ loc, PathElement * * This is the recursive portion of footpath_element_destination_in_direction(). */ -static uint8_t footpath_element_dest_in_dir(TileCoordsXYZ loc, Direction chosenDirection, ride_id_t* outRideIndex, int32_t level) +static uint8_t footpath_element_dest_in_dir( + TileCoordsXYZ loc, Direction chosenDirection, ride_id_t* outRideIndex, int32_t level) { TileElement* tileElement; Direction direction; @@ -596,8 +597,8 @@ static int32_t CalculateHeuristicPathingScore(TileCoordsXYZ loc1, TileCoordsXYZ */ static void peep_pathfind_heuristic_search( TileCoordsXYZ loc, Peep* peep, TileElement* currentTileElement, bool inPatrolArea, uint8_t counter, uint16_t* endScore, - Direction test_edge, uint8_t* endJunctions, TileCoordsXYZ junctionList[16], uint8_t directionList[16], TileCoordsXYZ* endXYZ, - uint8_t* endSteps) + Direction test_edge, uint8_t* endJunctions, TileCoordsXYZ junctionList[16], uint8_t directionList[16], + TileCoordsXYZ* endXYZ, uint8_t* endSteps) { uint8_t searchResult = PATH_SEARCH_FAILED; diff --git a/src/openrct2/peep/Peep.h b/src/openrct2/peep/Peep.h index 9e272e85ae..4474244de6 100644 --- a/src/openrct2/peep/Peep.h +++ b/src/openrct2/peep/Peep.h @@ -615,7 +615,7 @@ struct Peep : rct_sprite_common union { uint8_t maze_last_edge; // 0x78 - Direction direction; // Direction ? + Direction direction; // Direction ? }; uint8_t interaction_ride_index; uint16_t time_in_queue; // 0x7A diff --git a/src/openrct2/world/Location.hpp b/src/openrct2/world/Location.hpp index 34fa4f1c21..03abf81c7c 100644 --- a/src/openrct2/world/Location.hpp +++ b/src/openrct2/world/Location.hpp @@ -270,7 +270,8 @@ typedef uint8_t Direction; const Direction INVALID_DIRECTION = 0xFF; /** - * Array of all valid cardinal directions, to make it easy to write range-based for loops like: for (Direction d : ALL_DIRECTIONS) + * Array of all valid cardinal directions, to make it easy to write range-based for loops like: + * for (Direction d : ALL_DIRECTIONS) */ constexpr Direction ALL_DIRECTIONS[] = { 0, 1, 2, 3 }; @@ -289,7 +290,8 @@ constexpr Direction ALL_DIRECTIONS[] = { 0, 1, 2, 3 }; } /** - * Given a direction, return the next cardinal direction, wrapping around if necessary. (TODO: Figure out if this is CW or CCW) + * Given a direction, return the next cardinal direction, wrapping around if necessary. + * (TODO: Figure out if this is CW or CCW) */ [[maybe_unused]] static constexpr Direction direction_next(Direction dir) { @@ -297,7 +299,8 @@ constexpr Direction ALL_DIRECTIONS[] = { 0, 1, 2, 3 }; } /** - * Given a direction, return the previous cardinal direction, wrapping around if necessary. (TODO: Figure out if this is CW or CCW) + * Given a direction, return the previous cardinal direction, wrapping around if necessary. + * (TODO: Figure out if this is CW or CCW) */ [[maybe_unused]] static constexpr Direction direction_prev(Direction dir) {