Skip to content

fix: MapNavigator 若干潜在问题及阈值调整#1179

Merged
MistEO merged 6 commits intov2from
fix/MapNavigator
Mar 10, 2026
Merged

fix: MapNavigator 若干潜在问题及阈值调整#1179
MistEO merged 6 commits intov2from
fix/MapNavigator

Conversation

@Lemon-miaow
Copy link
Member

@Lemon-miaow Lemon-miaow commented Mar 10, 2026

Summary by Sourcery

优化 MapNavigator 的导航行为和诊断功能,简化终点定位逻辑,改进自动冲刺(auto-sprint)处理,并增强工具的健壮性与日志记录能力。

New Features:

  • 引入冲刺路段距离预估机制,以即将到来的路径长度而非瞬时距离来驱动自动冲刺决策。

Bug Fixes:

  • 在严格抵达(strict-arrival)步行重置以及跳跃、交互、战斗、传送门等交互动作之前,取消当前的冲刺状态,避免产生互相冲突的移动状态。
  • 修复连续 TRANSFER 处理逻辑,使同一点的后续动作通过完整的航点抵达流程处理,并使用更新后的距离与传送门就绪检查。
  • 防止严重转向漂移(severe turn drift)逻辑在非初始节点上触发,从而减少不必要的自适应校正。
  • 在录制和运行时工具中,显式处理 Agent 可执行文件缺失、Agent 启动失败以及 Maa 运行时导入错误,而不是静默失败。
  • 提高加载地图跟踪器 bbox 数据、读取 PNG 图片尺寸以及加载地图图片时的健壮性,通过记录错误日志并安全回退来处理异常情况。

Enhancements:

  • 移除 ExactTargetRefine 导航阶段及其相关配置,简化终点定位行为和状态管理。
  • 放宽严格抵达前瞻范围与步行重置距离阈值,使抵达处理更具容错性。
  • 在运动控制器中跟踪冲刺状态,允许在冲刺触发时发出显式通知,并支持在步行重置时有条件地取消冲刺。
  • 调整自动冲刺就绪逻辑,改为依赖预估的可冲刺路段距离,并在保留冷却行为的同时简化判定条件。
  • 为 MapNavigator 录制服务的生命周期增加详细诊断输出,包括 Agent 启动、运行时库加载、游戏窗口检测、控制器与客户端连接,以及任务器初始化等阶段。
  • 在工具中打开 Maa 运行时库失败时记录异常日志,以便调试重复初始化或初始化失败问题。
Original summary in English

Summary by Sourcery

Refine MapNavigator navigation behavior and diagnostics, simplifying terminal targeting, improving auto-sprint handling, and enhancing tooling robustness and logging.

New Features:

  • Introduce sprint segment distance estimation to drive auto-sprint decisions based on upcoming path length rather than instantaneous distance.

Bug Fixes:

  • Cancel active sprint before strict-arrival walk reset and interactive actions such as jump, interact, fight, and portal to avoid conflicting movement states.
  • Fix chained TRANSFER handling so same-point follow-up actions are processed via a full waypoint arrival flow using updated distance and portal readiness checks.
  • Prevent severe turn drift logic from activating on non-initial nodes to reduce spurious adaptive corrections.
  • Handle missing Agent executable, failed Agent startup, and Maa runtime import errors explicitly in the recording and runtime tools instead of failing silently.
  • Improve robustness when loading map tracker bbox data, reading PNG image sizes, and loading map images by logging errors and falling back safely.

Enhancements:

  • Remove the ExactTargetRefine navigation phase and related configuration, simplifying terminal targeting behavior and state management.
  • Broaden strict-arrival lookahead and walk reset distance thresholds to make arrival handling more tolerant.
  • Track sprint state within the motion controller, allowing explicit notification when sprint is triggered and enabling conditional sprint cancellation with walk reset.
  • Adjust auto-sprint readiness logic to rely on estimated sprintable segment distance and simplify gating conditions while preserving cooldown behavior.
  • Add detailed diagnostic prints to the MapNavigator recording service lifecycle, including Agent boot, runtime library opening, game window detection, controller and client connections, and tasker initialization.
  • Log exceptions when opening the Maa runtime library from tools to aid debugging duplicate or failed initialization.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我发现了 1 个问题,并留下了一些高层面的反馈:

  • 新增的 HasSevereTurnDrift 守卫 if (session_->current_node_idx() > 1) return false; 在第二个节点之后完全禁用了自适应漂移处理;如果你的意图只是缩小其适用范围,建议把条件绑定到距离 / 阶段 / 标志位,而不是硬编码在节点索引上,这样后续路段在合适情况下仍然可以受益。
  • EstimateSprintSegmentDistance 目前在找到第一个符合条件的下一路点后就直接返回,所以最多只会考虑两段(当前→下一);如果你希望自动冲刺更好地反映较长的直线路段,可以考虑在同一分区内,跨多个连续 RUN 路点累加距离,直到满足某个停止条件。
  • 修改后的自动冲刺就绪条件移除了之前的一些保护措施(偏航约束、本地驾驶员状态、严格到达排除、转弯后的提交条件等);如果这些场景对冲刺来说仍然有问题,可能值得有选择地重新引入部分检查,或者把这些逻辑编码进 EstimateSprintSegmentDistance 里以避免回归。
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new HasSevereTurnDrift guard `if (session_->current_node_idx() > 1) return false;` completely disables adaptive drift handling after the second node; if the intent is to narrow its scope, consider tying this to a distance/phase/flag instead of a hard node index cut‑off so later route segments can still benefit when appropriate.
- EstimateSprintSegmentDistance currently returns after the first eligible next waypoint, so it only ever considers at most two legs (current→next); if you want auto sprint to better reflect longer straight segments, consider accumulating distances across multiple consecutive RUN waypoints in the same zone until a stopping condition is hit.
- The revised auto-sprint readiness condition drops several previous safeguards (yaw constraint, local driver state, strict-arrival exclusion, post-turn commit, etc.); if those scenarios are still problematic for sprinting, it may be worth selectively reintroducing some of those checks or encoding them into EstimateSprintSegmentDistance to avoid regressions.

