Update space parameters in 2D and 3D

Clarified space parameters for contacts and added missing ones.

List of changes:
-Add contact bias to space parameters
-Add solver iterations to space parameters, instead of a specific
physics server function
-Renamed BODY_MAX_ALLOWED_PENETRATION to CONTACT_MAX_ALLOWED_PENETRATION
to make it consistent with other contact parameters
This commit is contained in:
PouleyKetchoupp 2021-12-03 10:38:40 -07:00
parent 5cbc7149a1
commit 2273a78af1
22 changed files with 93 additions and 84 deletions

View File

@ -711,13 +711,6 @@
Activates or deactivates the 2D physics engine. Activates or deactivates the 2D physics engine.
</description> </description>
</method> </method>
<method name="set_collision_iterations">
<return type="void" />
<argument index="0" name="iterations" type="int" />
<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].
</description>
</method>
<method name="shape_get_data" qualifiers="const"> <method name="shape_get_data" qualifiers="const">
<return type="Variant" /> <return type="Variant" />
<argument index="0" name="shape" type="RID" /> <argument index="0" name="shape" type="RID" />
@ -798,21 +791,27 @@
<constant name="SPACE_PARAM_CONTACT_MAX_SEPARATION" value="1" enum="SpaceParameter"> <constant name="SPACE_PARAM_CONTACT_MAX_SEPARATION" value="1" enum="SpaceParameter">
Constant to set/get the maximum distance a shape can be from another before they are considered separated. Constant to set/get the maximum distance a shape can be from another before they are considered separated.
</constant> </constant>
<constant name="SPACE_PARAM_BODY_MAX_ALLOWED_PENETRATION" value="2" enum="SpaceParameter"> <constant name="SPACE_PARAM_CONTACT_MAX_ALLOWED_PENETRATION" value="2" enum="SpaceParameter">
Constant to set/get the maximum distance a shape can penetrate another shape before it is considered a collision. Constant to set/get the maximum distance a shape can penetrate another shape before it is considered a collision.
</constant> </constant>
<constant name="SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD" value="3" enum="SpaceParameter"> <constant name="SPACE_PARAM_CONTACT_DEFAULT_BIAS" value="3" enum="SpaceParameter">
Constant to set/get the default solver bias for all physics contacts. A solver bias is a factor controlling how much two objects "rebound", after overlapping, to avoid leaving them in that state because of numerical imprecision.
</constant>
<constant name="SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD" value="4" enum="SpaceParameter">
Constant to set/get the threshold linear velocity of activity. A body marked as potentially inactive for both linear and angular velocity will be put to sleep after the time given. Constant to set/get the threshold linear velocity of activity. A body marked as potentially inactive for both linear and angular velocity will be put to sleep after the time given.
</constant> </constant>
<constant name="SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD" value="4" enum="SpaceParameter"> <constant name="SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD" value="5" enum="SpaceParameter">
Constant to set/get the threshold angular velocity of activity. A body marked as potentially inactive for both linear and angular velocity will be put to sleep after the time given. Constant to set/get the threshold angular velocity of activity. A body marked as potentially inactive for both linear and angular velocity will be put to sleep after the time given.
</constant> </constant>
<constant name="SPACE_PARAM_BODY_TIME_TO_SLEEP" value="5" enum="SpaceParameter"> <constant name="SPACE_PARAM_BODY_TIME_TO_SLEEP" value="6" enum="SpaceParameter">
Constant to set/get the maximum time of activity. A body marked as potentially inactive for both linear and angular velocity will be put to sleep after this time. Constant to set/get the maximum time of activity. A body marked as potentially inactive for both linear and angular velocity will be put to sleep after this time.
</constant> </constant>
<constant name="SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS" value="6" enum="SpaceParameter"> <constant name="SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS" value="7" enum="SpaceParameter">
Constant to set/get the default solver bias for all physics constraints. A solver bias is a factor controlling how much two objects "rebound", after violating a constraint, to avoid leaving them in that state because of numerical imprecision. Constant to set/get the default solver bias for all physics constraints. A solver bias is a factor controlling how much two objects "rebound", after violating a constraint, to avoid leaving them in that state because of numerical imprecision.
</constant> </constant>
<constant name="SPACE_PARAM_SOLVER_ITERATIONS" value="8" enum="SpaceParameter">
Constant to set/get the number of solver iterations for all contacts and constraints. 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.
</constant>
<constant name="SHAPE_WORLD_BOUNDARY" value="0" enum="ShapeType"> <constant name="SHAPE_WORLD_BOUNDARY" value="0" enum="ShapeType">
This is the constant for creating world boundary shapes. A world boundary shape is an [i]infinite[/i] line with an origin point, and a normal. Thus, it can be used for front/behind checks. This is the constant for creating world boundary shapes. A world boundary shape is an [i]infinite[/i] line with an origin point, and a normal. Thus, it can be used for front/behind checks.
</constant> </constant>

