minimap
This commit is contained in:
parent
6bc3fb6972
commit
40f013d07e
5 changed files with 129 additions and 129 deletions
|
|
@ -9,10 +9,11 @@ public class NavigationExecutor : IDisposable
|
|||
private readonly IGameController _game;
|
||||
private readonly MinimapConfig _config;
|
||||
private readonly MinimapCapture _capture;
|
||||
private readonly PositionTracker _tracker;
|
||||
private readonly WorldMap _worldMap;
|
||||
private NavigationState _state = NavigationState.Idle;
|
||||
private bool _stopped;
|
||||
private int _stuckCounter;
|
||||
private MapPosition? _lastPosition;
|
||||
private static readonly Random Rng = new();
|
||||
|
||||
public event Action<NavigationState>? StateChanged;
|
||||
|
|
@ -23,7 +24,6 @@ public class NavigationExecutor : IDisposable
|
|||
_game = game;
|
||||
_config = config ?? new MinimapConfig();
|
||||
_capture = new MinimapCapture(_config);
|
||||
_tracker = new PositionTracker(_config);
|
||||
_worldMap = new WorldMap(_config);
|
||||
}
|
||||
|
||||
|
|
@ -43,9 +43,10 @@ public class NavigationExecutor : IDisposable
|
|||
|
||||
public void Reset()
|
||||
{
|
||||
_tracker.Reset();
|
||||
_worldMap.Reset();
|
||||
_stopped = false;
|
||||
_stuckCounter = 0;
|
||||
_lastPosition = null;
|
||||
SetState(NavigationState.Idle);
|
||||
}
|
||||
|
||||
|
|
@ -77,8 +78,19 @@ public class NavigationExecutor : IDisposable
|
|||
}
|
||||
|
||||
SetState(NavigationState.Processing);
|
||||
var pos = _tracker.UpdatePosition(frame.GrayMat);
|
||||
_worldMap.StitchFrame(frame.ClassifiedMat, pos);
|
||||
var pos = _worldMap.MatchAndStitch(frame.ClassifiedMat, frame.WallMask);
|
||||
|
||||
// Stuck detection: position hasn't moved enough over several frames
|
||||
if (_lastPosition != null)
|
||||
{
|
||||
var dx = pos.X - _lastPosition.X;
|
||||
var dy = pos.Y - _lastPosition.Y;
|
||||
if (Math.Sqrt(dx * dx + dy * dy) < _config.StuckThreshold)
|
||||
_stuckCounter++;
|
||||
else
|
||||
_stuckCounter = 0;
|
||||
}
|
||||
_lastPosition = pos;
|
||||
|
||||
// 2. Movement decisions at slower rate
|
||||
var now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||
|
|
@ -86,7 +98,7 @@ public class NavigationExecutor : IDisposable
|
|||
{
|
||||
lastMoveTime = now;
|
||||
|
||||
if (_tracker.IsStuck)
|
||||
if (_stuckCounter >= _config.StuckFrameCount)
|
||||
{
|
||||
SetState(NavigationState.Stuck);
|
||||
Log.Information("Stuck detected, clicking random direction");
|
||||
|
|
@ -152,9 +164,9 @@ public class NavigationExecutor : IDisposable
|
|||
await ClickToMove(Math.Cos(angle), Math.Sin(angle));
|
||||
}
|
||||
|
||||
public MapPosition Position => _tracker.Position;
|
||||
public MapPosition Position => _worldMap.Position;
|
||||
public byte[] GetMapSnapshot() => _worldMap.GetMapSnapshot();
|
||||
public byte[] GetViewportSnapshot(int viewSize = 400) => _worldMap.GetViewportSnapshot(_tracker.Position, viewSize);
|
||||
public byte[] GetViewportSnapshot(int viewSize = 400) => _worldMap.GetViewportSnapshot(_worldMap.Position, viewSize);
|
||||
|
||||
/// <summary>
|
||||
/// Capture one frame, track position, stitch into world map.
|
||||
|
|
@ -165,8 +177,7 @@ public class NavigationExecutor : IDisposable
|
|||
using var frame = _capture.CaptureFrame();
|
||||
if (frame == null) return null;
|
||||
|
||||
var pos = _tracker.UpdatePosition(frame.GrayMat);
|
||||
_worldMap.StitchFrame(frame.ClassifiedMat, pos);
|
||||
var pos = _worldMap.MatchAndStitch(frame.ClassifiedMat, frame.WallMask);
|
||||
|
||||
if (stage == MinimapDebugStage.WorldMap)
|
||||
return _worldMap.GetViewportSnapshot(pos);
|
||||
|
|
@ -179,7 +190,6 @@ public class NavigationExecutor : IDisposable
|
|||
public void Dispose()
|
||||
{
|
||||
_capture.Dispose();
|
||||
_tracker.Dispose();
|
||||
_worldMap.Dispose();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue