Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: NpcNameFinder SearchMode.Fuzzy default for non corpse names and small improvements #506

Merged
merged 3 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Core/GoalsComponent/NpcNameTargeting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public bool FindBy(params CursorType[] cursor)
const int e = 3;
Span<Point> attemptPoints = stackalloc Point[c + (c * e)];

for (int ni = 0; ni < npcNameFinder.Npcs.Length; ni++)
for (int ni = 0; ni < npcNameFinder.Npcs.Count; ni++)
{
NpcPosition npc = npcNameFinder.Npcs[ni];
for (int i = 0; i < c; i += e)
Expand Down Expand Up @@ -204,7 +204,7 @@ public bool FindBy(params CursorType[] cursor)

public void ShowClickPositions(Graphics gr)
{
for (int i = 0; i < npcNameFinder.Npcs.Length; i++)
for (int i = 0; i < npcNameFinder.Npcs.Count; i++)
{
NpcPosition npc = npcNameFinder.Npcs[i];
for (int j = 0; j < locFindBy.Length; j++)
Expand Down
1 change: 1 addition & 0 deletions CoreTests/CoreTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<TargetFramework>net7.0</TargetFramework>
<Platforms>AnyCPU;x64;x86</Platforms>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions CoreTests/NpcNameFinder/NpcNameOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class NpcNameOverlay : IDisposable
private readonly bool debugTargeting;
private readonly bool debugSkinning;

private const int padding = 4;
private const int padding = 6;
private const float NumberLeftPadding = 20f;
private const int FontSize = 10;

Expand Down Expand Up @@ -115,7 +115,7 @@ private void DrawGraphics(object sender, DrawGraphicsEventArgs e)

g.DrawRectangle(brush, npcNameFinder.Area.Left, npcNameFinder.Area.Top, npcNameFinder.Area.Right, npcNameFinder.Area.Bottom, 1);

for (int i = 0; i < npcNameFinder.Npcs.Length; i++)
for (int i = 0; i < npcNameFinder.Npcs.Count; i++)
{
NpcPosition npc = npcNameFinder.Npcs[i];

Expand Down
20 changes: 12 additions & 8 deletions CoreTests/NpcNameFinder/Test_NpcNameFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,25 @@ public void Dispose()

public void Execute()
{
if (LogEachUpdate)
stopwatch.Restart();

long captureTime = Stopwatch.GetTimestamp();
wowScreen.Update();

if (LogEachUpdate)
logger.LogInformation($"Capture: {stopwatch.ElapsedMilliseconds}ms");

if (LogEachUpdate)
stopwatch.Restart();
{
stringBuilder.Length = 0;
stringBuilder.Append($"Capture: {Stopwatch.GetElapsedTime(captureTime).TotalMilliseconds:F6}ms");
}

long updateTime = Stopwatch.GetTimestamp();
npcNameFinder.Update();

if (LogEachUpdate)
logger.LogInformation($"Update: {stopwatch.ElapsedMilliseconds}ms");
{
stringBuilder.Append(" | ");
stringBuilder.Append($"Update: {Stopwatch.GetElapsedTime(updateTime).TotalMilliseconds:F6}ms");

logger.LogInformation(stringBuilder.ToString());
}

if (saveImage)
{
Expand Down
4 changes: 1 addition & 3 deletions SharedLib/Extensions/PointExt.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Drawing;

using static System.MathF;

namespace SharedLib.Extensions;

public static class PointExt
Expand All @@ -18,6 +16,6 @@ public static Point Scale(this Point p, float scaleX, float scaleY)

public static float SqrDistance(in Point p1, in Point p2)
{
return Sqrt(((p1.X - p2.X) * (p1.X - p2.X)) + ((p1.Y - p2.Y) * (p1.Y - p2.Y)));
return ((p1.X - p2.X) * (p1.X - p2.X)) + ((p1.Y - p2.Y) * (p1.Y - p2.Y));
}
}
4 changes: 2 additions & 2 deletions SharedLib/NpcFinder/LineSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ public readonly struct LineSegment
public readonly int XEnd;
public readonly int XCenter;

public LineSegment(int xStart, int xend, int y)
public LineSegment(int xStart, int xEnd, int y)
{
this.XStart = xStart;
this.Y = y;
this.XEnd = xend;
this.XEnd = xEnd;
XCenter = XStart + ((XEnd - XStart) / 2);
}
}
Loading