Skip to content

Commit

Permalink
Merge pull request #17353 from zmanuel/timer_hysteresis_multiframe_pr1
Browse files Browse the repository at this point in the history
Use hysteresis for smoother physics update frequency
  • Loading branch information
reduz authored May 7, 2018
2 parents 9f2d54c + d5abd4e commit 633bbdb
Show file tree
Hide file tree
Showing 6 changed files with 267 additions and 16 deletions.
11 changes: 11 additions & 0 deletions core/bind/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2652,6 +2652,14 @@ int _Engine::get_iterations_per_second() const {
return Engine::get_singleton()->get_iterations_per_second();
}

void _Engine::set_physics_jitter_fix(float p_threshold) {
Engine::get_singleton()->set_physics_jitter_fix(p_threshold);
}

float _Engine::get_physics_jitter_fix() const {
return Engine::get_singleton()->get_physics_jitter_fix();
}

void _Engine::set_target_fps(int p_fps) {
Engine::get_singleton()->set_target_fps(p_fps);
}
Expand Down Expand Up @@ -2718,6 +2726,8 @@ void _Engine::_bind_methods() {

ClassDB::bind_method(D_METHOD("set_iterations_per_second", "iterations_per_second"), &_Engine::set_iterations_per_second);
ClassDB::bind_method(D_METHOD("get_iterations_per_second"), &_Engine::get_iterations_per_second);
ClassDB::bind_method(D_METHOD("set_physics_jitter_fix", "physics_jitter_fix"), &_Engine::set_physics_jitter_fix);
ClassDB::bind_method(D_METHOD("get_physics_jitter_fix"), &_Engine::get_physics_jitter_fix);
ClassDB::bind_method(D_METHOD("set_target_fps", "target_fps"), &_Engine::set_target_fps);
ClassDB::bind_method(D_METHOD("get_target_fps"), &_Engine::get_target_fps);

Expand All @@ -2743,6 +2753,7 @@ void _Engine::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "iterations_per_second"), "set_iterations_per_second", "get_iterations_per_second");
ADD_PROPERTY(PropertyInfo(Variant::INT, "target_fps"), "set_target_fps", "get_target_fps");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "time_scale"), "set_time_scale", "get_time_scale");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "physics_jitter_fix"), "set_physics_jitter_fix", "get_physics_jitter_fix");
}

_Engine *_Engine::singleton = NULL;
Expand Down
3 changes: 3 additions & 0 deletions core/bind/core_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,9 @@ class _Engine : public Object {
void set_iterations_per_second(int p_ips);
int get_iterations_per_second() const;

void set_physics_jitter_fix(float p_threshold);
float get_physics_jitter_fix() const;

void set_target_fps(int p_fps);
int get_target_fps() const;

Expand Down
11 changes: 11 additions & 0 deletions core/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ int Engine::get_iterations_per_second() const {
return ips;
}

void Engine::set_physics_jitter_fix(float p_threshold) {
if (p_threshold < 0)
p_threshold = 0;
physics_jitter_fix = p_threshold;
}

float Engine::get_physics_jitter_fix() const {
return physics_jitter_fix;
}

void Engine::set_target_fps(int p_fps) {
_target_fps = p_fps > 0 ? p_fps : 0;
}
Expand Down Expand Up @@ -137,6 +147,7 @@ Engine::Engine() {
singleton = this;
frames_drawn = 0;
ips = 60;
physics_jitter_fix = 0.5;
_frame_delay = 0;
_fps = 1;
_target_fps = 0;
Expand Down
4 changes: 4 additions & 0 deletions core/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Engine {
float _frame_step;

int ips;
float physics_jitter_fix;
float _fps;
int _target_fps;
float _time_scale;
Expand All @@ -79,6 +80,9 @@ class Engine {
virtual void set_iterations_per_second(int p_ips);
virtual int get_iterations_per_second() const;

void set_physics_jitter_fix(float p_threshold);
float get_physics_jitter_fix() const;

virtual void set_target_fps(int p_fps);
virtual float get_target_fps() const;

Expand Down
Loading

0 comments on commit 633bbdb

Please sign in to comment.