optimized the Hide/Show function.

now overlay uses 0% of the CPU/GPU resources when it's hidden.
master
Zaafar Ahmed 7 years ago
parent c2aa64bc05
commit bdf04544c2
  1. 24
      ClickableTransparentOverlay/Overlay.cs

@ -26,11 +26,12 @@ namespace ClickableTransparentOverlay
// UI State // UI State
private static Vector4 clearColor; private static Vector4 clearColor;
private static Vector2 futurePos;
private static Vector2 futureSize;
private static int myFps; private static int myFps;
private static bool isVisible;
private static bool isClosed; private static bool isClosed;
// For Resizing SDL2Window
private static Vector2 futurePos;
private static Vector2 futureSize;
private static bool requireResize; private static bool requireResize;
/// <summary> /// <summary>
@ -55,7 +56,6 @@ namespace ClickableTransparentOverlay
{ {
clearColor = new Vector4(0.00f, 0.00f, 0.00f, 0.00f); clearColor = new Vector4(0.00f, 0.00f, 0.00f, 0.00f);
myFps = fps; myFps = fps;
isVisible = true;
isClosed = false; isClosed = false;
// Stuff related to (thread safe) resizing of SDL2Window // Stuff related to (thread safe) resizing of SDL2Window
@ -135,7 +135,7 @@ namespace ClickableTransparentOverlay
public void Show() public void Show()
{ {
hookController.ResumeHooks(); hookController.ResumeHooks();
isVisible = true; window.Visible = true;
} }
/// <summary> /// <summary>
@ -143,12 +143,8 @@ namespace ClickableTransparentOverlay
/// </summary> /// </summary>
public void Hide() public void Hide()
{ {
// TODO: Improve this function to do the following
// 1: Hide SDL2Window
// 2: Pause WhileLoop
// This will ensure we don't waste CPU/GPU resources while window is hidden
hookController.PauseHooks(); hookController.PauseHooks();
isVisible = false; window.Visible = false;
} }
/// <summary> /// <summary>
@ -156,7 +152,6 @@ namespace ClickableTransparentOverlay
/// </summary> /// </summary>
public void Dispose() public void Dispose()
{ {
isVisible = false;
window.Close(); window.Close();
while (!isClosed) while (!isClosed)
{ {
@ -192,6 +187,8 @@ namespace ClickableTransparentOverlay
if (!window.Visible) if (!window.Visible)
{ {
window.PumpEvents();
Thread.Sleep(10);
continue; continue;
} }
@ -201,12 +198,7 @@ namespace ClickableTransparentOverlay
} }
imController.InitlizeFrame(1f / myFps); imController.InitlizeFrame(1f / myFps);
if (isVisible)
{
this.SubmitUI?.Invoke(this, new EventArgs()); this.SubmitUI?.Invoke(this, new EventArgs());
}
commandList.Begin(); commandList.Begin();
commandList.SetFramebuffer(graphicsDevice.MainSwapchain.Framebuffer); commandList.SetFramebuffer(graphicsDevice.MainSwapchain.Framebuffer);
commandList.ClearColorTarget(0, new RgbaFloat(clearColor.X, clearColor.Y, clearColor.Z, clearColor.W)); commandList.ClearColorTarget(0, new RgbaFloat(clearColor.X, clearColor.Y, clearColor.Z, clearColor.W));

Loading…
Cancel
Save