added console
This commit is contained in:
parent
bb8e75a2f5
commit
dab5735c80
3 changed files with 45 additions and 3 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System.Diagnostics;
|
||||||
using Poe2Trade.Core;
|
using Poe2Trade.Core;
|
||||||
using Poe2Trade.Game;
|
using Poe2Trade.Game;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
@ -174,15 +175,30 @@ public class NavigationExecutor : IDisposable
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public byte[]? ProcessFrame(MinimapDebugStage stage = MinimapDebugStage.WorldMap)
|
public byte[]? ProcessFrame(MinimapDebugStage stage = MinimapDebugStage.WorldMap)
|
||||||
{
|
{
|
||||||
|
var sw = Stopwatch.StartNew();
|
||||||
|
|
||||||
|
var captureStart = sw.Elapsed.TotalMilliseconds;
|
||||||
using var frame = _capture.CaptureFrame();
|
using var frame = _capture.CaptureFrame();
|
||||||
|
var captureMs = sw.Elapsed.TotalMilliseconds - captureStart;
|
||||||
|
|
||||||
if (frame == null) return null;
|
if (frame == null) return null;
|
||||||
|
|
||||||
|
var stitchStart = sw.Elapsed.TotalMilliseconds;
|
||||||
var pos = _worldMap.MatchAndStitch(frame.ClassifiedMat, frame.WallMask);
|
var pos = _worldMap.MatchAndStitch(frame.ClassifiedMat, frame.WallMask);
|
||||||
|
var stitchMs = sw.Elapsed.TotalMilliseconds - stitchStart;
|
||||||
|
|
||||||
|
var renderStart = sw.Elapsed.TotalMilliseconds;
|
||||||
|
byte[]? result;
|
||||||
if (stage == MinimapDebugStage.WorldMap)
|
if (stage == MinimapDebugStage.WorldMap)
|
||||||
return _worldMap.GetViewportSnapshot(pos);
|
result = _worldMap.GetViewportSnapshot(pos);
|
||||||
|
else
|
||||||
|
result = _capture.CaptureStage(stage);
|
||||||
|
var renderMs = sw.Elapsed.TotalMilliseconds - renderStart;
|
||||||
|
|
||||||
return _capture.CaptureStage(stage);
|
Log.Information("ProcessFrame: capture={Capture:F1}ms stitch={Stitch:F1}ms render={Render:F1}ms total={Total:F1}ms",
|
||||||
|
captureMs, stitchMs, renderMs, sw.Elapsed.TotalMilliseconds);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveDebugCapture() => _capture.SaveDebugCapture();
|
public void SaveDebugCapture() => _capture.SaveDebugCapture();
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System.Diagnostics;
|
||||||
using OpenCvSharp;
|
using OpenCvSharp;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
|
|
@ -28,6 +29,7 @@ public class WorldMap : IDisposable
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public MapPosition MatchAndStitch(Mat classifiedMat, Mat wallMask)
|
public MapPosition MatchAndStitch(Mat classifiedMat, Mat wallMask)
|
||||||
{
|
{
|
||||||
|
var sw = Stopwatch.StartNew();
|
||||||
_frameCount++;
|
_frameCount++;
|
||||||
|
|
||||||
// Frame deduplication: skip if minimap hasn't scrolled yet
|
// Frame deduplication: skip if minimap hasn't scrolled yet
|
||||||
|
|
@ -38,11 +40,14 @@ public class WorldMap : IDisposable
|
||||||
var changedPixels = Cv2.CountNonZero(xor);
|
var changedPixels = Cv2.CountNonZero(xor);
|
||||||
if (changedPixels < _config.FrameChangeThreshold)
|
if (changedPixels < _config.FrameChangeThreshold)
|
||||||
{
|
{
|
||||||
Log.Debug("Frame dedup: {Changed} changed pixels, skipping", changedPixels);
|
Log.Information("Frame dedup: {Changed} changed pixels, skipping ({Ms:F1}ms)",
|
||||||
|
changedPixels, sw.Elapsed.TotalMilliseconds);
|
||||||
return _position;
|
return _position;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var dedupMs = sw.Elapsed.TotalMilliseconds;
|
||||||
|
|
||||||
// Store current wall mask for next frame's dedup check
|
// Store current wall mask for next frame's dedup check
|
||||||
_prevWallMask?.Dispose();
|
_prevWallMask?.Dispose();
|
||||||
_prevWallMask = wallMask.Clone();
|
_prevWallMask = wallMask.Clone();
|
||||||
|
|
@ -51,16 +56,30 @@ public class WorldMap : IDisposable
|
||||||
if (_frameCount <= _config.WarmupFrames)
|
if (_frameCount <= _config.WarmupFrames)
|
||||||
{
|
{
|
||||||
StitchWithConfidence(classifiedMat, _position, boosted: true);
|
StitchWithConfidence(classifiedMat, _position, boosted: true);
|
||||||
|
Log.Information("Warmup frame {N}/{Total}: stitch={Ms:F1}ms",
|
||||||
|
_frameCount, _config.WarmupFrames, sw.Elapsed.TotalMilliseconds);
|
||||||
return _position;
|
return _position;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Match wallMask against canvas to find best position
|
// Match wallMask against canvas to find best position
|
||||||
|
var matchStart = sw.Elapsed.TotalMilliseconds;
|
||||||
var matched = MatchPosition(wallMask, _position);
|
var matched = MatchPosition(wallMask, _position);
|
||||||
|
var matchMs = sw.Elapsed.TotalMilliseconds - matchStart;
|
||||||
|
|
||||||
if (matched == null)
|
if (matched == null)
|
||||||
|
{
|
||||||
|
Log.Information("MatchAndStitch: dedup={Dedup:F1}ms match={Match:F1}ms (FAILED) total={Total:F1}ms",
|
||||||
|
dedupMs, matchMs, sw.Elapsed.TotalMilliseconds);
|
||||||
return _position; // skip stitching entirely on failed match
|
return _position; // skip stitching entirely on failed match
|
||||||
|
}
|
||||||
|
|
||||||
_position = matched;
|
_position = matched;
|
||||||
|
var stitchStart = sw.Elapsed.TotalMilliseconds;
|
||||||
StitchWithConfidence(classifiedMat, _position, boosted: false);
|
StitchWithConfidence(classifiedMat, _position, boosted: false);
|
||||||
|
var stitchMs = sw.Elapsed.TotalMilliseconds - stitchStart;
|
||||||
|
|
||||||
|
Log.Information("MatchAndStitch: dedup={Dedup:F1}ms match={Match:F1}ms stitch={Stitch:F1}ms total={Total:F1}ms",
|
||||||
|
dedupMs, matchMs, stitchMs, sw.Elapsed.TotalMilliseconds);
|
||||||
return _position;
|
return _position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Poe2Trade.Core;
|
using Poe2Trade.Core;
|
||||||
|
|
||||||
|
|
@ -5,9 +6,15 @@ namespace Poe2Trade.Ui;
|
||||||
|
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
|
[DllImport("kernel32.dll")]
|
||||||
|
private static extern bool AttachConsole(int dwProcessId);
|
||||||
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
AttachConsole(-1); // ATTACH_PARENT_PROCESS — reuse the launching terminal
|
||||||
|
Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true });
|
||||||
|
Console.SetError(new StreamWriter(Console.OpenStandardError()) { AutoFlush = true });
|
||||||
Logging.Setup();
|
Logging.Setup();
|
||||||
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
|
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue