Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a method to set the number of physics solver iterations in 3D (3.x) #50257

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/classes/Physics2DServer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@
<argument index="0" name="iterations" type="int">
</argument>
<description>
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].
</description>
</method>
<method name="shape_get_data" qualifiers="const">
Expand Down
10 changes: 10 additions & 0 deletions doc/classes/PhysicsServer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,16 @@
Activates or deactivates the 3D physics engine.
</description>
</method>
<method name="set_collision_iterations">
<return type="void">
</return>
<argument index="0" name="iterations" type="int">
</argument>
<description>
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 GodotPhysics engine, not the default Bullet physics engine.
</description>
</method>
<method name="shape_create">
<return type="RID">
</return>
Expand Down
4 changes: 4 additions & 0 deletions modules/bullet/bullet_physics_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,10 @@ void BulletPhysicsServer::finish() {
BulletPhysicsDirectBodyState::destroySingleton();
}

void BulletPhysicsServer::set_collision_iterations(int p_iterations) {
WARN_PRINT("Changing the number of 3D physics collision iterations is only supported when using GodotPhysics, not Bullet.");
}

int BulletPhysicsServer::get_process_info(ProcessInfo p_info) {
return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions modules/bullet/bullet_physics_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,8 @@ class BulletPhysicsServer : public PhysicsServer {

virtual bool is_flushing_queries() const { return false; }

virtual void set_collision_iterations(int p_iterations);

virtual int get_process_info(ProcessInfo p_info);

CollisionObjectBullet *get_collisin_object(RID p_object) const;
Expand Down
4 changes: 4 additions & 0 deletions servers/physics/physics_server_sw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,10 @@ void PhysicsServerSW::set_active(bool p_active) {
active = p_active;
};

void PhysicsServerSW::set_collision_iterations(int p_iterations) {
iterations = p_iterations;
};

void PhysicsServerSW::init() {
last_step = 0.001;
iterations = 8; // 8?
Expand Down
2 changes: 2 additions & 0 deletions servers/physics/physics_server_sw.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ class PhysicsServerSW : public PhysicsServer {
virtual void flush_queries();
virtual void finish();

virtual void set_collision_iterations(int p_iterations);

virtual bool is_flushing_queries() const { return flushing_queries; }

int get_process_info(ProcessInfo p_info);
Expand Down
2 changes: 1 addition & 1 deletion servers/physics_2d_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ class Physics2DServer : public Object {

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 {

Expand Down
2 changes: 2 additions & 0 deletions servers/physics_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,8 @@ void PhysicsServer::_bind_methods() {

ClassDB::bind_method(D_METHOD("set_active", "active"), &PhysicsServer::set_active);

ClassDB::bind_method(D_METHOD("set_collision_iterations", "iterations"), &PhysicsServer::set_collision_iterations);

ClassDB::bind_method(D_METHOD("get_process_info", "process_info"), &PhysicsServer::get_process_info);

BIND_ENUM_CONSTANT(SHAPE_PLANE);
Expand Down
2 changes: 2 additions & 0 deletions servers/physics_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,8 @@ class PhysicsServer : public Object {

virtual bool is_flushing_queries() const = 0;

virtual void set_collision_iterations(int p_iterations) = 0;

enum ProcessInfo {

INFO_ACTIVE_OBJECTS,
Expand Down