View File

@ -846,14 +846,6 @@
Activates or deactivates the 3D physics engine. Activates or deactivates the 3D physics engine.
</description> </description>
</method> </method>
<method name="set_collision_iterations">
<return type="void" />
<argument index="0" name="iterations" type="int" />
<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 default GodotPhysics engine, not the Bullet physics engine.
</description>
</method>
<method name="shape_get_data" qualifiers="const"> <method name="shape_get_data" qualifiers="const">
<return type="Variant" /> <return type="Variant" />
<argument index="0" name="shape" type="RID" /> <argument index="0" name="shape" type="RID" />
@ -1343,23 +1335,29 @@
<constant name="SPACE_PARAM_CONTACT_MAX_SEPARATION" value="1" enum="SpaceParameter"> <constant name="SPACE_PARAM_CONTACT_MAX_SEPARATION" value="1" enum="SpaceParameter">
Constant to set/get the maximum distance a shape can be from another before they are considered separated. Constant to set/get the maximum distance a shape can be from another before they are considered separated.
</constant> </constant>
<constant name="SPACE_PARAM_BODY_MAX_ALLOWED_PENETRATION" value="2" enum="SpaceParameter"> <constant name="SPACE_PARAM_CONTACT_MAX_ALLOWED_PENETRATION" value="2" enum="SpaceParameter">
Constant to set/get the maximum distance a shape can penetrate another shape before it is considered a collision. Constant to set/get the maximum distance a shape can penetrate another shape before it is considered a collision.
</constant> </constant>
<constant name="SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD" value="3" enum="SpaceParameter"> <constant name="SPACE_PARAM_CONTACT_DEFAULT_BIAS" value="3" enum="SpaceParameter">
Constant to set/get the default solver bias for all physics contacts. A solver bias is a factor controlling how much two objects "rebound", after overlapping, to avoid leaving them in that state because of numerical imprecision.
</constant>
<constant name="SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD" value="4" enum="SpaceParameter">
Constant to set/get the threshold linear velocity of activity. A body marked as potentially inactive for both linear and angular velocity will be put to sleep after the time given. Constant to set/get the threshold linear velocity of activity. A body marked as potentially inactive for both linear and angular velocity will be put to sleep after the time given.
</constant> </constant>
<constant name="SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD" value="4" enum="SpaceParameter"> <constant name="SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD" value="5" enum="SpaceParameter">
Constant to set/get the threshold angular velocity of activity. A body marked as potentially inactive for both linear and angular velocity will be put to sleep after the time given. Constant to set/get the threshold angular velocity of activity. A body marked as potentially inactive for both linear and angular velocity will be put to sleep after the time given.
</constant> </constant>
<constant name="SPACE_PARAM_BODY_TIME_TO_SLEEP" value="5" enum="SpaceParameter"> <constant name="SPACE_PARAM_BODY_TIME_TO_SLEEP" value="6" enum="SpaceParameter">
Constant to set/get the maximum time of activity. A body marked as potentially inactive for both linear and angular velocity will be put to sleep after this time. Constant to set/get the maximum time of activity. A body marked as potentially inactive for both linear and angular velocity will be put to sleep after this time.
</constant> </constant>
<constant name="SPACE_PARAM_BODY_ANGULAR_VELOCITY_DAMP_RATIO" value="6" enum="SpaceParameter"> <constant name="SPACE_PARAM_BODY_ANGULAR_VELOCITY_DAMP_RATIO" value="7" enum="SpaceParameter">
</constant> </constant>
<constant name="SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS" value="7" enum="SpaceParameter"> <constant name="SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS" value="8" enum="SpaceParameter">
Constant to set/get the default solver bias for all physics constraints. A solver bias is a factor controlling how much two objects "rebound", after violating a constraint, to avoid leaving them in that state because of numerical imprecision. Constant to set/get the default solver bias for all physics constraints. A solver bias is a factor controlling how much two objects "rebound", after violating a constraint, to avoid leaving them in that state because of numerical imprecision.
</constant> </constant>
<constant name="SPACE_PARAM_SOLVER_ITERATIONS" value="9" enum="SpaceParameter">
Constant to set/get the number of solver iterations for contacts and constraints. The greater the amount of iterations, the more accurate the collisions and constraints will be. However, a greater amount of iterations requires more CPU power, which can decrease performance.
</constant>
<constant name="BODY_AXIS_LINEAR_X" value="1" enum="BodyAxis"> <constant name="BODY_AXIS_LINEAR_X" value="1" enum="BodyAxis">
</constant> </constant>
<constant name="BODY_AXIS_LINEAR_Y" value="2" enum="BodyAxis"> <constant name="BODY_AXIS_LINEAR_Y" value="2" enum="BodyAxis">

