Skip to content
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
659 changes: 581 additions & 78 deletions Aimmy2/AILogic/AIManager.cs

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions Aimmy2/AILogic/CaptureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
InitializeDxgiDuplication();
_displayChangesPending = false;
}
catch (Exception ex)

Check warning on line 78 in Aimmy2/AILogic/CaptureManager.cs

View workflow job for this annotation

GitHub Actions / build (x64, Release)

The variable 'ex' is declared but never used
{

}
Expand Down Expand Up @@ -239,7 +239,7 @@
throw;
}
}
private Bitmap? DirectX(Rectangle detectionBox)
private Bitmap? DirectX(Rectangle detectionBox, bool allowStaleCache = false)
{
int w = detectionBox.Width;
int h = detectionBox.Height;
Expand Down Expand Up @@ -268,7 +268,7 @@
if (_dxDevice == null || _dxDevice.ImmediateContext == null || _deskDuplication == null)
{
lock (_displayLock) { _displayChangesPending = true; }
return GetCachedFrame(detectionBox);
return GetCachedFrame(detectionBox, allowStaleCache);
}
}

Expand Down Expand Up @@ -305,7 +305,7 @@
{
// No new frame available - this is normal
_consecutiveFailures = 0; // Reset failure counter
return GetCachedFrame(detectionBox);
return GetCachedFrame(detectionBox, allowStaleCache);
}
else if (result == Vortice.DXGI.ResultCode.DeviceRemoved || result == Vortice.DXGI.ResultCode.AccessLost)
{ // Device lost - need to reinitialize
Expand All @@ -314,13 +314,13 @@
if (_consecutiveFailures >= MAX_CONSECUTIVE_FAILURES)
lock (_displayLock) { _displayChangesPending = true; }

return GetCachedFrame(detectionBox);
return GetCachedFrame(detectionBox, allowStaleCache);
}
else if (result != Result.Ok)
{
// Other error
_consecutiveFailures++;
return GetCachedFrame(detectionBox);
return GetCachedFrame(detectionBox, allowStaleCache);
}

frameAcquired = true;
Expand Down Expand Up @@ -362,7 +362,7 @@
else
{
LogManager.Log(LogLevel.Warning, "No visible region to copy from DirectX capture.", true, 3000);
return GetCachedFrame(detectionBox);
return GetCachedFrame(detectionBox, allowStaleCache);
}

#endregion
Expand Down Expand Up @@ -432,7 +432,7 @@
if (++_consecutiveFailures >= MAX_CONSECUTIVE_FAILURES)
lock (_displayLock) { _displayChangesPending = true; }

return GetCachedFrame(detectionBox);
return GetCachedFrame(detectionBox, allowStaleCache);
}
finally
{
Expand Down Expand Up @@ -465,11 +465,11 @@
}


private Bitmap? GetCachedFrame(Rectangle detectionBox)
private Bitmap? GetCachedFrame(Rectangle detectionBox, bool allowStaleCache = false)
{
if (_cachedFrame != null &&
_cachedFrameBounds.Equals(detectionBox) &&
DateTime.Now - _lastFrameTime <= _frameCacheTimeout)
(allowStaleCache || DateTime.Now - _lastFrameTime <= _frameCacheTimeout))
{
return (Bitmap)_cachedFrame.Clone();
}
Expand Down Expand Up @@ -528,7 +528,7 @@
}
#endregion

public Bitmap? ScreenGrab(Rectangle detectionBox)
public Bitmap? ScreenGrab(Rectangle detectionBox, bool allowStaleCache = false)
{
string selectedMethod = AimSettings.ScreenCaptureMethod;

Expand Down Expand Up @@ -566,7 +566,7 @@

if (selectedMethod == "DirectX" && !_directXFailedPermanently)
{
return DirectX(detectionBox);
return DirectX(detectionBox, allowStaleCache);
}
else
{
Expand Down
Loading
Loading