From dab5735c8046fca302e5f9b3462a8c4b76b555c8 Mon Sep 17 00:00:00 2001 From: Boki Date: Fri, 13 Feb 2026 13:18:29 -0500 Subject: [PATCH] added console --- .../NavigationExecutor.cs | 20 ++++++++++++++++-- src/Poe2Trade.Navigation/WorldMap.cs | 21 ++++++++++++++++++- src/Poe2Trade.Ui/Program.cs | 7 +++++++ 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/Poe2Trade.Navigation/NavigationExecutor.cs b/src/Poe2Trade.Navigation/NavigationExecutor.cs index 3e1e20c..04ebf85 100644 --- a/src/Poe2Trade.Navigation/NavigationExecutor.cs +++ b/src/Poe2Trade.Navigation/NavigationExecutor.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using Poe2Trade.Core; using Poe2Trade.Game; using Serilog; @@ -174,15 +175,30 @@ public class NavigationExecutor : IDisposable /// public byte[]? ProcessFrame(MinimapDebugStage stage = MinimapDebugStage.WorldMap) { + var sw = Stopwatch.StartNew(); + + var captureStart = sw.Elapsed.TotalMilliseconds; using var frame = _capture.CaptureFrame(); + var captureMs = sw.Elapsed.TotalMilliseconds - captureStart; + if (frame == null) return null; + var stitchStart = sw.Elapsed.TotalMilliseconds; 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) - 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(); diff --git a/src/Poe2Trade.Navigation/WorldMap.cs b/src/Poe2Trade.Navigation/WorldMap.cs index 56ccbdd..31933da 100644 --- a/src/Poe2Trade.Navigation/WorldMap.cs +++ b/src/Poe2Trade.Navigation/WorldMap.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using OpenCvSharp; using Serilog; @@ -28,6 +29,7 @@ public class WorldMap : IDisposable /// public MapPosition MatchAndStitch(Mat classifiedMat, Mat wallMask) { + var sw = Stopwatch.StartNew(); _frameCount++; // Frame deduplication: skip if minimap hasn't scrolled yet @@ -38,11 +40,14 @@ public class WorldMap : IDisposable var changedPixels = Cv2.CountNonZero(xor); 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; } } + var dedupMs = sw.Elapsed.TotalMilliseconds; + // Store current wall mask for next frame's dedup check _prevWallMask?.Dispose(); _prevWallMask = wallMask.Clone(); @@ -51,16 +56,30 @@ public class WorldMap : IDisposable if (_frameCount <= _config.WarmupFrames) { StitchWithConfidence(classifiedMat, _position, boosted: true); + Log.Information("Warmup frame {N}/{Total}: stitch={Ms:F1}ms", + _frameCount, _config.WarmupFrames, sw.Elapsed.TotalMilliseconds); return _position; } // Match wallMask against canvas to find best position + var matchStart = sw.Elapsed.TotalMilliseconds; var matched = MatchPosition(wallMask, _position); + var matchMs = sw.Elapsed.TotalMilliseconds - matchStart; + 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 + } _position = matched; + var stitchStart = sw.Elapsed.TotalMilliseconds; 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; } diff --git a/src/Poe2Trade.Ui/Program.cs b/src/Poe2Trade.Ui/Program.cs index 246076c..77c09f6 100644 --- a/src/Poe2Trade.Ui/Program.cs +++ b/src/Poe2Trade.Ui/Program.cs @@ -1,3 +1,4 @@ +using System.Runtime.InteropServices; using Avalonia; using Poe2Trade.Core; @@ -5,9 +6,15 @@ namespace Poe2Trade.Ui; class Program { + [DllImport("kernel32.dll")] + private static extern bool AttachConsole(int dwProcessId); + [STAThread] 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(); BuildAvaloniaApp().StartWithClassicDesktopLifetime(args); }