From f0a145bbf52b44c5e45ee292935163bc882fa063 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Wed, 7 Jul 2021 19:09:15 +0200 Subject: [PATCH] Add a method to set the number of physics solver iterations in 3D This is only for GodotPhysics, and adds a 3D counterpart to the 2D method that was recently added. --- doc/classes/PhysicsServer2D.xml | 2 +- doc/classes/PhysicsServer3D.xml | 10 ++++++++++ servers/physics_3d/physics_server_3d_sw.cpp | 4 ++++ servers/physics_3d/physics_server_3d_sw.h | 2 ++ servers/physics_3d/physics_server_3d_wrap_mt.h | 1 + servers/physics_server_2d.h | 2 +- servers/physics_server_3d.cpp | 2 ++ servers/physics_server_3d.h | 2 ++ 8 files changed, 23 insertions(+), 2 deletions(-) diff --git a/doc/classes/PhysicsServer2D.xml b/doc/classes/PhysicsServer2D.xml index 33cd61eb9cf..67b27b174f5 100644 --- a/doc/classes/PhysicsServer2D.xml +++ b/doc/classes/PhysicsServer2D.xml @@ -1024,7 +1024,7 @@ - Sets the amount of iterations for calculating velocities of colliding bodies. The greater the amount, the more accurate the collisions, but with a performance loss. + Sets the amount of iterations for calculating velocities of colliding bodies. The greater the amount of iterations, the more accurate the collisions will be. However, a greater amount of iterations requires more CPU power, which can decrease performance. The default value is [code]8[/code]. diff --git a/doc/classes/PhysicsServer3D.xml b/doc/classes/PhysicsServer3D.xml index 88ce2223240..9db7ff5c128 100644 --- a/doc/classes/PhysicsServer3D.xml +++ b/doc/classes/PhysicsServer3D.xml @@ -1187,6 +1187,16 @@ Activates or deactivates the 3D physics engine. + + + + + + + Sets the amount of iterations for calculating velocities of colliding bodies. The greater the amount of iterations, the more accurate the collisions will be. However, a greater amount of iterations requires more CPU power, which can decrease performance. The default value is [code]8[/code]. + [b]Note:[/b] Only has an effect when using the default GodotPhysics engine, not the Bullet physics engine. + + diff --git a/servers/physics_3d/physics_server_3d_sw.cpp b/servers/physics_3d/physics_server_3d_sw.cpp index f26129a4046..c1a9d6259da 100644 --- a/servers/physics_3d/physics_server_3d_sw.cpp +++ b/servers/physics_3d/physics_server_3d_sw.cpp @@ -1584,6 +1584,10 @@ void PhysicsServer3DSW::set_active(bool p_active) { active = p_active; }; +void PhysicsServer3DSW::set_collision_iterations(int p_iterations) { + iterations = p_iterations; +}; + void PhysicsServer3DSW::init() { last_step = 0.001; iterations = 8; // 8? diff --git a/servers/physics_3d/physics_server_3d_sw.h b/servers/physics_3d/physics_server_3d_sw.h index 57b6385758b..0ccd15fbb2f 100644 --- a/servers/physics_3d/physics_server_3d_sw.h +++ b/servers/physics_3d/physics_server_3d_sw.h @@ -367,6 +367,8 @@ public: virtual void end_sync() override; virtual void finish() override; + virtual void set_collision_iterations(int p_iterations) override; + virtual bool is_flushing_queries() const override { return flushing_queries; } int get_process_info(ProcessInfo p_info) override; diff --git a/servers/physics_3d/physics_server_3d_wrap_mt.h b/servers/physics_3d/physics_server_3d_wrap_mt.h index bda2e30dd12..9beec22bcd6 100644 --- a/servers/physics_3d/physics_server_3d_wrap_mt.h +++ b/servers/physics_3d/physics_server_3d_wrap_mt.h @@ -377,6 +377,7 @@ public: FUNC1(free, RID); FUNC1(set_active, bool); + FUNC1(set_collision_iterations, int); virtual void init() override; virtual void step(real_t p_step) override; diff --git a/servers/physics_server_2d.h b/servers/physics_server_2d.h index 6737aacaf09..e2bff2975e0 100644 --- a/servers/physics_server_2d.h +++ b/servers/physics_server_2d.h @@ -564,7 +564,7 @@ public: virtual bool is_flushing_queries() const = 0; - virtual void set_collision_iterations(int iterations) = 0; + virtual void set_collision_iterations(int p_iterations) = 0; enum ProcessInfo { INFO_ACTIVE_OBJECTS, diff --git a/servers/physics_server_3d.cpp b/servers/physics_server_3d.cpp index 7a0253506cf..3ed88411194 100644 --- a/servers/physics_server_3d.cpp +++ b/servers/physics_server_3d.cpp @@ -740,6 +740,8 @@ void PhysicsServer3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_active", "active"), &PhysicsServer3D::set_active); + ClassDB::bind_method(D_METHOD("set_collision_iterations", "iterations"), &PhysicsServer3D::set_collision_iterations); + ClassDB::bind_method(D_METHOD("get_process_info", "process_info"), &PhysicsServer3D::get_process_info); BIND_ENUM_CONSTANT(SHAPE_PLANE); diff --git a/servers/physics_server_3d.h b/servers/physics_server_3d.h index 78fc0267473..17bae9a057b 100644 --- a/servers/physics_server_3d.h +++ b/servers/physics_server_3d.h @@ -740,6 +740,8 @@ public: virtual bool is_flushing_queries() const = 0; + virtual void set_collision_iterations(int p_iterations) = 0; + enum ProcessInfo { INFO_ACTIVE_OBJECTS, INFO_COLLISION_PAIRS,