You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-29 16:16:38 +00:00
Refactor Jolt-related project settings to only be loaded as needed
This commit is contained in:
@@ -104,23 +104,23 @@ JoltSpace3D::JoltSpace3D(JPH::JobSystem *p_job_system) :
|
||||
layers(new JoltLayers()),
|
||||
contact_listener(new JoltContactListener3D(this)),
|
||||
physics_system(new JPH::PhysicsSystem()) {
|
||||
physics_system->Init((JPH::uint)JoltProjectSettings::get_max_bodies(), 0, (JPH::uint)JoltProjectSettings::get_max_pairs(), (JPH::uint)JoltProjectSettings::get_max_contact_constraints(), *layers, *layers, *layers);
|
||||
physics_system->Init((JPH::uint)JoltProjectSettings::max_bodies, 0, (JPH::uint)JoltProjectSettings::max_body_pairs, (JPH::uint)JoltProjectSettings::max_contact_constraints, *layers, *layers, *layers);
|
||||
|
||||
JPH::PhysicsSettings settings;
|
||||
settings.mBaumgarte = JoltProjectSettings::get_baumgarte_stabilization_factor();
|
||||
settings.mSpeculativeContactDistance = JoltProjectSettings::get_speculative_contact_distance();
|
||||
settings.mPenetrationSlop = JoltProjectSettings::get_penetration_slop();
|
||||
settings.mLinearCastThreshold = JoltProjectSettings::get_ccd_movement_threshold();
|
||||
settings.mLinearCastMaxPenetration = JoltProjectSettings::get_ccd_max_penetration();
|
||||
settings.mBodyPairCacheMaxDeltaPositionSq = JoltProjectSettings::get_body_pair_cache_distance_sq();
|
||||
settings.mBodyPairCacheCosMaxDeltaRotationDiv2 = JoltProjectSettings::get_body_pair_cache_angle_cos_div2();
|
||||
settings.mNumVelocitySteps = (JPH::uint)JoltProjectSettings::get_simulation_velocity_steps();
|
||||
settings.mNumPositionSteps = (JPH::uint)JoltProjectSettings::get_simulation_position_steps();
|
||||
settings.mMinVelocityForRestitution = JoltProjectSettings::get_bounce_velocity_threshold();
|
||||
settings.mTimeBeforeSleep = JoltProjectSettings::get_sleep_time_threshold();
|
||||
settings.mPointVelocitySleepThreshold = JoltProjectSettings::get_sleep_velocity_threshold();
|
||||
settings.mUseBodyPairContactCache = JoltProjectSettings::is_body_pair_contact_cache_enabled();
|
||||
settings.mAllowSleeping = JoltProjectSettings::is_sleep_allowed();
|
||||
settings.mBaumgarte = JoltProjectSettings::baumgarte_stabilization_factor;
|
||||
settings.mSpeculativeContactDistance = JoltProjectSettings::speculative_contact_distance;
|
||||
settings.mPenetrationSlop = JoltProjectSettings::penetration_slop;
|
||||
settings.mLinearCastThreshold = JoltProjectSettings::ccd_movement_threshold;
|
||||
settings.mLinearCastMaxPenetration = JoltProjectSettings::ccd_max_penetration;
|
||||
settings.mBodyPairCacheMaxDeltaPositionSq = JoltProjectSettings::body_pair_cache_distance_sq;
|
||||
settings.mBodyPairCacheCosMaxDeltaRotationDiv2 = JoltProjectSettings::body_pair_cache_angle_cos_div2;
|
||||
settings.mNumVelocitySteps = (JPH::uint)JoltProjectSettings::simulation_velocity_steps;
|
||||
settings.mNumPositionSteps = (JPH::uint)JoltProjectSettings::simulation_position_steps;
|
||||
settings.mMinVelocityForRestitution = JoltProjectSettings::bounce_velocity_threshold;
|
||||
settings.mTimeBeforeSleep = JoltProjectSettings::sleep_time_threshold;
|
||||
settings.mPointVelocitySleepThreshold = JoltProjectSettings::sleep_velocity_threshold;
|
||||
settings.mUseBodyPairContactCache = JoltProjectSettings::body_pair_contact_cache_enabled;
|
||||
settings.mAllowSleeping = JoltProjectSettings::sleep_allowed;
|
||||
|
||||
physics_system->SetPhysicsSettings(settings);
|
||||
physics_system->SetGravity(JPH::Vec3::sZero());
|
||||
@@ -175,21 +175,21 @@ void JoltSpace3D::step(float p_step) {
|
||||
WARN_PRINT_ONCE(vformat("Jolt Physics manifold cache exceeded capacity and contacts were ignored. "
|
||||
"Consider increasing maximum number of contact constraints in project settings. "
|
||||
"Maximum number of contact constraints is currently set to %d.",
|
||||
JoltProjectSettings::get_max_contact_constraints()));
|
||||
JoltProjectSettings::max_contact_constraints));
|
||||
}
|
||||
|
||||
if ((update_error & JPH::EPhysicsUpdateError::BodyPairCacheFull) != JPH::EPhysicsUpdateError::None) {
|
||||
WARN_PRINT_ONCE(vformat("Jolt Physics body pair cache exceeded capacity and contacts were ignored. "
|
||||
"Consider increasing maximum number of body pairs in project settings. "
|
||||
"Maximum number of body pairs is currently set to %d.",
|
||||
JoltProjectSettings::get_max_pairs()));
|
||||
JoltProjectSettings::max_body_pairs));
|
||||
}
|
||||
|
||||
if ((update_error & JPH::EPhysicsUpdateError::ContactConstraintsFull) != JPH::EPhysicsUpdateError::None) {
|
||||
WARN_PRINT_ONCE(vformat("Jolt Physics contact constraint buffer exceeded capacity and contacts were ignored. "
|
||||
"Consider increasing maximum number of contact constraints in project settings. "
|
||||
"Maximum number of contact constraints is currently set to %d.",
|
||||
JoltProjectSettings::get_max_contact_constraints()));
|
||||
JoltProjectSettings::max_contact_constraints));
|
||||
}
|
||||
|
||||
_post_step(p_step);
|
||||
@@ -233,7 +233,7 @@ double JoltSpace3D::get_param(PhysicsServer3D::SpaceParameter p_param) const {
|
||||
return DEFAULT_SLEEP_THRESHOLD_ANGULAR;
|
||||
}
|
||||
case PhysicsServer3D::SPACE_PARAM_BODY_TIME_TO_SLEEP: {
|
||||
return JoltProjectSettings::get_sleep_time_threshold();
|
||||
return JoltProjectSettings::sleep_time_threshold;
|
||||
}
|
||||
case PhysicsServer3D::SPACE_PARAM_SOLVER_ITERATIONS: {
|
||||
return DEFAULT_SOLVER_ITERATIONS;
|
||||
@@ -359,7 +359,7 @@ JPH::BodyID JoltSpace3D::add_rigid_body(const JoltObject3D &p_object, const JPH:
|
||||
ERR_PRINT_ONCE(vformat("Failed to create underlying Jolt Physics body for '%s'. "
|
||||
"Consider increasing maximum number of bodies in project settings. "
|
||||
"Maximum number of bodies is currently set to %d.",
|
||||
p_object.to_string(), JoltProjectSettings::get_max_bodies()));
|
||||
p_object.to_string(), JoltProjectSettings::max_bodies));
|
||||
|
||||
return JPH::BodyID();
|
||||
}
|
||||
@@ -376,7 +376,7 @@ JPH::BodyID JoltSpace3D::add_soft_body(const JoltObject3D &p_object, const JPH::
|
||||
ERR_PRINT_ONCE(vformat("Failed to create underlying Jolt Physics body for '%s'. "
|
||||
"Consider increasing maximum number of bodies in project settings. "
|
||||
"Maximum number of bodies is currently set to %d.",
|
||||
p_object.to_string(), JoltProjectSettings::get_max_bodies()));
|
||||
p_object.to_string(), JoltProjectSettings::max_bodies));
|
||||
|
||||
return JPH::BodyID();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user