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.AllowMinimize = true;
settings.Size = Platform::GetDesktopSize(); settings.Size = Platform::GetDesktopSize();
settings.Position = Float2::Zero; settings.Position = Float2::Zero;
settings.WindowFPSWhenNotFocused = 0;
Game::InitMainWindowSettings(settings); Game::InitMainWindowSettings(settings);

View File

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

View File

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

View File

@@ -133,6 +133,11 @@ DECLARE_SCRIPTING_TYPE_MINIMAL(CreateWindowSettings);
/// </summary> /// </summary>
API_FIELD() bool ShowAfterFirstPaint = true; 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> /// <summary>
/// The custom data (platform dependant). /// The custom data (platform dependant).
/// </summary> /// </summary>