View File

@ -341,7 +341,7 @@ bool GodotBodyPair2D::pre_solve(real_t p_step) {
real_t max_penetration = space->get_contact_max_allowed_penetration(); real_t max_penetration = space->get_contact_max_allowed_penetration();
real_t bias = 0.8; real_t bias = space->get_contact_bias();
GodotShape2D *shape_A_ptr = A->get_shape(shape_A); GodotShape2D *shape_A_ptr = A->get_shape(shape_A);
GodotShape2D *shape_B_ptr = B->get_shape(shape_B); GodotShape2D *shape_B_ptr = B->get_shape(shape_B);

View File

@ -1214,21 +1214,16 @@ void GodotPhysicsServer2D::free(RID p_rid) {
} else { } else {
ERR_FAIL_MSG("Invalid ID."); ERR_FAIL_MSG("Invalid ID.");
} }
}; }
void GodotPhysicsServer2D::set_active(bool p_active) { void GodotPhysicsServer2D::set_active(bool p_active) {
active = p_active; active = p_active;
}; }
void GodotPhysicsServer2D::set_collision_iterations(int p_iterations) {
iterations = p_iterations;
};
void GodotPhysicsServer2D::init() { void GodotPhysicsServer2D::init() {
doing_sync = false; doing_sync = false;
iterations = 16;
stepper = memnew(GodotStep2D); stepper = memnew(GodotStep2D);
}; }
void GodotPhysicsServer2D::step(real_t p_step) { void GodotPhysicsServer2D::step(real_t p_step) {
if (!active) { if (!active) {
@ -1241,16 +1236,16 @@ void GodotPhysicsServer2D::step(real_t p_step) {
active_objects = 0; active_objects = 0;
collision_pairs = 0; collision_pairs = 0;
for (Set<const GodotSpace2D *>::Element *E = active_spaces.front(); E; E = E->next()) { for (Set<const GodotSpace2D *>::Element *E = active_spaces.front(); E; E = E->next()) {
stepper->step((GodotSpace2D *)E->get(), p_step, iterations); stepper->step((GodotSpace2D *)E->get(), p_step);
island_count += E->get()->get_island_count(); island_count += E->get()->get_island_count();
active_objects += E->get()->get_active_objects(); active_objects += E->get()->get_active_objects();
collision_pairs += E->get()->get_collision_pairs(); collision_pairs += E->get()->get_collision_pairs();
} }
}; }
void GodotPhysicsServer2D::sync() { void GodotPhysicsServer2D::sync() {
doing_sync = true; doing_sync = true;
}; }
void GodotPhysicsServer2D::flush_queries() { void GodotPhysicsServer2D::flush_queries() {
if (!active) { if (!active) {
@ -1308,7 +1303,7 @@ void GodotPhysicsServer2D::end_sync() {
void GodotPhysicsServer2D::finish() { void GodotPhysicsServer2D::finish() {
memdelete(stepper); memdelete(stepper);
}; }
void GodotPhysicsServer2D::_update_shapes() { void GodotPhysicsServer2D::_update_shapes() {
while (pending_shape_update_list.first()) { while (pending_shape_update_list.first()) {
@ -1340,4 +1335,4 @@ GodotPhysicsServer2D::GodotPhysicsServer2D(bool p_using_threads) {
GodotBroadPhase2D::create_func = GodotBroadPhase2DBVH::_create; GodotBroadPhase2D::create_func = GodotBroadPhase2DBVH::_create;
using_threads = p_using_threads; using_threads = p_using_threads;
}; }

View File

@ -45,7 +45,6 @@ class GodotPhysicsServer2D : public PhysicsServer2D {
friend class GodotPhysicsDirectSpaceState2D; friend class GodotPhysicsDirectSpaceState2D;
friend class GodotPhysicsDirectBodyState2D; friend class GodotPhysicsDirectBodyState2D;
bool active = true; bool active = true;
int iterations = 0;
bool doing_sync = false; bool doing_sync = false;
int island_count = 0; int island_count = 0;
@ -283,8 +282,6 @@ public:
virtual void end_sync() override; virtual void end_sync() override;
virtual void finish() override; virtual void finish() override;
virtual void set_collision_iterations(int p_iterations) override;
virtual bool is_flushing_queries() const override { return flushing_queries; } virtual bool is_flushing_queries() const override { return flushing_queries; }
int get_process_info(ProcessInfo p_info) override; int get_process_info(ProcessInfo p_info) override;

View File

@ -1138,9 +1138,12 @@ void GodotSpace2D::set_param(PhysicsServer2D::SpaceParameter p_param, real_t p_v
case PhysicsServer2D::SPACE_PARAM_CONTACT_MAX_SEPARATION: case PhysicsServer2D::SPACE_PARAM_CONTACT_MAX_SEPARATION:
contact_max_separation = p_value; contact_max_separation = p_value;
break; break;
case PhysicsServer2D::SPACE_PARAM_BODY_MAX_ALLOWED_PENETRATION: case PhysicsServer2D::SPACE_PARAM_CONTACT_MAX_ALLOWED_PENETRATION:
contact_max_allowed_penetration = p_value; contact_max_allowed_penetration = p_value;
break; break;
case PhysicsServer2D::SPACE_PARAM_CONTACT_DEFAULT_BIAS:
contact_bias = p_value;
break;
case PhysicsServer2D::SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD: case PhysicsServer2D::SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD:
body_linear_velocity_sleep_threshold = p_value; body_linear_velocity_sleep_threshold = p_value;
break; break;
@ -1153,6 +1156,9 @@ void GodotSpace2D::set_param(PhysicsServer2D::SpaceParameter p_param, real_t p_v
case PhysicsServer2D::SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS: case PhysicsServer2D::SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS:
constraint_bias = p_value; constraint_bias = p_value;
break; break;
case PhysicsServer2D::SPACE_PARAM_SOLVER_ITERATIONS:
solver_iterations = p_value;
break;
} }
} }
@ -1162,8 +1168,10 @@ real_t GodotSpace2D::get_param(PhysicsServer2D::SpaceParameter p_param) const {
return contact_recycle_radius; return contact_recycle_radius;
case PhysicsServer2D::SPACE_PARAM_CONTACT_MAX_SEPARATION: case PhysicsServer2D::SPACE_PARAM_CONTACT_MAX_SEPARATION:
return contact_max_separation; return contact_max_separation;
case PhysicsServer2D::SPACE_PARAM_BODY_MAX_ALLOWED_PENETRATION: case PhysicsServer2D::SPACE_PARAM_CONTACT_MAX_ALLOWED_PENETRATION:
return contact_max_allowed_penetration; return contact_max_allowed_penetration;
case PhysicsServer2D::SPACE_PARAM_CONTACT_DEFAULT_BIAS:
return contact_bias;
case PhysicsServer2D::SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD: case PhysicsServer2D::SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD:
return body_linear_velocity_sleep_threshold; return body_linear_velocity_sleep_threshold;
case PhysicsServer2D::SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD: case PhysicsServer2D::SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD:
@ -1172,6 +1180,8 @@ real_t GodotSpace2D::get_param(PhysicsServer2D::SpaceParameter p_param) const {
return body_time_to_sleep; return body_time_to_sleep;
case PhysicsServer2D::SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS: case PhysicsServer2D::SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS:
return constraint_bias; return constraint_bias;
case PhysicsServer2D::SPACE_PARAM_SOLVER_ITERATIONS:
return solver_iterations;
} }
return 0; return 0;
} }

View File

@ -96,9 +96,12 @@ private:
GodotArea2D *area = nullptr; GodotArea2D *area = nullptr;
int solver_iterations = 16;
real_t contact_recycle_radius = 1.0; real_t contact_recycle_radius = 1.0;
real_t contact_max_separation = 1.5; real_t contact_max_separation = 1.5;
real_t contact_max_allowed_penetration = 0.3; real_t contact_max_allowed_penetration = 0.3;
real_t contact_bias = 0.8;
real_t constraint_bias = 0.2; real_t constraint_bias = 0.2;
enum { enum {
@ -155,9 +158,11 @@ public:
void remove_object(GodotCollisionObject2D *p_object); void remove_object(GodotCollisionObject2D *p_object);
const Set<GodotCollisionObject2D *> &get_objects() const; const Set<GodotCollisionObject2D *> &get_objects() const;
_FORCE_INLINE_ int get_solver_iterations() const { return solver_iterations; }
_FORCE_INLINE_ real_t get_contact_recycle_radius() const { return contact_recycle_radius; } _FORCE_INLINE_ real_t get_contact_recycle_radius() const { return contact_recycle_radius; }
_FORCE_INLINE_ real_t get_contact_max_separation() const { return contact_max_separation; } _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_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_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_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_angular_velocity_sleep_threshold() const { return body_angular_velocity_sleep_threshold; }

View File

@ -124,14 +124,14 @@ void GodotStep2D::_check_suspend(LocalVector<GodotBody2D *> &p_body_island) cons
} }
} }
void GodotStep2D::step(GodotSpace2D *p_space, real_t p_delta, int p_iterations) { void GodotStep2D::step(GodotSpace2D *p_space, real_t p_delta) {
p_space->lock(); // can't access space during this p_space->lock(); // can't access space during this
p_space->setup(); //update inertias, etc p_space->setup(); //update inertias, etc
p_space->set_last_step(p_delta); p_space->set_last_step(p_delta);
iterations = p_iterations; iterations = p_space->get_solver_iterations();
delta = p_delta; delta = p_delta;
const SelfList<GodotBody2D>::List *body_list = &p_space->get_active_body_list(); const SelfList<GodotBody2D>::List *body_list = &p_space->get_active_body_list();

View File

@ -55,7 +55,7 @@ class GodotStep2D {
void _check_suspend(LocalVector<GodotBody2D *> &p_body_island) const; void _check_suspend(LocalVector<GodotBody2D *> &p_body_island) const;
public: public:
void step(GodotSpace2D *p_space, real_t p_delta, int p_iterations); void step(GodotSpace2D *p_space, real_t p_delta);
GodotStep2D(); GodotStep2D();
~GodotStep2D(); ~GodotStep2D();
}; };

View File

@ -658,7 +658,7 @@ bool GodotBodySoftBodyPair3D::pre_solve(real_t p_step) {
real_t max_penetration = space->get_contact_max_allowed_penetration(); real_t max_penetration = space->get_contact_max_allowed_penetration();
real_t bias = 0.8; real_t bias = space->get_contact_bias();
GodotShape3D *shape_A_ptr = body->get_shape(body_shape); GodotShape3D *shape_A_ptr = body->get_shape(body_shape);

View File

@ -1574,20 +1574,15 @@ void GodotPhysicsServer3D::free(RID p_rid) {
} else { } else {
ERR_FAIL_MSG("Invalid ID."); ERR_FAIL_MSG("Invalid ID.");
} }
}; }
void GodotPhysicsServer3D::set_active(bool p_active) { void GodotPhysicsServer3D::set_active(bool p_active) {
active = p_active; active = p_active;
}; }
void GodotPhysicsServer3D::set_collision_iterations(int p_iterations) {
iterations = p_iterations;
};
void GodotPhysicsServer3D::init() { void GodotPhysicsServer3D::init() {
iterations = 16;
stepper = memnew(GodotStep3D); stepper = memnew(GodotStep3D);
}; }
void GodotPhysicsServer3D::step(real_t p_step) { void GodotPhysicsServer3D::step(real_t p_step) {
#ifndef _3D_DISABLED #ifndef _3D_DISABLED
@ -1602,7 +1597,7 @@ void GodotPhysicsServer3D::step(real_t p_step) {
active_objects = 0; active_objects = 0;
collision_pairs = 0; collision_pairs = 0;
for (Set<const GodotSpace3D *>::Element *E = active_spaces.front(); E; E = E->next()) { for (Set<const GodotSpace3D *>::Element *E = active_spaces.front(); E; E = E->next()) {
stepper->step((GodotSpace3D *)E->get(), p_step, iterations); stepper->step((GodotSpace3D *)E->get(), p_step);
island_count += E->get()->get_island_count(); island_count += E->get()->get_island_count();
active_objects += E->get()->get_active_objects(); active_objects += E->get()->get_active_objects();
collision_pairs += E->get()->get_collision_pairs(); collision_pairs += E->get()->get_collision_pairs();
@ -1612,7 +1607,7 @@ void GodotPhysicsServer3D::step(real_t p_step) {
void GodotPhysicsServer3D::sync() { void GodotPhysicsServer3D::sync() {
doing_sync = true; doing_sync = true;
}; }
void GodotPhysicsServer3D::flush_queries() { void GodotPhysicsServer3D::flush_queries() {
#ifndef _3D_DISABLED #ifndef _3D_DISABLED
@ -1665,15 +1660,15 @@ void GodotPhysicsServer3D::flush_queries() {
EngineDebugger::profiler_add_frame_data("servers", values); EngineDebugger::profiler_add_frame_data("servers", values);
} }
#endif #endif
}; }
void GodotPhysicsServer3D::end_sync() { void GodotPhysicsServer3D::end_sync() {
doing_sync = false; doing_sync = false;
}; }
void GodotPhysicsServer3D::finish() { void GodotPhysicsServer3D::finish() {
memdelete(stepper); memdelete(stepper);
}; }
int GodotPhysicsServer3D::get_process_info(ProcessInfo p_info) { int GodotPhysicsServer3D::get_process_info(ProcessInfo p_info) {
switch (p_info) { switch (p_info) {

View File

@ -44,7 +44,6 @@ class GodotPhysicsServer3D : public PhysicsServer3D {
friend class GodotPhysicsDirectSpaceState3D; friend class GodotPhysicsDirectSpaceState3D;
bool active = true; bool active = true;
int iterations = 0;
int island_count = 0; int island_count = 0;
int active_objects = 0; int active_objects = 0;
@ -364,8 +363,6 @@ public:
virtual void end_sync() override; virtual void end_sync() override;
virtual void finish() override; virtual void finish() override;
virtual void set_collision_iterations(int p_iterations) override;
virtual bool is_flushing_queries() const override { return flushing_queries; } virtual bool is_flushing_queries() const override { return flushing_queries; }
int get_process_info(ProcessInfo p_info) override; int get_process_info(ProcessInfo p_info) override;

View File

@ -1173,9 +1173,12 @@ void GodotSpace3D::set_param(PhysicsServer3D::SpaceParameter p_param, real_t p_v
case PhysicsServer3D::SPACE_PARAM_CONTACT_MAX_SEPARATION: case PhysicsServer3D::SPACE_PARAM_CONTACT_MAX_SEPARATION:
contact_max_separation = p_value; contact_max_separation = p_value;
break; break;
case PhysicsServer3D::SPACE_PARAM_BODY_MAX_ALLOWED_PENETRATION: case PhysicsServer3D::SPACE_PARAM_CONTACT_MAX_ALLOWED_PENETRATION:
contact_max_allowed_penetration = p_value; contact_max_allowed_penetration = p_value;
break; break;
case PhysicsServer3D::SPACE_PARAM_CONTACT_DEFAULT_BIAS:
contact_bias = p_value;
break;
case PhysicsServer3D::SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD: case PhysicsServer3D::SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD:
body_linear_velocity_sleep_threshold = p_value; body_linear_velocity_sleep_threshold = p_value;
break; break;
@ -1191,6 +1194,9 @@ void GodotSpace3D::set_param(PhysicsServer3D::SpaceParameter p_param, real_t p_v
case PhysicsServer3D::SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS: case PhysicsServer3D::SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS:
constraint_bias = p_value; constraint_bias = p_value;
break; break;
case PhysicsServer3D::SPACE_PARAM_SOLVER_ITERATIONS:
solver_iterations = p_value;
break;
} }
} }
@ -1200,8 +1206,10 @@ real_t GodotSpace3D::get_param(PhysicsServer3D::SpaceParameter p_param) const {
return contact_recycle_radius; return contact_recycle_radius;
case PhysicsServer3D::SPACE_PARAM_CONTACT_MAX_SEPARATION: case PhysicsServer3D::SPACE_PARAM_CONTACT_MAX_SEPARATION:
return contact_max_separation; return contact_max_separation;
case PhysicsServer3D::SPACE_PARAM_BODY_MAX_ALLOWED_PENETRATION: case PhysicsServer3D::SPACE_PARAM_CONTACT_MAX_ALLOWED_PENETRATION:
return contact_max_allowed_penetration; return contact_max_allowed_penetration;
case PhysicsServer3D::SPACE_PARAM_CONTACT_DEFAULT_BIAS:
return contact_bias;
case PhysicsServer3D::SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD: case PhysicsServer3D::SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD:
return body_linear_velocity_sleep_threshold; return body_linear_velocity_sleep_threshold;
case PhysicsServer3D::SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD: case PhysicsServer3D::SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD:
@ -1212,6 +1220,8 @@ real_t GodotSpace3D::get_param(PhysicsServer3D::SpaceParameter p_param) const {
return body_angular_velocity_damp_ratio; return body_angular_velocity_damp_ratio;
case PhysicsServer3D::SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS: case PhysicsServer3D::SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS:
return constraint_bias; return constraint_bias;
case PhysicsServer3D::SPACE_PARAM_SOLVER_ITERATIONS:
return solver_iterations;
} }
return 0; return 0;
} }

View File

@ -93,9 +93,12 @@ private:
GodotArea3D *area = nullptr; GodotArea3D *area = nullptr;
int solver_iterations = 16;
real_t contact_recycle_radius = 0.01; real_t contact_recycle_radius = 0.01;
real_t contact_max_separation = 0.05; real_t contact_max_separation = 0.05;
real_t contact_max_allowed_penetration = 0.01; real_t contact_max_allowed_penetration = 0.01;
real_t contact_bias = 0.8;
real_t constraint_bias = 0.01; real_t constraint_bias = 0.01;
enum { enum {
@ -159,9 +162,11 @@ public:
void remove_object(GodotCollisionObject3D *p_object); void remove_object(GodotCollisionObject3D *p_object);
const Set<GodotCollisionObject3D *> &get_objects() const; const Set<GodotCollisionObject3D *> &get_objects() const;
_FORCE_INLINE_ int get_solver_iterations() const { return solver_iterations; }
_FORCE_INLINE_ real_t get_contact_recycle_radius() const { return contact_recycle_radius; } _FORCE_INLINE_ real_t get_contact_recycle_radius() const { return contact_recycle_radius; }
_FORCE_INLINE_ real_t get_contact_max_separation() const { return contact_max_separation; } _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_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_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_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_angular_velocity_sleep_threshold() const { return body_angular_velocity_sleep_threshold; }

View File

@ -181,14 +181,14 @@ void GodotStep3D::_check_suspend(const LocalVector<GodotBody3D *> &p_body_island
} }
} }
void GodotStep3D::step(GodotSpace3D *p_space, real_t p_delta, int p_iterations) { void GodotStep3D::step(GodotSpace3D *p_space, real_t p_delta) {
p_space->lock(); // can't access space during this p_space->lock(); // can't access space during this
p_space->setup(); //update inertias, etc p_space->setup(); //update inertias, etc
p_space->set_last_step(p_delta); p_space->set_last_step(p_delta);
iterations = p_iterations; iterations = p_space->get_solver_iterations();
delta = p_delta; delta = p_delta;
const SelfList<GodotBody3D>::List *body_list = &p_space->get_active_body_list(); const SelfList<GodotBody3D>::List *body_list = &p_space->get_active_body_list();

View File

@ -56,7 +56,7 @@ class GodotStep3D {
void _check_suspend(const LocalVector<GodotBody3D *> &p_body_island) const; void _check_suspend(const LocalVector<GodotBody3D *> &p_body_island) const;
public: public:
void step(GodotSpace3D *p_space, real_t p_delta, int p_iterations); void step(GodotSpace3D *p_space, real_t p_delta);
GodotStep3D(); GodotStep3D();
~GodotStep3D(); ~GodotStep3D();
}; };

View File

@ -730,17 +730,17 @@ void PhysicsServer2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_active", "active"), &PhysicsServer2D::set_active); ClassDB::bind_method(D_METHOD("set_active", "active"), &PhysicsServer2D::set_active);
ClassDB::bind_method(D_METHOD("set_collision_iterations", "iterations"), &PhysicsServer2D::set_collision_iterations);
ClassDB::bind_method(D_METHOD("get_process_info", "process_info"), &PhysicsServer2D::get_process_info); ClassDB::bind_method(D_METHOD("get_process_info", "process_info"), &PhysicsServer2D::get_process_info);
BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_RECYCLE_RADIUS); BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_RECYCLE_RADIUS);
BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_MAX_SEPARATION); BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_MAX_SEPARATION);
BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_MAX_ALLOWED_PENETRATION); BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_MAX_ALLOWED_PENETRATION);
BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_DEFAULT_BIAS);
BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD); 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_ANGULAR_VELOCITY_SLEEP_THRESHOLD);
BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_TIME_TO_SLEEP); BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_TIME_TO_SLEEP);
BIND_ENUM_CONSTANT(SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS); BIND_ENUM_CONSTANT(SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS);
BIND_ENUM_CONSTANT(SPACE_PARAM_SOLVER_ITERATIONS);
BIND_ENUM_CONSTANT(SHAPE_WORLD_BOUNDARY); BIND_ENUM_CONSTANT(SHAPE_WORLD_BOUNDARY);
BIND_ENUM_CONSTANT(SHAPE_SEPARATION_RAY); BIND_ENUM_CONSTANT(SHAPE_SEPARATION_RAY);

