Add setting for specifying custom framerate when window is not active

This commit is contained in:
2023-10-01 17:53:10 +03:00
parent a818f39464
commit 7ed59a4426
4 changed files with 14 additions and 0 deletions

View File

@@ -176,6 +176,7 @@ Window* GameBase::CreateMainWindow()
settings.AllowMinimize = true;
settings.Size = Platform::GetDesktopSize();
settings.Position = Float2::Zero;
settings.WindowFPSWhenNotFocused = 0;
Game::InitMainWindowSettings(settings);

View File

@@ -14,6 +14,7 @@
#include "Engine/Scripting/ManagedCLR/MUtils.h"
#include "Engine/Scripting/ManagedCLR/MMethod.h"
#include "Engine/Scripting/ManagedCLR/MClass.h"
#include "Engine/Engine/Time.h"
#if USE_CSHARP
// Helper macros for calling C# events
@@ -436,6 +437,9 @@ void WindowBase::OnGotFocus()
return;
_focused = true;
if (RenderTask && _settings.WindowFPSWhenNotFocused > ZeroTolerance)
RenderTask->RenderFPS = 0;
GotFocus();
INVOKE_EVENT_PARAMS_0(OnGotFocus);
}
@@ -446,6 +450,9 @@ void WindowBase::OnLostFocus()
return;
_focused = false;
if (RenderTask && _settings.WindowFPSWhenNotFocused > ZeroTolerance)
RenderTask->RenderFPS = _settings.WindowFPSWhenNotFocused;
LostFocus();
INVOKE_EVENT_PARAMS_0(OnLostFocus);
}

View File

@@ -24,6 +24,7 @@ namespace FlaxEngine
IsRegularWindow = true,
HasSizingFrame = true,
ShowAfterFirstPaint = true,
WindowFPSWhenNotFocused = 2,
};
}
}

View File

@@ -133,6 +133,11 @@ DECLARE_SCRIPTING_TYPE_MINIMAL(CreateWindowSettings);
/// </summary>
API_FIELD() bool ShowAfterFirstPaint = true;
/// <summary>
/// Custom framerate limit for window rendering when the window is not focused.
/// </summary>
API_FIELD() int WindowFPSWhenNotFocused = 2;
/// <summary>
/// The custom data (platform dependant).
/// </summary>