added console

This commit is contained in:
Boki 2026-02-13 13:18:29 -05:00
parent bb8e75a2f5
commit dab5735c80
3 changed files with 45 additions and 3 deletions

View file

@ -1,3 +1,4 @@
using System.Diagnostics;
using Poe2Trade.Core;
using Poe2Trade.Game;
using Serilog;
@ -174,15 +175,30 @@ public class NavigationExecutor : IDisposable
/// </summary>
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();

View file

@ -1,3 +1,4 @@
using System.Diagnostics;
using OpenCvSharp;
using Serilog;
@ -28,6 +29,7 @@ public class WorldMap : IDisposable
/// </summary>
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;
}

View file

@ -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);
}