integrate(m02): preserve valid off-window terrain interactions
This commit is contained in:
commit
14987b240e
4 files changed
+74
-8
No files matched your search
@@ -145,11 +145,14 @@ private:
|
||||
std::size_t sx_, sy_, count_;
|
||||
};
|
||||
|
||||
VoxelPathResult search(Queries& queries, const VoxelPathRequest& request, std::span<const VoxelPosition> goals) {
|
||||
VoxelPathResult search(Queries& queries, const VoxelPathRequest& request,
|
||||
std::span<const VoxelPosition> goals, std::span<const VoxelPosition> omitted = {}) {
|
||||
VoxelPathResult result;
|
||||
if (goals.empty()) return result;
|
||||
if (goals.empty() && omitted.empty()) return result;
|
||||
const auto& limits = request.limits;
|
||||
if (goals.size() > limits.max_goals) { result.status = Status::LimitExceeded; return result; }
|
||||
if (omitted.size() > limits.max_goals || goals.size() > limits.max_goals - omitted.size()) {
|
||||
result.status = Status::LimitExceeded; return result;
|
||||
}
|
||||
for (auto goal : goals) if (!request.search_bounds.contains(goal)) return result;
|
||||
const auto sx = static_cast<std::size_t>(request.search_bounds.upper.x - request.search_bounds.lower.x);
|
||||
const auto sy = static_cast<std::size_t>(request.search_bounds.upper.y - request.search_bounds.lower.y);
|
||||
@@ -195,6 +198,13 @@ VoxelPathResult search(Queries& queries, const VoxelPathRequest& request, std::s
|
||||
(!result.goal || goal < *result.goal))) { distance = cost; result.goal = goal; }
|
||||
}
|
||||
if (!result.goal) {
|
||||
// Interaction contacts outside the selected window still matter to a
|
||||
// global negative. Their feasibility cannot manufacture a frontier;
|
||||
// BFS must also have reached a valid exit or an unresolved transition.
|
||||
for (auto goal : omitted) {
|
||||
const auto standing = queries.standing(goal);
|
||||
possible_goal = possible_goal || standing != Status::Unreachable;
|
||||
}
|
||||
result.status = Status::Unreachable;
|
||||
if (possible_goal) {
|
||||
if (graph.unavailable) result.status = Status::Unavailable;
|
||||
@@ -247,16 +257,22 @@ VoxelPathResult path(const VoxelRegion& world, const VoxelPathRequest& request,
|
||||
result.status = cell.availability == VoxelAvailability::Unavailable ? Status::Unavailable : Status::InvalidInput;
|
||||
} else {
|
||||
std::array<VoxelPosition, 10> goals{};
|
||||
std::size_t size = 0;
|
||||
std::array<VoxelPosition, 10> omitted{};
|
||||
std::size_t size = 0, omitted_size = 0;
|
||||
const auto add_goal = [&](std::optional<VoxelPosition> goal) {
|
||||
if (!goal) return;
|
||||
if (request.search_bounds.contains(*goal)) goals[size++] = *goal;
|
||||
else omitted[omitted_size++] = *goal;
|
||||
};
|
||||
constexpr std::array<std::array<int, 2>, 4> directions{{{-1, 0}, {0, -1}, {0, 1}, {1, 0}}};
|
||||
for (auto direction : directions) for (int dz : {-1, 0}) {
|
||||
if (auto goal = offset(*target, direction[0], direction[1], dz); goal && request.search_bounds.contains(*goal)) goals[size++] = *goal;
|
||||
add_goal(offset(*target, direction[0], direction[1], dz));
|
||||
}
|
||||
for (int dz : {-2, 1}) {
|
||||
if (auto goal = offset(*target, 0, 0, dz); goal && request.search_bounds.contains(*goal)) goals[size++] = *goal;
|
||||
add_goal(offset(*target, 0, 0, dz));
|
||||
}
|
||||
if (size == 0) result.status = Status::SearchBoundary;
|
||||
else result = search(queries, request, std::span(goals.data(), size));
|
||||
result = search(queries, request, std::span(goals.data(), size),
|
||||
std::span(omitted.data(), omitted_size));
|
||||
}
|
||||
} else result = search(queries, request, request.goals);
|
||||
} catch (const NavigationFailure& failure) { result.status = failure.status; }
|
||||
|
||||
Reference in new issue
Block a user