Skip to content

Commit

Permalink
Debug tools for ai outside modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
awgil committed Sep 7, 2024
1 parent baec92d commit 72b704d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
22 changes: 19 additions & 3 deletions BossMod/Pathfinding/MapVisualizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class MapVisualizer
public List<(WPos origin, WPos dest)> Lines = [];

private ThetaStar _pathfind;
private float _lastExecTime;
private int _lastSteps;

public MapVisualizer(Map map, WPos startPos, WPos goalPos, float goalRadius)
{
Expand Down Expand Up @@ -174,6 +176,8 @@ public void Draw()
ImGui.SameLine();
if (ImGui.Button("Run pf"))
RunPathfind();
ImGui.SameLine();
ImGui.TextUnformatted($"Last op: {_lastExecTime:f3}s, last steps: {_lastSteps}");

var pfRes = _pathfind.BestIndex;
if (pfRes >= 0)
Expand All @@ -187,9 +191,21 @@ public void Draw()
DrawWaypoints(hoverNode >= 0 ? hoverNode : _pathfind.BestIndex);
}

public void StepPathfind() => _pathfind.ExecuteStep();
public void RunPathfind() => _pathfind.Execute();
public void ResetPathfind() => _pathfind = BuildPathfind();
public void StepPathfind() => ExecTimed(() => _pathfind.ExecuteStep());
public void RunPathfind() => ExecTimed(() =>
{
_lastSteps = 0;
while (!_pathfind.IsVeryGood(_pathfind.BestIndex) && _pathfind.ExecuteStep())
++_lastSteps;
});
public void ResetPathfind() => ExecTimed(() => _pathfind = BuildPathfind());

private void ExecTimed(Action action)
{
var now = DateTime.Now;
action();
_lastExecTime = (float)(DateTime.Now - now).TotalSeconds;
}

private void DrawSector(ImDrawListPtr dl, Vector2 tl, WPos center, float ir, float or, Angle dir, Angle halfWidth)
{
Expand Down
6 changes: 2 additions & 4 deletions BossMod/Replay/Visualization/ReplayDetailsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ public override void Draw()
ImGui.DragFloat("Camera azimuth", ref _azimuth, 1, -180, 180);
ImGui.SameLine();
ImGui.Checkbox("Override", ref _azimuthOverride);
_hintsBuilder.Update(_hints, _povSlot);
if (_mgr.ActiveModule != null)
{
_hintsBuilder.Update(_hints, _povSlot);
_rmm.Update(0, float.MaxValue, false);

var drawTimerPre = DateTime.Now;
Expand Down Expand Up @@ -412,9 +412,7 @@ private void DrawAI()
{
if (!ImGui.CollapsingHeader("AI hints"))
return;
if (_mgr.ActiveModule == null)
return;
var player = _mgr.ActiveModule.Raid[_povSlot];
var player = _player.WorldState.Party[_povSlot];
if (player == null)
return;

Expand Down

0 comments on commit 72b704d

Please sign in to comment.