Merge pull request #88 from EmbarkStudios/refactor-params
Small refactor of IntegrationParameters
This commit is contained in:
@@ -3,9 +3,8 @@
|
|||||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||||
pub struct IntegrationParameters {
|
pub struct IntegrationParameters {
|
||||||
/// The timestep length (default: `1.0 / 60.0`)
|
/// The timestep length (default: `1.0 / 60.0`)
|
||||||
dt: f32,
|
pub dt: f32,
|
||||||
/// The inverse of `dt`.
|
|
||||||
inv_dt: f32,
|
|
||||||
// /// If `true` and if rapier is compiled with the `parallel` feature, this will enable rayon-based multithreading (default: `true`).
|
// /// If `true` and if rapier is compiled with the `parallel` feature, this will enable rayon-based multithreading (default: `true`).
|
||||||
// ///
|
// ///
|
||||||
// /// This parameter is ignored if rapier is not compiled with is `parallel` feature.
|
// /// This parameter is ignored if rapier is not compiled with is `parallel` feature.
|
||||||
@@ -29,7 +28,7 @@ pub struct IntegrationParameters {
|
|||||||
/// Contacts at points where the involved bodies have a relative
|
/// Contacts at points where the involved bodies have a relative
|
||||||
/// velocity smaller than this threshold wont be affected by the restitution force (default: `1.0`).
|
/// velocity smaller than this threshold wont be affected by the restitution force (default: `1.0`).
|
||||||
pub restitution_velocity_threshold: f32,
|
pub restitution_velocity_threshold: f32,
|
||||||
/// Amount of penetration the engine wont attempt to correct (default: `0.001m`).
|
/// Amount of penetration the engine wont attempt to correct (default: `0.005m`).
|
||||||
pub allowed_linear_error: f32,
|
pub allowed_linear_error: f32,
|
||||||
/// The maximal distance separating two objects that will generate predictive contacts (default: `0.002`).
|
/// The maximal distance separating two objects that will generate predictive contacts (default: `0.002`).
|
||||||
pub prediction_distance: f32,
|
pub prediction_distance: f32,
|
||||||
@@ -87,6 +86,7 @@ pub struct IntegrationParameters {
|
|||||||
|
|
||||||
impl IntegrationParameters {
|
impl IntegrationParameters {
|
||||||
/// Creates a set of integration parameters with the given values.
|
/// Creates a set of integration parameters with the given values.
|
||||||
|
#[deprecated = "Use `IntegrationParameters { dt: 60.0, ..Default::default() }` instead"]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
dt: f32,
|
dt: f32,
|
||||||
// multithreading_enabled: bool,
|
// multithreading_enabled: bool,
|
||||||
@@ -110,7 +110,6 @@ impl IntegrationParameters {
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
IntegrationParameters {
|
IntegrationParameters {
|
||||||
dt,
|
dt,
|
||||||
inv_dt: if dt == 0.0 { 0.0 } else { 1.0 / dt },
|
|
||||||
// multithreading_enabled,
|
// multithreading_enabled,
|
||||||
erp,
|
erp,
|
||||||
joint_erp,
|
joint_erp,
|
||||||
@@ -140,30 +139,29 @@ impl IntegrationParameters {
|
|||||||
|
|
||||||
/// The current time-stepping length.
|
/// The current time-stepping length.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
#[deprecated = "You can just read the `IntegrationParams::dt` value directly"]
|
||||||
pub fn dt(&self) -> f32 {
|
pub fn dt(&self) -> f32 {
|
||||||
self.dt
|
self.dt
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The inverse of the time-stepping length.
|
/// The inverse of the time-stepping length, i.e. the steps per seconds (Hz).
|
||||||
///
|
///
|
||||||
/// This is zero if `self.dt` is zero.
|
/// This is zero if `self.dt` is zero.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn inv_dt(&self) -> f32 {
|
pub fn inv_dt(&self) -> f32 {
|
||||||
self.inv_dt
|
if self.dt == 0.0 {
|
||||||
|
0.0
|
||||||
|
} else {
|
||||||
|
1.0 / self.dt
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the time-stepping length.
|
/// Sets the time-stepping length.
|
||||||
///
|
|
||||||
/// This automatically recompute `self.inv_dt`.
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[deprecated = "You can just set the `IntegrationParams::dt` value directly"]
|
||||||
pub fn set_dt(&mut self, dt: f32) {
|
pub fn set_dt(&mut self, dt: f32) {
|
||||||
assert!(dt >= 0.0, "The time-stepping length cannot be negative.");
|
assert!(dt >= 0.0, "The time-stepping length cannot be negative.");
|
||||||
self.dt = dt;
|
self.dt = dt;
|
||||||
if dt == 0.0 {
|
|
||||||
self.inv_dt = 0.0
|
|
||||||
} else {
|
|
||||||
self.inv_dt = 1.0 / dt
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the inverse time-stepping length (i.e. the frequency).
|
/// Sets the inverse time-stepping length (i.e. the frequency).
|
||||||
@@ -171,7 +169,6 @@ impl IntegrationParameters {
|
|||||||
/// This automatically recompute `self.dt`.
|
/// This automatically recompute `self.dt`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_inv_dt(&mut self, inv_dt: f32) {
|
pub fn set_inv_dt(&mut self, inv_dt: f32) {
|
||||||
self.inv_dt = inv_dt;
|
|
||||||
if inv_dt == 0.0 {
|
if inv_dt == 0.0 {
|
||||||
self.dt = 0.0
|
self.dt = 0.0
|
||||||
} else {
|
} else {
|
||||||
@@ -182,26 +179,32 @@ impl IntegrationParameters {
|
|||||||
|
|
||||||
impl Default for IntegrationParameters {
|
impl Default for IntegrationParameters {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new(
|
Self {
|
||||||
1.0 / 60.0,
|
dt: 1.0 / 60.0,
|
||||||
// true,
|
// multithreading_enabled: true,
|
||||||
0.2,
|
return_after_ccd_substep: false,
|
||||||
0.2,
|
erp: 0.2,
|
||||||
1.0,
|
joint_erp: 0.2,
|
||||||
1.0,
|
warmstart_coeff: 1.0,
|
||||||
0.005,
|
restitution_velocity_threshold: 1.0,
|
||||||
0.001,
|
allowed_linear_error: 0.005,
|
||||||
0.2,
|
prediction_distance: 0.002,
|
||||||
0.2,
|
allowed_angular_error: 0.001,
|
||||||
0.002,
|
max_linear_correction: 0.2,
|
||||||
0.2,
|
max_angular_correction: 0.2,
|
||||||
4,
|
max_stabilization_multiplier: 0.2,
|
||||||
1,
|
max_velocity_iterations: 4,
|
||||||
10,
|
max_position_iterations: 1,
|
||||||
1,
|
// FIXME: what is the optimal value for min_island_size?
|
||||||
false,
|
// It should not be too big so that we don't end up with
|
||||||
false,
|
// huge islands that don't fit in cache.
|
||||||
false,
|
// However we don't want it to be too small and end up with
|
||||||
)
|
// tons of islands, reducing SIMD parallelism opportunities.
|
||||||
|
min_island_size: 128,
|
||||||
|
max_ccd_position_iterations: 10,
|
||||||
|
max_ccd_substeps: 1,
|
||||||
|
multiple_ccd_substep_sensor_events_enabled: false,
|
||||||
|
ccd_on_penetration_enabled: false,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,8 +59,7 @@ impl IslandSolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
counters.solver.velocity_update_time.resume();
|
counters.solver.velocity_update_time.resume();
|
||||||
bodies
|
bodies.foreach_active_island_body_mut_internal(island_id, |_, rb| rb.integrate(params.dt));
|
||||||
.foreach_active_island_body_mut_internal(island_id, |_, rb| rb.integrate(params.dt()));
|
|
||||||
counters.solver.velocity_update_time.pause();
|
counters.solver.velocity_update_time.pause();
|
||||||
|
|
||||||
if manifold_indices.len() != 0 || joint_indices.len() != 0 {
|
if manifold_indices.len() != 0 || joint_indices.len() != 0 {
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ impl ParallelIslandSolver {
|
|||||||
let dvel = mj_lambdas[rb.active_set_offset];
|
let dvel = mj_lambdas[rb.active_set_offset];
|
||||||
rb.linvel += dvel.linear;
|
rb.linvel += dvel.linear;
|
||||||
rb.angvel += rb.world_inv_inertia_sqrt.transform_vector(dvel.angular);
|
rb.angvel += rb.world_inv_inertia_sqrt.transform_vector(dvel.angular);
|
||||||
rb.integrate(params.dt());
|
rb.integrate(params.dt);
|
||||||
positions[rb.active_set_offset] = rb.position;
|
positions[rb.active_set_offset] = rb.position;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,6 +144,7 @@ impl VelocityConstraint {
|
|||||||
out_constraints: &mut Vec<AnyVelocityConstraint>,
|
out_constraints: &mut Vec<AnyVelocityConstraint>,
|
||||||
push: bool,
|
push: bool,
|
||||||
) {
|
) {
|
||||||
|
let inv_dt = params.inv_dt();
|
||||||
let rb1 = &bodies[manifold.body_pair.body1];
|
let rb1 = &bodies[manifold.body_pair.body1];
|
||||||
let rb2 = &bodies[manifold.body_pair.body2];
|
let rb2 = &bodies[manifold.body_pair.body2];
|
||||||
let mj_lambda1 = rb1.active_set_offset;
|
let mj_lambda1 = rb1.active_set_offset;
|
||||||
@@ -244,7 +245,7 @@ impl VelocityConstraint {
|
|||||||
rhs += manifold.restitution * rhs
|
rhs += manifold.restitution * rhs
|
||||||
}
|
}
|
||||||
|
|
||||||
rhs += manifold_point.dist.max(0.0) * params.inv_dt();
|
rhs += manifold_point.dist.max(0.0) * inv_dt;
|
||||||
|
|
||||||
let impulse = manifold_points[k].impulse * warmstart_coeff;
|
let impulse = manifold_points[k].impulse * warmstart_coeff;
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ impl VelocityGroundConstraint {
|
|||||||
out_constraints: &mut Vec<AnyVelocityConstraint>,
|
out_constraints: &mut Vec<AnyVelocityConstraint>,
|
||||||
push: bool,
|
push: bool,
|
||||||
) {
|
) {
|
||||||
|
let inv_dt = params.inv_dt();
|
||||||
let mut rb1 = &bodies[manifold.body_pair.body1];
|
let mut rb1 = &bodies[manifold.body_pair.body1];
|
||||||
let mut rb2 = &bodies[manifold.body_pair.body2];
|
let mut rb2 = &bodies[manifold.body_pair.body2];
|
||||||
let flipped = !rb2.is_dynamic();
|
let flipped = !rb2.is_dynamic();
|
||||||
@@ -176,7 +177,7 @@ impl VelocityGroundConstraint {
|
|||||||
rhs += manifold.restitution * rhs
|
rhs += manifold.restitution * rhs
|
||||||
}
|
}
|
||||||
|
|
||||||
rhs += manifold_point.dist.max(0.0) * params.inv_dt();
|
rhs += manifold_point.dist.max(0.0) * inv_dt;
|
||||||
|
|
||||||
let impulse = manifold_points[k].impulse * warmstart_coeff;
|
let impulse = manifold_points[k].impulse * warmstart_coeff;
|
||||||
|
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ impl PhysicsPipeline {
|
|||||||
self.counters.stages.update_time.start();
|
self.counters.stages.update_time.start();
|
||||||
bodies.foreach_active_dynamic_body_mut_internal(|_, b| {
|
bodies.foreach_active_dynamic_body_mut_internal(|_, b| {
|
||||||
b.update_world_mass_properties();
|
b.update_world_mass_properties();
|
||||||
b.integrate_accelerations(integration_parameters.dt(), *gravity)
|
b.integrate_accelerations(integration_parameters.dt, *gravity)
|
||||||
});
|
});
|
||||||
self.counters.stages.update_time.pause();
|
self.counters.stages.update_time.pause();
|
||||||
|
|
||||||
@@ -239,7 +239,7 @@ impl PhysicsPipeline {
|
|||||||
rb.linvel = na::zero();
|
rb.linvel = na::zero();
|
||||||
rb.angvel = na::zero();
|
rb.angvel = na::zero();
|
||||||
} else {
|
} else {
|
||||||
rb.update_predicted_position(integration_parameters.dt());
|
rb.update_predicted_position(integration_parameters.dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
rb.update_colliders_positions(colliders);
|
rb.update_colliders_positions(colliders);
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ impl Box2dWorld {
|
|||||||
|
|
||||||
counters.step_started();
|
counters.step_started();
|
||||||
self.world.step(
|
self.world.step(
|
||||||
params.dt(),
|
params.dt,
|
||||||
params.max_velocity_iterations as i32,
|
params.max_velocity_iterations as i32,
|
||||||
params.max_position_iterations as i32,
|
params.max_position_iterations as i32,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ impl Harness {
|
|||||||
|
|
||||||
self.events.poll_all();
|
self.events.poll_all();
|
||||||
|
|
||||||
self.state.time += self.physics.integration_parameters.dt();
|
self.state.time += self.physics.integration_parameters.dt;
|
||||||
self.state.timestep_id += 1;
|
self.state.timestep_id += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ impl NPhysicsWorld {
|
|||||||
.max_velocity_iterations = params.max_velocity_iterations;
|
.max_velocity_iterations = params.max_velocity_iterations;
|
||||||
self.mechanical_world
|
self.mechanical_world
|
||||||
.integration_parameters
|
.integration_parameters
|
||||||
.set_dt(params.dt());
|
.set_dt(params.dt);
|
||||||
|
|
||||||
counters.step_started();
|
counters.step_started();
|
||||||
self.mechanical_world.step(
|
self.mechanical_world.step(
|
||||||
|
|||||||
@@ -396,7 +396,7 @@ impl PhysxWorld {
|
|||||||
|
|
||||||
pub fn step(&mut self, counters: &mut Counters, params: &IntegrationParameters) {
|
pub fn step(&mut self, counters: &mut Counters, params: &IntegrationParameters) {
|
||||||
counters.step_started();
|
counters.step_started();
|
||||||
self.scene.step(params.dt(), true);
|
self.scene.step(params.dt, true);
|
||||||
counters.step_completed();
|
counters.step_completed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user