Skip to content

Commit 9bcdb31

Browse files
committed
feat: add actions to set max and min FPS at runtime
This adds two new event actions under the Time category that allow developers to change the game's maximum and minimum FPS during runtime. These values are applied directly to the RuntimeGame instance and affect the rendering loop's frame rate capping behavior. Note: No validation is currently performed. Negative values or setting minFPS greater than maxFPS may lead to undefined behavior or visual issues. Future improvements could include IDE-level validation or runtime warnings.
1 parent f28dc8e commit 9bcdb31

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

Core/GDCore/Extensions/Builtin/TimeExtension.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,28 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsTimeExtension(
151151
.AddParameter("expression",
152152
_("Scale (1: Default, 2: 2x faster, 0.5: 2x slower...)"));
153153

154+
extension
155+
.AddAction("SetMaximumFPS",
156+
_("Maximum FPS"),
157+
_("Change the maximum frames per second at runtime."),
158+
_("Set maximum FPS to _PARAM1_"),
159+
_("Rendering"),
160+
"res/actions/fps_max24.png",
161+
"res/actions/fps_max.png")
162+
.AddCodeOnlyParameter("currentScene", "")
163+
.AddParameter("expression", _("Maximum FPS"));
164+
165+
extension
166+
.AddAction("SetMinimumFPS",
167+
_("Minimum FPS"),
168+
_("Change the minimum frames per second at runtime."),
169+
_("Set minimum FPS to _PARAM1_"),
170+
_("Rendering"),
171+
"res/actions/fps_min24.png",
172+
"res/actions/fps_min.png")
173+
.AddCodeOnlyParameter("currentScene", "")
174+
.AddParameter("expression", _("Minimum FPS"));
175+
154176
extension
155177
.AddAction("Wait",
156178
_("Wait X seconds"),

GDJS/GDJS/Extensions/Builtin/TimeExtension.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ TimeExtension::TimeExtension() {
3434
"gdjs.evtTools.runtimeScene.getTimeScale");
3535
GetAllActions()["ChangeTimeScale"].SetFunctionName(
3636
"gdjs.evtTools.runtimeScene.setTimeScale");
37+
GetAllActions()["SetMaximumFPS"].SetFunctionName(
38+
"gdjs.evtTools.runtimeScene.setMaximumFPS");
39+
GetAllActions()["SetMinimumFPS"].SetFunctionName(
40+
"gdjs.evtTools.runtimeScene.setMinimumFPS");
3741

3842
GetAllExpressions()["TimeDelta"].SetFunctionName(
3943
"gdjs.evtTools.runtimeScene.getElapsedTimeInSeconds");

GDJS/Runtime/events-tools/runtimescenetools.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@ namespace gdjs {
5252
return runtimeScene.getScene().getTimeManager().setTimeScale(timeScale);
5353
};
5454

55+
export const setMaximumFPS = function(
56+
runtimeScene: gdjs.RuntimeScene,
57+
fps: float
58+
) {
59+
runtimeScene.getGame()._maxFPS = fps;
60+
};
61+
62+
export const setMinimumFPS = function(
63+
runtimeScene: gdjs.RuntimeScene,
64+
fps: float
65+
) {
66+
runtimeScene.getGame()._minFPS = fps;
67+
};
68+
5569
export const getTimeScale = function (runtimeScene: gdjs.RuntimeScene) {
5670
return runtimeScene.getScene().getTimeManager().getTimeScale();
5771
};

0 commit comments

Comments
 (0)