summaryrefslogtreecommitdiff
path: root/core/config
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 /core/config
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 'core/config')
-rw-r--r--core/config/engine.cpp9
-rw-r--r--core/config/engine.h4
2 files changed, 13 insertions, 0 deletions
diff --git a/core/config/engine.cpp b/core/config/engine.cpp
index 21e910be5b..7aa5f4d06d 100644
--- a/core/config/engine.cpp
+++ b/core/config/engine.cpp
@@ -48,6 +48,15 @@ int Engine::get_physics_ticks_per_second() const {
return ips;
}
+void Engine::set_max_physics_steps_per_frame(int p_max_physics_steps) {
+ ERR_FAIL_COND_MSG(p_max_physics_steps <= 0, "Maximum number of physics steps per frame must be greater than 0.");
+ max_physics_steps_per_frame = p_max_physics_steps;
+}
+
+int Engine::get_max_physics_steps_per_frame() const {
+ return max_physics_steps_per_frame;
+}
+
void Engine::set_physics_jitter_fix(double p_threshold) {
if (p_threshold < 0) {
p_threshold = 0;
diff --git a/core/config/engine.h b/core/config/engine.h
index 21517e46b7..1b179c5727 100644
--- a/core/config/engine.h
+++ b/core/config/engine.h
@@ -63,6 +63,7 @@ private:
int _max_fps = 0;
double _time_scale = 1.0;
uint64_t _physics_frames = 0;
+ int max_physics_steps_per_frame = 8;
double _physics_interpolation_fraction = 0.0f;
bool abort_on_gpu_errors = false;
bool use_validation_layers = false;
@@ -93,6 +94,9 @@ public:
virtual void set_physics_ticks_per_second(int p_ips);
virtual int get_physics_ticks_per_second() const;
+ virtual void set_max_physics_steps_per_frame(int p_max_physics_steps);
+ virtual int get_max_physics_steps_per_frame() const;
+
void set_physics_jitter_fix(double p_threshold);
double get_physics_jitter_fix() const;