Skip to content

Commit fd376b4

Browse files
committed
refined and fixed stickyaim
1 parent dcfcf7f commit fd376b4

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

Aimmy2/AILogic/AIManager.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,13 @@ public void PrintBenchmarks()
190190
var data = kvp.Value;
191191
lines.Add($"{kvp.Key}: Avg={data.AverageTime:F2}ms, Min={data.MinTime}ms, Max={data.MaxTime}ms, Count={data.CallCount}");
192192
}
193+
var overallFps = iterationCount > 0 && totalTime > 0 ? 1000.0 * iterationCount / totalTime : 0;
193194

194-
lines.Add($"Overall FPS: {(1000.0 / ((double)totalTime / iterationCount)):F2}");
195+
lines.Add($"Overall FPS: {overallFps:F2}");
195196

196197
//File.WriteAllLines("AIManager_Benchmarks.txt", lines);
197198

198-
LogManager.Log(LogManager.LogLevel.Info, string.Join(Environment.NewLine, lines));
199+
Log(LogLevel.Info, string.Join(Environment.NewLine, lines));
199200
}
200201
}
201202

@@ -982,12 +983,18 @@ private void HandlePredictions(KalmanPrediction kalmanPrediction, Prediction clo
982983
private Prediction? HandleStickyAim(Prediction? bestCandidate, List<Prediction> KDPredictions)
983984
{
984985
bool stickyAimEnabled = Dictionary.toggleState["Sticky Aim"];
985-
if (!stickyAimEnabled) return bestCandidate;
986+
if (!stickyAimEnabled)
987+
{
988+
_currentTarget = bestCandidate; // update anyway
989+
return bestCandidate;
990+
}
991+
992+
float thresholdSqr = (float)Math.Pow(Dictionary.sliderSettings["Sticky Aim Threshold"], 2);
993+
986994
if (_currentTarget != null)
987995
{
988996
Prediction? matchedTarget = null;
989997
float minSqrDistance = float.MaxValue;
990-
float thresholdSqr = (float)Math.Pow(Dictionary.sliderSettings["Sticky Aim Threshold"], 2);
991998

992999
foreach (var candidate in KDPredictions)
9931000
{
@@ -1002,14 +1009,21 @@ private void HandlePredictions(KalmanPrediction kalmanPrediction, Prediction clo
10021009
if (matchedTarget != null)
10031010
{
10041011
_consecutiveFramesWithoutTarget = 0;
1012+
_currentTarget = matchedTarget;
10051013
return matchedTarget;
10061014
}
10071015

10081016
if (++_consecutiveFramesWithoutTarget > MAX_FRAMES_WITHOUT_TARGET)
10091017
{
10101018
_currentTarget = null;
1019+
} else
1020+
{
1021+
return null; // No match found, keep the current target
10111022
}
10121023
}
1024+
1025+
// acquire a new target
1026+
_currentTarget = bestCandidate;
10131027
return bestCandidate;
10141028
}
10151029

Aimmy2/AILogic/CaptureManager.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ public void DisposeDxgiResources()
597597
_stagingTex?.Dispose();
598598
_dxDevice?.Dispose();
599599
_cachedFrame?.Dispose();
600-
//screenCaptureBitmap?.Dispose();
600+
directXBitmap?.Dispose();
601601

602602
_deskDuplication = null;
603603
_stagingTex = null;
@@ -618,7 +618,6 @@ public void Dispose()
618618
DisplayManager.DisplayChanged -= OnDisplayChanged;
619619
DisposeDxgiResources();
620620
screenCaptureBitmap?.Dispose();
621-
directXBitmap?.Dispose();
622621
}
623622
#endregion
624623
}

Aimmy2/AILogic/MathUtil.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static float Distance(Prediction a, Prediction b)
2121
{
2222
float dx = a.ScreenCenterX - b.ScreenCenterX;
2323
float dy = a.ScreenCenterY - b.ScreenCenterY;
24-
return (float)Math.Sqrt(dx * dx + dy * dy);
24+
return dx * dx + dy * dy;
2525
}
2626

2727
public static unsafe void BitmapToFloatArrayInPlace(Bitmap image, float[] result, int IMAGE_SIZE)

0 commit comments

Comments
 (0)