summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorHugo Locurcio <hugo.locurcio@hugo.pro>2022-09-15 18:57:34 +0200
committerHugo Locurcio <hugo.locurcio@hugo.pro>2022-10-09 23:00:09 +0200
commit66f7c48e39c6479f11c0dd2426c093b0f2910f76 (patch)
treeaeec63f81055de9bcfb37d1a850937ce55662165 /main
parentca25c6e0a3f25948ee4a197f3442c66f019e7424 (diff)
Implement adjusting the maximum number of physics steps per rendered frame
When using high physics FPS (which is a requirement to minimize input lag and improve precision in simulation racing games), a higher value prevents the game from slowing down at low rendering FPS. This can be done via an Engine property for run-time changes, or a project setting for initial changes.
Diffstat (limited to 'main')
-rw-r--r--main/main.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/main/main.cpp b/main/main.cpp
index 08a9b4c310..539a3ad542 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -1774,6 +1774,12 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
ProjectSettings::get_singleton()->set_custom_property_info("physics/common/physics_ticks_per_second",
PropertyInfo(Variant::INT, "physics/common/physics_ticks_per_second",
PROPERTY_HINT_RANGE, "1,1000,1"));
+
+ Engine::get_singleton()->set_max_physics_steps_per_frame(GLOBAL_DEF("physics/common/max_physics_steps_per_frame", 8));
+ ProjectSettings::get_singleton()->set_custom_property_info("physics/common/max_physics_steps_per_frame",
+ PropertyInfo(Variant::INT, "physics/common/max_physics_steps_per_frame",
+ PROPERTY_HINT_RANGE, "1,100,1"));
+
Engine::get_singleton()->set_physics_jitter_fix(GLOBAL_DEF("physics/common/physics_jitter_fix", 0.5));
Engine::get_singleton()->set_max_fps(GLOBAL_DEF("application/run/max_fps", 0));
ProjectSettings::get_singleton()->set_custom_property_info("application/run/max_fps",
@@ -3076,7 +3082,7 @@ bool Main::iteration() {
last_ticks = ticks;
- static const int max_physics_steps = 8;
+ const int max_physics_steps = Engine::get_singleton()->get_max_physics_steps_per_frame();
if (fixed_fps == -1 && advance.physics_steps > max_physics_steps) {
process_step -= (advance.physics_steps - max_physics_steps) * physics_step;
advance.physics_steps = max_physics_steps;