View File

@ -242,11 +242,13 @@ public:
enum SpaceParameter { enum SpaceParameter {
SPACE_PARAM_CONTACT_RECYCLE_RADIUS, SPACE_PARAM_CONTACT_RECYCLE_RADIUS,
SPACE_PARAM_CONTACT_MAX_SEPARATION, SPACE_PARAM_CONTACT_MAX_SEPARATION,
SPACE_PARAM_BODY_MAX_ALLOWED_PENETRATION, SPACE_PARAM_CONTACT_MAX_ALLOWED_PENETRATION,
SPACE_PARAM_CONTACT_DEFAULT_BIAS,
SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD, SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD,
SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD, SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD,
SPACE_PARAM_BODY_TIME_TO_SLEEP, SPACE_PARAM_BODY_TIME_TO_SLEEP,
SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS, SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS,
SPACE_PARAM_SOLVER_ITERATIONS,
}; };
virtual void space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) = 0; virtual void space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) = 0;
@ -566,8 +568,6 @@ public:
virtual bool is_flushing_queries() const = 0; virtual bool is_flushing_queries() const = 0;
virtual void set_collision_iterations(int p_iterations) = 0;
enum ProcessInfo { enum ProcessInfo {
INFO_ACTIVE_OBJECTS, INFO_ACTIVE_OBJECTS,
INFO_COLLISION_PAIRS, INFO_COLLISION_PAIRS,

View File

@ -294,7 +294,6 @@ public:
FUNC1(free, RID); FUNC1(free, RID);
FUNC1(set_active, bool); FUNC1(set_active, bool);
FUNC1(set_collision_iterations, int);
virtual void init() override; virtual void init() override;
virtual void step(real_t p_step) override; virtual void step(real_t p_step) override;

View File

@ -890,8 +890,6 @@ void PhysicsServer3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_active", "active"), &PhysicsServer3D::set_active); 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); ClassDB::bind_method(D_METHOD("get_process_info", "process_info"), &PhysicsServer3D::get_process_info);
BIND_ENUM_CONSTANT(SHAPE_WORLD_BOUNDARY); BIND_ENUM_CONSTANT(SHAPE_WORLD_BOUNDARY);
@ -963,12 +961,14 @@ void PhysicsServer3D::_bind_methods() {
BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_RECYCLE_RADIUS); BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_RECYCLE_RADIUS);
BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_MAX_SEPARATION); BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_MAX_SEPARATION);
BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_MAX_ALLOWED_PENETRATION); BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_MAX_ALLOWED_PENETRATION);
BIND_ENUM_CONSTANT(SPACE_PARAM_CONTACT_DEFAULT_BIAS);
BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD); 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_ANGULAR_VELOCITY_SLEEP_THRESHOLD);
BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_TIME_TO_SLEEP); BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_TIME_TO_SLEEP);
BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_ANGULAR_VELOCITY_DAMP_RATIO); BIND_ENUM_CONSTANT(SPACE_PARAM_BODY_ANGULAR_VELOCITY_DAMP_RATIO);
BIND_ENUM_CONSTANT(SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS); BIND_ENUM_CONSTANT(SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS);
BIND_ENUM_CONSTANT(SPACE_PARAM_SOLVER_ITERATIONS);
BIND_ENUM_CONSTANT(BODY_AXIS_LINEAR_X); BIND_ENUM_CONSTANT(BODY_AXIS_LINEAR_X);
BIND_ENUM_CONSTANT(BODY_AXIS_LINEAR_Y); BIND_ENUM_CONSTANT(BODY_AXIS_LINEAR_Y);

