#[derive(Debug)]
pub struct PhysicsTime {
pub(crate) delta_seconds: f32,
pub(crate) max_sub_steps: u32,
pub(crate) in_sub_step: bool,
pub(crate) _max_bank_size: f32,
pub(crate) _time_bank: f32,
}
impl Default for PhysicsTime {
fn default() -> Self {
let t = PhysicsTime {
delta_seconds: 0.0,
max_sub_steps: 0,
in_sub_step: false,
_max_bank_size: 0.0,
_time_bank: 0.0,
};
t.with_frames_per_second(60).with_max_sub_steps(8)
}
}
impl PhysicsTime {
pub fn delta_seconds(&self) -> f32 {
self.delta_seconds
}
pub fn in_sub_step(&self) -> bool {
self.in_sub_step
}
pub fn with_frames_per_second(mut self, frames_per_seconds: u32) -> Self {
self.set_frames_per_seconds(frames_per_seconds);
self
}
pub fn set_frames_per_seconds(&mut self, frames_per_seconds: u32) {
self.set_delta_seconds(1.0 / frames_per_seconds as f32);
}
pub fn with_max_sub_steps(mut self, max_sub_steps: u32) -> Self {
self.set_max_sub_steps(max_sub_steps);
self
}
pub fn set_max_sub_steps(&mut self, max_sub_steps: u32) {
self.max_sub_steps = max_sub_steps;
self.update_max_bank_size();
}
pub fn sub_max_sub_steps(&self) -> u32 {
self.max_sub_steps
}
fn set_delta_seconds(&mut self, delta_seconds: f32) {
self.delta_seconds = delta_seconds;
self.update_max_bank_size();
}
fn update_max_bank_size(&mut self) {
self._max_bank_size = self.delta_seconds * self.max_sub_steps as f32;
}
}