From fdff60552b9aba7c765efe8a091c787a316f5e71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <5415177+ZehMatt@users.noreply.github.com> Date: Mon, 30 Sep 2024 12:36:01 +0300 Subject: [PATCH] Reduce memory footprint for history, cleanup code --- src/openrct2/peep/GuestPathfinding.cpp | 37 ++++++++++++++++---------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/openrct2/peep/GuestPathfinding.cpp b/src/openrct2/peep/GuestPathfinding.cpp index 97cd396544..193c7f8401 100644 --- a/src/openrct2/peep/GuestPathfinding.cpp +++ b/src/openrct2/peep/GuestPathfinding.cpp @@ -33,21 +33,29 @@ RideId gPeepPathFindQueueRideIndex; namespace OpenRCT2::PathFinding { + // The search limits the maximum junctions by certain conditions. + static constexpr uint8_t kMaxJunctionsStaff = 8; + static constexpr uint8_t kMaxJunctionsGuest = 5; + static constexpr uint8_t kMaxJunctionsGuestWithMap = 7; + static constexpr uint8_t kMaxJunctionsGuestLeavingPark = 7; + static constexpr uint8_t kMaxJunctionsGuestLeavingParkLost = 8; + + // Maximum amount of junctions. + static constexpr uint8_t kMaxJunctions = std::max({ kMaxJunctionsStaff, kMaxJunctionsGuest, kMaxJunctionsGuestWithMap, + kMaxJunctionsGuestLeavingPark, kMaxJunctionsGuestLeavingParkLost }); + struct PathFindingState { int8_t junctionCount; int8_t maxJunctions; int32_t countTilesChecked; - /* A junction history for the peep pathfinding heuristic search - * The magic number 16 is the largest value returned by - * PeepPathfindGetMaxNumberJunctions() which should eventually - * be declared properly. */ + // A junction history for the peep path finding heuristic search. struct { TileCoordsXYZ location; Direction direction; - } history[16]; + } history[kMaxJunctions + 1]; }; static int32_t GuestSurfacePathFinding(Peep& peep); @@ -553,24 +561,25 @@ namespace OpenRCT2::PathFinding static uint8_t PeepPathfindGetMaxNumberJunctions(Peep& peep) { if (peep.Is()) - return 8; + return kMaxJunctionsStaff; auto* guest = peep.As(); if (guest == nullptr) - return 8; + return kMaxJunctionsStaff; - if (guest->PeepFlags & PEEP_FLAGS_LEAVING_PARK && guest->GuestIsLostCountdown < 90) + bool isLeavingPark = (guest->PeepFlags & PEEP_FLAGS_LEAVING_PARK) != 0; + if (isLeavingPark && guest->GuestIsLostCountdown < 90) { - return 8; + return kMaxJunctionsGuestLeavingParkLost; } + if (isLeavingPark) + return kMaxJunctionsGuestLeavingPark; + if (guest->HasItem(ShopItem::Map)) - return 7; + return kMaxJunctionsGuestWithMap; - if (guest->PeepFlags & PEEP_FLAGS_LEAVING_PARK) - return 7; - - return 5; + return kMaxJunctionsGuest; } /**