From ccc6a8c7ec2e31885e508f9cfa2956d75d53ee66 Mon Sep 17 00:00:00 2001 From: Doprez <73259914+Doprez@users.noreply.github.com> Date: Sat, 9 Mar 2024 14:11:40 -0700 Subject: [PATCH] added focus lost extension --- .../Engine/GameExtensions.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Stride.CommunityToolkit/Engine/GameExtensions.cs b/src/Stride.CommunityToolkit/Engine/GameExtensions.cs index 00fbaf70..65aa87bd 100644 --- a/src/Stride.CommunityToolkit/Engine/GameExtensions.cs +++ b/src/Stride.CommunityToolkit/Engine/GameExtensions.cs @@ -781,7 +781,19 @@ public static Entity Create3DPrimitiveWithBepu(this IGame game, PrimitiveModelTy public static void SetMaxFPS(this IGame game, int targetFPS) { var gameBase = (GameBase)game; - gameBase.WindowMinimumUpdateRate.MinimumElapsedTime = TimeSpan.FromMilliseconds(1000 / targetFPS); + gameBase.WindowMinimumUpdateRate.MinimumElapsedTime = TimeSpan.FromMilliseconds(1000f / targetFPS); + } + + /// + /// Sets the maximum frames per second (FPS) rate for the game when not in focus. + /// Set to 0 for max possible FPS. + /// + /// + /// + public static void SetFocusLostFPS(this IGame game, int targetFPS) + { + var gameBase = (GameBase)game; + gameBase.MinimizedMinimumUpdateRate.MinimumElapsedTime = TimeSpan.FromMilliseconds(1000f / targetFPS); } /// @@ -789,7 +801,7 @@ public static void SetMaxFPS(this IGame game, int targetFPS) /// /// The game instance from which to obtain the FPS rate. /// The current FPS rate of the game. - public static float FPS(this Game game) => game.UpdateTime.FramePerSecond; + public static float FPS(this IGame game) => game.UpdateTime.FramePerSecond; private static ColliderBase? Get2DColliderShapeWithBepu(Primitive2DModelType type, Vector2? size = null, float depth = 0) {