diff options
author | PouleyKetchoupp <pouleyketchoup@gmail.com> | 2021-12-06 18:10:13 -0700 |
---|---|---|
committer | PouleyKetchoupp <pouleyketchoup@gmail.com> | 2021-12-07 12:08:04 -0700 |
commit | 8682adcb8726459d2a0366dcea0a59ce742bee43 (patch) | |
tree | 5eade5f25ecd9247d3a926d9b27bddc7416287cb /servers | |
parent | 4bce5e302ef8cc6fcd0caf5137f0c1d3abdb88c2 (diff) |
Add physics solver settings to project settings
Helps with discovery and setup of physics solver settings, in a specific
project settings section for both 2D and 3D.
Other changes for cleanup:
-Removed unused space parameters in 3D
SPACE_PARAM_BODY_ANGULAR_VELOCITY_DAMP_RATIO
SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS
-Added custom solver bias for Shape3D (same as Shape2D)
-Improved documentation for solver settings
Diffstat (limited to 'servers')
-rw-r--r-- | servers/physics_2d/godot_space_2d.cpp | 18 | ||||
-rw-r--r-- | servers/physics_2d/godot_space_2d.h | 14 | ||||
-rw-r--r-- | servers/physics_3d/godot_space_3d.cpp | 26 | ||||
-rw-r--r-- | servers/physics_3d/godot_space_3d.h | 24 | ||||
-rw-r--r-- | servers/physics_server_3d.cpp | 2 | ||||
-rw-r--r-- | servers/physics_server_3d.h | 2 |
6 files changed, 50 insertions, 36 deletions
diff --git a/servers/physics_2d/godot_space_2d.cpp b/servers/physics_2d/godot_space_2d.cpp index 5e6f233667..2e0379fe8a 100644 --- a/servers/physics_2d/godot_space_2d.cpp +++ b/servers/physics_2d/godot_space_2d.cpp @@ -1208,6 +1208,24 @@ GodotSpace2D::GodotSpace2D() { body_time_to_sleep = GLOBAL_DEF("physics/2d/time_before_sleep", 0.5); ProjectSettings::get_singleton()->set_custom_property_info("physics/2d/time_before_sleep", PropertyInfo(Variant::FLOAT, "physics/2d/time_before_sleep", PROPERTY_HINT_RANGE, "0,5,0.01,or_greater")); + solver_iterations = GLOBAL_DEF("physics/2d/solver/solver_iterations", 16); + ProjectSettings::get_singleton()->set_custom_property_info("physics/2d/solver/solver_iterations", PropertyInfo(Variant::INT, "physics/2d/solver/solver_iterations", PROPERTY_HINT_RANGE, "1,32,1,or_greater")); + + contact_recycle_radius = GLOBAL_DEF("physics/2d/solver/contact_recycle_radius", 1.0); + ProjectSettings::get_singleton()->set_custom_property_info("physics/2d/solver/contact_recycle_radius", PropertyInfo(Variant::FLOAT, "physics/2d/solver/contact_max_separation", PROPERTY_HINT_RANGE, "0,10,0.01,or_greater")); + + contact_max_separation = GLOBAL_DEF("physics/2d/solver/contact_max_separation", 1.5); + ProjectSettings::get_singleton()->set_custom_property_info("physics/2d/solver/contact_max_separation", PropertyInfo(Variant::FLOAT, "physics/2d/solver/contact_max_separation", PROPERTY_HINT_RANGE, "0,10,0.01,or_greater")); + + contact_max_allowed_penetration = GLOBAL_DEF("physics/2d/solver/contact_max_allowed_penetration", 0.3); + ProjectSettings::get_singleton()->set_custom_property_info("physics/2d/solver/contact_max_allowed_penetration", PropertyInfo(Variant::FLOAT, "physics/2d/solver/contact_max_allowed_penetration", PROPERTY_HINT_RANGE, "0,10,0.01,or_greater")); + + contact_bias = GLOBAL_DEF("physics/2d/solver/default_contact_bias", 0.8); + ProjectSettings::get_singleton()->set_custom_property_info("physics/2d/solver/default_contact_bias", PropertyInfo(Variant::FLOAT, "physics/2d/solver/default_contact_bias", PROPERTY_HINT_RANGE, "0,1,0.01")); + + constraint_bias = GLOBAL_DEF("physics/2d/solver/default_constraint_bias", 0.2); + ProjectSettings::get_singleton()->set_custom_property_info("physics/2d/solver/default_constraint_bias", PropertyInfo(Variant::FLOAT, "physics/2d/solver/default_constraint_bias", PROPERTY_HINT_RANGE, "0,1,0.01")); + broadphase = GodotBroadPhase2D::create_func(); broadphase->set_pair_callback(_broadphase_pair, this); broadphase->set_unpair_callback(_broadphase_unpair, this); diff --git a/servers/physics_2d/godot_space_2d.h b/servers/physics_2d/godot_space_2d.h index c0d06706d8..e11f4c3afb 100644 --- a/servers/physics_2d/godot_space_2d.h +++ b/servers/physics_2d/godot_space_2d.h @@ -82,7 +82,7 @@ private: GodotPhysicsDirectSpaceState2D *direct_access = nullptr; RID self; - GodotBroadPhase2D *broadphase; + GodotBroadPhase2D *broadphase = nullptr; SelfList<GodotBody2D>::List active_list; SelfList<GodotBody2D>::List mass_properties_update_list; SelfList<GodotBody2D>::List state_query_list; @@ -96,13 +96,13 @@ private: GodotArea2D *area = nullptr; - int solver_iterations = 16; + int solver_iterations = 0; - real_t contact_recycle_radius = 1.0; - real_t contact_max_separation = 1.5; - real_t contact_max_allowed_penetration = 0.3; - real_t contact_bias = 0.8; - real_t constraint_bias = 0.2; + real_t contact_recycle_radius = 0.0; + real_t contact_max_separation = 0.0; + real_t contact_max_allowed_penetration = 0.0; + real_t contact_bias = 0.0; + real_t constraint_bias = 0.0; enum { INTERSECTION_QUERY_MAX = 2048 diff --git a/servers/physics_3d/godot_space_3d.cpp b/servers/physics_3d/godot_space_3d.cpp index b2a8b00bca..e62ae41ca0 100644 --- a/servers/physics_3d/godot_space_3d.cpp +++ b/servers/physics_3d/godot_space_3d.cpp @@ -1188,12 +1188,6 @@ void GodotSpace3D::set_param(PhysicsServer3D::SpaceParameter p_param, real_t p_v case PhysicsServer3D::SPACE_PARAM_BODY_TIME_TO_SLEEP: body_time_to_sleep = p_value; break; - case PhysicsServer3D::SPACE_PARAM_BODY_ANGULAR_VELOCITY_DAMP_RATIO: - body_angular_velocity_damp_ratio = p_value; - break; - case PhysicsServer3D::SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS: - constraint_bias = p_value; - break; case PhysicsServer3D::SPACE_PARAM_SOLVER_ITERATIONS: solver_iterations = p_value; break; @@ -1216,10 +1210,6 @@ real_t GodotSpace3D::get_param(PhysicsServer3D::SpaceParameter p_param) const { return body_angular_velocity_sleep_threshold; case PhysicsServer3D::SPACE_PARAM_BODY_TIME_TO_SLEEP: return body_time_to_sleep; - case PhysicsServer3D::SPACE_PARAM_BODY_ANGULAR_VELOCITY_DAMP_RATIO: - return body_angular_velocity_damp_ratio; - case PhysicsServer3D::SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS: - return constraint_bias; case PhysicsServer3D::SPACE_PARAM_SOLVER_ITERATIONS: return solver_iterations; } @@ -1247,7 +1237,21 @@ GodotSpace3D::GodotSpace3D() { body_angular_velocity_sleep_threshold = GLOBAL_DEF("physics/3d/sleep_threshold_angular", Math::deg2rad(8.0)); body_time_to_sleep = GLOBAL_DEF("physics/3d/time_before_sleep", 0.5); ProjectSettings::get_singleton()->set_custom_property_info("physics/3d/time_before_sleep", PropertyInfo(Variant::FLOAT, "physics/3d/time_before_sleep", PROPERTY_HINT_RANGE, "0,5,0.01,or_greater")); - body_angular_velocity_damp_ratio = 10; + + solver_iterations = GLOBAL_DEF("physics/3d/solver/solver_iterations", 16); + ProjectSettings::get_singleton()->set_custom_property_info("physics/3d/solver/solver_iterations", PropertyInfo(Variant::INT, "physics/3d/solver/solver_iterations", PROPERTY_HINT_RANGE, "1,32,1,or_greater")); + + contact_recycle_radius = GLOBAL_DEF("physics/3d/solver/contact_recycle_radius", 0.01); + ProjectSettings::get_singleton()->set_custom_property_info("physics/3d/solver/contact_recycle_radius", PropertyInfo(Variant::FLOAT, "physics/3d/solver/contact_max_separation", PROPERTY_HINT_RANGE, "0,0.1,0.01,or_greater")); + + contact_max_separation = GLOBAL_DEF("physics/3d/solver/contact_max_separation", 0.05); + ProjectSettings::get_singleton()->set_custom_property_info("physics/3d/solver/contact_max_separation", PropertyInfo(Variant::FLOAT, "physics/3d/solver/contact_max_separation", PROPERTY_HINT_RANGE, "0,0.1,0.01,or_greater")); + + contact_max_allowed_penetration = GLOBAL_DEF("physics/3d/solver/contact_max_allowed_penetration", 0.01); + ProjectSettings::get_singleton()->set_custom_property_info("physics/3d/solver/contact_max_allowed_penetration", PropertyInfo(Variant::FLOAT, "physics/3d/solver/contact_max_allowed_penetration", PROPERTY_HINT_RANGE, "0,0.1,0.01,or_greater")); + + contact_bias = GLOBAL_DEF("physics/3d/solver/default_contact_bias", 0.8); + ProjectSettings::get_singleton()->set_custom_property_info("physics/3d/solver/default_contact_bias", PropertyInfo(Variant::FLOAT, "physics/3d/solver/default_contact_bias", PROPERTY_HINT_RANGE, "0,1,0.01")); broadphase = GodotBroadPhase3D::create_func(); broadphase->set_pair_callback(_broadphase_pair, this); diff --git a/servers/physics_3d/godot_space_3d.h b/servers/physics_3d/godot_space_3d.h index b9aeee7583..fbdb65e29c 100644 --- a/servers/physics_3d/godot_space_3d.h +++ b/servers/physics_3d/godot_space_3d.h @@ -75,10 +75,10 @@ public: private: uint64_t elapsed_time[ELAPSED_TIME_MAX] = {}; - GodotPhysicsDirectSpaceState3D *direct_access; + GodotPhysicsDirectSpaceState3D *direct_access = nullptr; RID self; - GodotBroadPhase3D *broadphase; + GodotBroadPhase3D *broadphase = nullptr; SelfList<GodotBody3D>::List active_list; SelfList<GodotBody3D>::List mass_properties_update_list; SelfList<GodotBody3D>::List state_query_list; @@ -93,13 +93,12 @@ private: GodotArea3D *area = nullptr; - int solver_iterations = 16; + int solver_iterations = 0; - real_t contact_recycle_radius = 0.01; - real_t contact_max_separation = 0.05; - real_t contact_max_allowed_penetration = 0.01; - real_t contact_bias = 0.8; - real_t constraint_bias = 0.01; + real_t contact_recycle_radius = 0.0; + real_t contact_max_separation = 0.0; + real_t contact_max_allowed_penetration = 0.0; + real_t contact_bias = 0.0; enum { INTERSECTION_QUERY_MAX = 2048 @@ -108,10 +107,9 @@ private: GodotCollisionObject3D *intersection_query_results[INTERSECTION_QUERY_MAX]; int intersection_query_subindex_results[INTERSECTION_QUERY_MAX]; - real_t body_linear_velocity_sleep_threshold; - real_t body_angular_velocity_sleep_threshold; - real_t body_time_to_sleep; - real_t body_angular_velocity_damp_ratio; + real_t body_linear_velocity_sleep_threshold = 0.0; + real_t body_angular_velocity_sleep_threshold = 0.0; + real_t body_time_to_sleep = 0.0; bool locked = false; @@ -167,11 +165,9 @@ public: _FORCE_INLINE_ real_t get_contact_max_separation() const { return contact_max_separation; } _FORCE_INLINE_ real_t get_contact_max_allowed_penetration() const { return contact_max_allowed_penetration; } _FORCE_INLINE_ real_t get_contact_bias() const { return contact_bias; } - _FORCE_INLINE_ real_t get_constraint_bias() const { return constraint_bias; } _FORCE_INLINE_ real_t get_body_linear_velocity_sleep_threshold() const { return body_linear_velocity_sleep_threshold; } _FORCE_INLINE_ real_t get_body_angular_velocity_sleep_threshold() const { return body_angular_velocity_sleep_threshold; } _FORCE_INLINE_ real_t get_body_time_to_sleep() const { return body_time_to_sleep; } - _FORCE_INLINE_ real_t get_body_angular_velocity_damp_ratio() const { return body_angular_velocity_damp_ratio; } void update(); void setup(); diff --git a/servers/physics_server_3d.cpp b/servers/physics_server_3d.cpp index 658f7daf9f..405188d8d9 100644 --- a/servers/physics_server_3d.cpp +++ b/servers/physics_server_3d.cpp @@ -966,8 +966,6 @@ void PhysicsServer3D::_bind_methods() { BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD); BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD); BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_TIME_TO_SLEEP); - BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_ANGULAR_VELOCITY_DAMP_RATIO); - BIND_ENUM_CONSTANT(SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS); BIND_ENUM_CONSTANT(SPACE_PARAM_SOLVER_ITERATIONS); BIND_ENUM_CONSTANT(BODY_AXIS_LINEAR_X); diff --git a/servers/physics_server_3d.h b/servers/physics_server_3d.h index dfaefc5fbf..d58dccc41a 100644 --- a/servers/physics_server_3d.h +++ b/servers/physics_server_3d.h @@ -268,8 +268,6 @@ public: SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD, SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD, SPACE_PARAM_BODY_TIME_TO_SLEEP, - SPACE_PARAM_BODY_ANGULAR_VELOCITY_DAMP_RATIO, - SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS, SPACE_PARAM_SOLVER_ITERATIONS, }; |