#[derive(Clone, Copy, Debug)]
pub struct FracturePolicy {
pub max_fractures_per_frame: i32,
pub max_new_bodies_per_frame: i32,
pub max_dynamic_bodies: i32,
pub max_collider_migrations_per_frame: i32,
pub min_child_node_count: u32,
pub idle_skip: bool,
pub apply_excess_forces: bool,
}
impl Default for FracturePolicy {
fn default() -> Self {
Self {
max_fractures_per_frame: -1,
max_new_bodies_per_frame: -1,
max_dynamic_bodies: -1,
max_collider_migrations_per_frame: -1,
min_child_node_count: 1,
idle_skip: true,
apply_excess_forces: true,
}
}
}
impl FracturePolicy {
pub fn should_suppress(&self, current_dynamic_bodies: usize) -> bool {
if self.max_dynamic_bodies > 0 && current_dynamic_bodies >= self.max_dynamic_bodies as usize
{
return true;
}
false
}
pub fn clamp_fractures(&self, count: usize) -> usize {
if self.max_fractures_per_frame < 0 {
count
} else {
count.min(self.max_fractures_per_frame as usize)
}
}
pub fn clamp_new_bodies(&self, count: usize) -> usize {
if self.max_new_bodies_per_frame < 0 {
count
} else {
count.min(self.max_new_bodies_per_frame as usize)
}
}
pub fn clamp_collider_migrations(&self, count: usize) -> usize {
if self.max_collider_migrations_per_frame < 0 {
count
} else {
count.min(self.max_collider_migrations_per_frame as usize)
}
}
pub fn split_budgets_unlimited(&self) -> bool {
self.max_new_bodies_per_frame < 0 && self.max_collider_migrations_per_frame < 0
}
pub fn child_qualifies(&self, node_count: u32) -> bool {
node_count >= self.min_child_node_count
}
}