View File

@ -263,12 +263,14 @@ public:
enum SpaceParameter { enum SpaceParameter {
SPACE_PARAM_CONTACT_RECYCLE_RADIUS, SPACE_PARAM_CONTACT_RECYCLE_RADIUS,
SPACE_PARAM_CONTACT_MAX_SEPARATION, SPACE_PARAM_CONTACT_MAX_SEPARATION,
SPACE_PARAM_BODY_MAX_ALLOWED_PENETRATION, SPACE_PARAM_CONTACT_MAX_ALLOWED_PENETRATION,
SPACE_PARAM_CONTACT_DEFAULT_BIAS,
SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD, SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD,
SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD, SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD,
SPACE_PARAM_BODY_TIME_TO_SLEEP, SPACE_PARAM_BODY_TIME_TO_SLEEP,
SPACE_PARAM_BODY_ANGULAR_VELOCITY_DAMP_RATIO, SPACE_PARAM_BODY_ANGULAR_VELOCITY_DAMP_RATIO,
SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS, SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS,
SPACE_PARAM_SOLVER_ITERATIONS,
}; };
virtual void space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) = 0; virtual void space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) = 0;
@ -768,8 +770,6 @@ public:
virtual bool is_flushing_queries() const = 0; virtual bool is_flushing_queries() const = 0;
virtual void set_collision_iterations(int p_iterations) = 0;
enum ProcessInfo { enum ProcessInfo {
INFO_ACTIVE_OBJECTS, INFO_ACTIVE_OBJECTS,
INFO_COLLISION_PAIRS, INFO_COLLISION_PAIRS,

View File

@ -370,7 +370,6 @@ public:
FUNC1(free, RID); FUNC1(free, RID);
FUNC1(set_active, bool); FUNC1(set_active, bool);
FUNC1(set_collision_iterations, int);
virtual void init() override; virtual void init() override;
virtual void step(real_t p_step) override; virtual void step(real_t p_step) override;