fixed switching
This commit is contained in:
parent
ec1f6274e3
commit
d71c1d97c5
1 changed files with 7 additions and 41 deletions
|
|
@ -13,8 +13,6 @@ public class WorldMap : IDisposable
|
||||||
private int _frameCount;
|
private int _frameCount;
|
||||||
private int _consecutiveMatchFails;
|
private int _consecutiveMatchFails;
|
||||||
private Mat? _prevWallMask; // for frame deduplication
|
private Mat? _prevWallMask; // for frame deduplication
|
||||||
private bool _modeSwitchPending; // suppress blind bootstrap after mode switch
|
|
||||||
private bool _hasCanvasData; // true after first successful stitch
|
|
||||||
|
|
||||||
public MapPosition Position => _position;
|
public MapPosition Position => _position;
|
||||||
public bool LastMatchSucceeded { get; private set; }
|
public bool LastMatchSucceeded { get; private set; }
|
||||||
|
|
@ -38,9 +36,7 @@ public class WorldMap : IDisposable
|
||||||
|
|
||||||
var isCorner = mode == MinimapMode.Corner;
|
var isCorner = mode == MinimapMode.Corner;
|
||||||
var warmupFrames = isCorner ? 2 : _config.WarmupFrames;
|
var warmupFrames = isCorner ? 2 : _config.WarmupFrames;
|
||||||
// After mode switch, don't blindly stitch — wait for template match to confirm alignment
|
var needsBootstrap = _frameCount <= warmupFrames || _consecutiveMatchFails >= 30;
|
||||||
var needsBootstrap = !_modeSwitchPending
|
|
||||||
&& (_frameCount <= warmupFrames || _consecutiveMatchFails >= 30);
|
|
||||||
|
|
||||||
// Block-based noise filter: only needed for overlay (game effects bleed through)
|
// Block-based noise filter: only needed for overlay (game effects bleed through)
|
||||||
if (!isCorner)
|
if (!isCorner)
|
||||||
|
|
@ -78,7 +74,6 @@ public class WorldMap : IDisposable
|
||||||
if (needsBootstrap)
|
if (needsBootstrap)
|
||||||
{
|
{
|
||||||
StitchWithConfidence(classifiedMat, _position, boosted: true, mode: mode);
|
StitchWithConfidence(classifiedMat, _position, boosted: true, mode: mode);
|
||||||
_hasCanvasData = true;
|
|
||||||
if (_consecutiveMatchFails >= 30)
|
if (_consecutiveMatchFails >= 30)
|
||||||
{
|
{
|
||||||
Log.Information("Re-bootstrap: stitching at current position after {Fails} match failures ({Ms:F1}ms)",
|
Log.Information("Re-bootstrap: stitching at current position after {Fails} match failures ({Ms:F1}ms)",
|
||||||
|
|
@ -102,38 +97,11 @@ public class WorldMap : IDisposable
|
||||||
{
|
{
|
||||||
_consecutiveMatchFails++;
|
_consecutiveMatchFails++;
|
||||||
LastMatchSucceeded = false;
|
LastMatchSucceeded = false;
|
||||||
if (_modeSwitchPending)
|
|
||||||
{
|
|
||||||
// After 60 failures, give up on cross-mode alignment and force bootstrap
|
|
||||||
if (_consecutiveMatchFails >= 60)
|
|
||||||
{
|
|
||||||
Log.Information("Mode switch: giving up on alignment after {Fails} tries, force bootstrap",
|
|
||||||
_consecutiveMatchFails);
|
|
||||||
_modeSwitchPending = false;
|
|
||||||
_consecutiveMatchFails = 0;
|
|
||||||
_frameCount = 0; // will trigger warmup bootstrap next frame
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Log.Information("Mode switch: match failed x{Fails}, waiting for alignment ({Ms:F1}ms)",
|
|
||||||
_consecutiveMatchFails, sw.Elapsed.TotalMilliseconds);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Log.Information("MatchAndStitch: dedup={Dedup:F1}ms match={Match:F1}ms (FAILED x{Fails}) total={Total:F1}ms",
|
Log.Information("MatchAndStitch: dedup={Dedup:F1}ms match={Match:F1}ms (FAILED x{Fails}) total={Total:F1}ms",
|
||||||
dedupMs, matchMs, _consecutiveMatchFails, sw.Elapsed.TotalMilliseconds);
|
dedupMs, matchMs, _consecutiveMatchFails, sw.Elapsed.TotalMilliseconds);
|
||||||
}
|
|
||||||
return _position; // don't stitch — wrong position would corrupt the canvas
|
return _position; // don't stitch — wrong position would corrupt the canvas
|
||||||
}
|
}
|
||||||
|
|
||||||
// Successful match — clear mode switch pending (alignment confirmed)
|
|
||||||
if (_modeSwitchPending)
|
|
||||||
{
|
|
||||||
Log.Information("Mode switch: alignment confirmed after {Fails} tries", _consecutiveMatchFails);
|
|
||||||
_modeSwitchPending = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
_consecutiveMatchFails = 0;
|
_consecutiveMatchFails = 0;
|
||||||
LastMatchSucceeded = true;
|
LastMatchSucceeded = true;
|
||||||
_position = matched;
|
_position = matched;
|
||||||
|
|
@ -535,20 +503,18 @@ public class WorldMap : IDisposable
|
||||||
_position = new MapPosition(_config.CanvasSize / 2.0, _config.CanvasSize / 2.0);
|
_position = new MapPosition(_config.CanvasSize / 2.0, _config.CanvasSize / 2.0);
|
||||||
_frameCount = 0;
|
_frameCount = 0;
|
||||||
_consecutiveMatchFails = 0;
|
_consecutiveMatchFails = 0;
|
||||||
_hasCanvasData = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Re-bootstrap without clearing the canvas. Used when minimap mode switches
|
/// Mode switch: clear frame dedup cache (frame sizes differ between modes)
|
||||||
/// so new frames get stitched onto existing map data.
|
/// but keep template matching active — no blind bootstrap needed since scales match.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Rebootstrap()
|
public void Rebootstrap()
|
||||||
{
|
{
|
||||||
_prevWallMask?.Dispose();
|
_prevWallMask?.Dispose();
|
||||||
_prevWallMask = null;
|
_prevWallMask = null;
|
||||||
_frameCount = 0;
|
// Don't reset _frameCount or _consecutiveMatchFails —
|
||||||
_consecutiveMatchFails = 0;
|
// template matching continues seamlessly with the new frame size
|
||||||
_modeSwitchPending = _hasCanvasData; // only suppress if canvas has data worth protecting
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue