//! This module handles the physics of things and how they interact
//! (and also collisions)
use std::collections::HashMap;
use ulid::Ulid;
/// An entity that has been marked to be interactable by the physics system
//
// None - the corresponding internal structures have not been made to identify this object
// Some(id) - the internal structures that identify this object are stored under/with `id`
#[derive(Debug)]
pub struct PhysicalObject(Option<Ulid>);
pub struct PhysicsSystem {}
/// A description of the state of physical objects
#[derive(Debug, Clone)]
pub struct PhysicsState {
objects: HashMap<Ulid, PhysicsObject>,
}
impl PhysicsState {
/// linearly interpolate between two physics states
pub fn lerp(&self, to: &PhysicsState, alpha: f32) -> PhysicsState {
let both_exist = self
.objects
.iter()
.filter_map(|(id, oobj)| to.objects.get(id).map(|obj| (id, oobj, obj)));
let only_self = self
.objects
.iter()
.filter(|(id, _)| !to.objects.contains_key(*id));
let mut new_objects = HashMap::new();
// Lerp objects that exist in both states
for (id, oobj, obj) in both_exist {
new_objects.insert(*id, oobj.lerp(obj, alpha));
}
// Copy objects that exist only in this state
for (id, obj) in only_self {
new_objects.insert(*id, obj.clone());
}
Self {
objects: new_objects,
}
}
}
/// Physical description of a physics object
#[derive(Debug, Clone)]
pub struct PhysicsObject {}
impl PhysicsObject {
fn lerp(&self, to: &PhysicsObject, alpha: f32) -> PhysicsObject {
Self {}
}
}