Modify path visualization
This commit is contained in:
1 parent
542fc191fa
commit
53328484b8
14 files changed
+175
-41
No files matched your search
+22
-5
@@ -91,6 +91,7 @@ void CharacterState::stopInPlace() {
|
||||
pathWaypoints.clear();
|
||||
currentWaypointIndex = 0;
|
||||
onArrivedCallbackName.clear();
|
||||
navigationOutcome = PathFinder::PathOutcome::ReachedExactGoal;
|
||||
movementBlockedTicks = 0;
|
||||
navigationRetryTicks = 0;
|
||||
velocity = Vec2fp(fp(0), fp(0));
|
||||
@@ -128,11 +129,14 @@ void CharacterState::setTarget(
|
||||
if (location.activeNavigationIndex < 0 ||
|
||||
location.activeNavigationIndex >= static_cast<int>(location.navigationMaps.size())) {
|
||||
walkTarget = Vec3fp(position.x, static_cast<fp>(0.f), position.z);
|
||||
navigationOutcome = PathFinder::PathOutcome::NoPath;
|
||||
return;
|
||||
}
|
||||
|
||||
pathWaypoints = location.navigationMaps[location.activeNavigationIndex]
|
||||
.findPathToNearest(this->position, normalizedTarget);
|
||||
const auto pathResult = location.navigationMaps[location.activeNavigationIndex]
|
||||
.findPathResult(this->position, normalizedTarget);
|
||||
pathWaypoints = pathResult.waypoints;
|
||||
navigationOutcome = pathResult.outcome;
|
||||
|
||||
// Сразу целимся во второй элемент (индекс 1), так как индекс 0 — это точка старта
|
||||
currentWaypointIndex = (pathWaypoints.size() > 1) ? 1 : 0;
|
||||
@@ -160,11 +164,14 @@ void CharacterState::forceReplan(
|
||||
if (location.activeNavigationIndex < 0 ||
|
||||
location.activeNavigationIndex >= static_cast<int>(location.navigationMaps.size())) {
|
||||
walkTarget = Vec3fp(position.x, static_cast<fp>(0.f), position.z);
|
||||
navigationOutcome = PathFinder::PathOutcome::NoPath;
|
||||
return;
|
||||
}
|
||||
|
||||
pathWaypoints = location.navigationMaps[location.activeNavigationIndex]
|
||||
.findPathToNearest(this->position, normalizedTarget);
|
||||
const auto pathResult = location.navigationMaps[location.activeNavigationIndex]
|
||||
.findPathResult(this->position, normalizedTarget);
|
||||
pathWaypoints = pathResult.waypoints;
|
||||
navigationOutcome = pathResult.outcome;
|
||||
|
||||
currentWaypointIndex = (pathWaypoints.size() > 1) ? 1 : 0;
|
||||
movementBlockedTicks = 0;
|
||||
@@ -316,14 +323,21 @@ CharacterUpdateEvents CharacterState::update(
|
||||
currentWaypointIndex = 0;
|
||||
|
||||
if (completedPath &&
|
||||
navigationOutcome == PathFinder::PathOutcome::ReachedExactGoal &&
|
||||
(requestedWalkTarget - position).normSquared() > TARGET_REPLAN_THRESHOLD_SQUARED &&
|
||||
!isPlayer) {
|
||||
scheduleNextNavigationRetry();
|
||||
}
|
||||
if (completedPath && !onArrivedCallbackName.empty()) {
|
||||
if (completedPath &&
|
||||
navigationOutcome == PathFinder::PathOutcome::ReachedExactGoal &&
|
||||
!onArrivedCallbackName.empty()) {
|
||||
events.arrivedCallbackName = onArrivedCallbackName;
|
||||
onArrivedCallbackName.clear();
|
||||
}
|
||||
else if (completedPath &&
|
||||
navigationOutcome != PathFinder::PathOutcome::ReachedExactGoal) {
|
||||
onArrivedCallbackName.clear();
|
||||
}
|
||||
if (faceTarget) {
|
||||
Vec3fp toFace = faceTarget->position - position;
|
||||
toFace.y = fp(0);
|
||||
@@ -516,6 +530,7 @@ void CharacterState::save(nlohmann::json& out) const
|
||||
}
|
||||
out["pathWaypoints"] = std::move(wpArr);
|
||||
out["currentWaypointIndex"] = currentWaypointIndex;
|
||||
out["navigationOutcome"] = static_cast<int>(navigationOutcome);
|
||||
out["homeDriftCheckTimer"] = static_cast<double>(homeDriftCheckTimer);
|
||||
out["movementBlockedTicks"] = movementBlockedTicks;
|
||||
out["navigationRetryTicks"] = navigationRetryTicks;
|
||||
@@ -573,6 +588,8 @@ void CharacterState::load(const nlohmann::json& in)
|
||||
}
|
||||
}
|
||||
currentWaypointIndex = in.value("currentWaypointIndex", currentWaypointIndex);
|
||||
navigationOutcome = static_cast<PathFinder::PathOutcome>(
|
||||
in.value("navigationOutcome", static_cast<int>(navigationOutcome)));
|
||||
homeDriftCheckTimer = static_cast<fp>(in.value("homeDriftCheckTimer", static_cast<double>(homeDriftCheckTimer)));
|
||||
movementBlockedTicks = in.value("movementBlockedTicks", movementBlockedTicks);
|
||||
navigationRetryTicks = in.value("navigationRetryTicks", navigationRetryTicks);
|
||||
|
||||
Reference in new issue
Block a user