use crate::engines::soa::phys_obj::{AttrsError, PhysObj};
pub const ATTR_R: &str = "r";
pub const ATTR_V: &str = "v";
pub const ATTR_A: &str = "a";
pub const ATTR_M: &str = "m";
pub const ATTR_M_INV: &str = "m_inv";
pub const ATTR_ALIVE: &str = "alive";
pub const ATTR_RIGID: &str = "rigid";
pub const ALIVE_FALSE: u8 = 0;
pub const ALIVE_TRUE: u8 = 1;
pub const RIGID_FALSE: u8 = 0;
pub const RIGID_TRUE: u8 = 1;
pub fn alive_value(alive: bool) -> u8 {
if alive { ALIVE_TRUE } else { ALIVE_FALSE }
}
pub fn is_alive_value(value: u8) -> bool {
value != ALIVE_FALSE
}
pub fn rigid_value(rigid: bool) -> u8 {
if rigid { RIGID_TRUE } else { RIGID_FALSE }
}
pub fn is_rigid_value(value: u8) -> bool {
value != RIGID_FALSE
}
pub fn set_alive(objects: &mut PhysObj, i: usize, alive: bool) -> Result<(), AttrsError> {
objects
.core
.set_vector_of::<u8>(ATTR_ALIVE, i, &[alive_value(alive)])
}
pub fn is_alive(objects: &PhysObj, i: usize) -> Result<bool, AttrsError> {
Ok(is_alive_value(
objects.core.vector_of::<u8>(ATTR_ALIVE, i)?[0],
))
}
pub fn set_rigid(objects: &mut PhysObj, i: usize, rigid: bool) -> Result<(), AttrsError> {
objects
.core
.set_vector_of::<u8>(ATTR_RIGID, i, &[rigid_value(rigid)])
}
pub fn is_rigid(objects: &PhysObj, i: usize) -> Result<bool, AttrsError> {
Ok(is_rigid_value(
objects.core.vector_of::<u8>(ATTR_RIGID, i)?[0],
))
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ParticleSelection {
AliveOnly,
All,
}
impl ParticleSelection {
pub fn includes_dead(self) -> bool {
matches!(self, Self::All)
}
}