## Individual Comments

### Comment 1
<location path="agent/cpp-algo/source/MapNavigator/navigation_state_machine.cpp" line_range="834" />
<code_context>
         }
         else {
-            action_wrapper_->ClickKeySync(kKeyW, kExactTargetMoveWaitMs);
+            action_wrapper_->ClickKeySync(kKeyW, 60); // kExactTargetMoveWaitMs
         }
     }
</code_context>
<issue_to_address>
**nitpick:** Hardcoded magic number with a stale constant name comment can be confusing and brittle.

The literal `60` has replaced `kExactTargetMoveWaitMs`, but the trailing comment still references the removed constant, which suggests a dangling or misleading reference. Please either introduce a new, clearly named constant for this delay or remove the stale comment so the purpose of `60` is explicit and maintainable.
</issue_to_address>

Sourcery 对开源项目免费——如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进评审质量。
Original comment in English

Hey - I've found 1 issue, and left some high level feedback:

  • The new HasSevereTurnDrift guard if (session_->current_node_idx() > 1) return false; completely disables adaptive drift handling after the second node; if the intent is to narrow its scope, consider tying this to a distance/phase/flag instead of a hard node index cut‑off so later route segments can still benefit when appropriate.
  • EstimateSprintSegmentDistance currently returns after the first eligible next waypoint, so it only ever considers at most two legs (current→next); if you want auto sprint to better reflect longer straight segments, consider accumulating distances across multiple consecutive RUN waypoints in the same zone until a stopping condition is hit.
  • The revised auto-sprint readiness condition drops several previous safeguards (yaw constraint, local driver state, strict-arrival exclusion, post-turn commit, etc.); if those scenarios are still problematic for sprinting, it may be worth selectively reintroducing some of those checks or encoding them into EstimateSprintSegmentDistance to avoid regressions.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new HasSevereTurnDrift guard `if (session_->current_node_idx() > 1) return false;` completely disables adaptive drift handling after the second node; if the intent is to narrow its scope, consider tying this to a distance/phase/flag instead of a hard node index cut‑off so later route segments can still benefit when appropriate.
- EstimateSprintSegmentDistance currently returns after the first eligible next waypoint, so it only ever considers at most two legs (current→next); if you want auto sprint to better reflect longer straight segments, consider accumulating distances across multiple consecutive RUN waypoints in the same zone until a stopping condition is hit.
- The revised auto-sprint readiness condition drops several previous safeguards (yaw constraint, local driver state, strict-arrival exclusion, post-turn commit, etc.); if those scenarios are still problematic for sprinting, it may be worth selectively reintroducing some of those checks or encoding them into EstimateSprintSegmentDistance to avoid regressions.

## Individual Comments

### Comment 1
<location path="agent/cpp-algo/source/MapNavigator/navigation_state_machine.cpp" line_range="834" />
<code_context>
         }
         else {
-            action_wrapper_->ClickKeySync(kKeyW, kExactTargetMoveWaitMs);
+            action_wrapper_->ClickKeySync(kKeyW, 60); // kExactTargetMoveWaitMs
         }
     }
</code_context>
<issue_to_address>
**nitpick:** Hardcoded magic number with a stale constant name comment can be confusing and brittle.

The literal `60` has replaced `kExactTargetMoveWaitMs`, but the trailing comment still references the removed constant, which suggests a dangling or misleading reference. Please either introduce a new, clearly named constant for this delay or remove the stale comment so the purpose of `60` is explicit and maintainable.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@MistEO MistEO merged commit 2da7a2c into v2 Mar 10, 2026
16 checks passed
@MistEO MistEO deleted the fix/MapNavigator branch March 10, 2026 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants