Files
better-genshin-impact/BetterGenshinImpact/GameTask/AutoTrackPath/PathPointRecorder.cs
辉鸭蛋 807288ab90 重构底层截图器,大幅提升截图器耗时 (#1302)
* to mat init

* BitBlt 加锁

* 使用读写锁重构 Windows.Graphics.Capture,删除BGI自己命名的缓存设置

* dwm加锁并返回mat

* 队伍中没有对应元素角色修复日志问题

* 清除所有 DispatcherTimerOperationEnum 内容

* 修复单测的编译错误

* HDR Support

* 清理无用的截图器模式
2025-03-15 13:18:19 +08:00

102 lines
3.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using BetterGenshinImpact.Core.Config;
using BetterGenshinImpact.Core.Recognition.OpenCv;
using BetterGenshinImpact.GameTask.AutoGeniusInvokation.Exception;
using BetterGenshinImpact.GameTask.AutoTrackPath.Model;
using BetterGenshinImpact.GameTask.Common.Element.Assets;
using BetterGenshinImpact.GameTask.Common.Map;
using BetterGenshinImpact.Helpers.Extensions;
using BetterGenshinImpact.Model;
using BetterGenshinImpact.Service;
using Microsoft.Extensions.Logging;
using OpenCvSharp;
using System;
using System.Diagnostics;
using System.IO;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using static BetterGenshinImpact.GameTask.Common.TaskControl;
namespace BetterGenshinImpact.GameTask.AutoTrackPath;
[Obsolete]
public class PathPointRecorder : Singleton<PathPointRecorder>
{
private readonly EntireMap _bigMap = EntireMap.Instance;
private Task? _recordTask;
private CancellationTokenSource? _recordTaskCts;
public void Switch()
{
try
{
if (_recordTask == null)
{
_recordTaskCts = new CancellationTokenSource();
_recordTask = RecordTask(_recordTaskCts.Token);
_recordTask.Start();
}
else
{
_recordTaskCts?.Cancel();
_recordTask = null;
}
}
catch (NormalEndException)
{
Logger.LogInformation("关闭路线录制");
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
public Task RecordTask(CancellationToken ct)
{
return new Task(() =>
{
GiPath way = new();
while (!ct.IsCancellationRequested)
{
try
{
Sleep(10, ct);
var ra = CaptureToRectArea();
// 小地图匹配
var tar = ElementAssets.Instance.PaimonMenuRo.TemplateImageGreyMat!;
var p = MatchTemplateHelper.MatchTemplate(ra.SrcGreyMat, tar, TemplateMatchModes.CCoeffNormed, null, 0.9);
if (p.X == 0 || p.Y == 0)
{
Sleep(50, ct);
continue;
}
var p2 = _bigMap.GetMiniMapPositionByFeatureMatch(new Mat(ra.SrcGreyMat, new Rect(p.X + 24, p.Y - 15, 210, 210)));
if (!p2.IsEmpty())
{
way.AddPoint(p2);
Debug.WriteLine($"AddPoint: {p2}");
}
else
{
Sleep(50, ct);
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
#if DEBUG
File.WriteAllText(Global.Absolute($@"log\way\{DateTime.Now:yyyy-MM-dd HHmmssffff}.json"), JsonSerializer.Serialize(way, ConfigService.JsonOptions));
#endif
Logger.LogInformation("路线录制结束");
}, ct);
}
}