earths 0.0.1

High-fidelity Earth simulation engine — orbit, atmosphere, geology, hydrology, biosphere, terrain, lighting, rendering, satellites, and temporal systems with full scientific coupling
Documentation
use super::calendar::SECONDS_PER_DAY;
pub struct TimeScale {
    pub simulation_time_s: f64,
    pub real_time_s: f64,
    pub speed_multiplier: f64,
    pub paused: bool,
}
impl TimeScale {
    pub fn new(speed_multiplier: f64) -> Self {
        Self {
            simulation_time_s: 0.0,
            real_time_s: 0.0,
            speed_multiplier,
            paused: false,
        }
    }
    pub fn realtime() -> Self {
        Self::new(1.0)
    }
    pub fn fast_forward(factor: f64) -> Self {
        Self::new(factor)
    }
    pub fn slow_motion(factor: f64) -> Self {
        Self::new(1.0 / factor)
    }
    pub fn step(&mut self, real_dt_s: f64) {
        self.real_time_s += real_dt_s;
        if !self.paused {
            self.simulation_time_s += real_dt_s * self.speed_multiplier;
        }
    }
    pub fn pause(&mut self) {
        self.paused = true;
    }
    pub fn resume(&mut self) {
        self.paused = false;
    }
    pub fn toggle_pause(&mut self) {
        self.paused = !self.paused;
    }
    pub fn set_speed(&mut self, multiplier: f64) {
        self.speed_multiplier = multiplier;
    }
    pub fn simulation_dt(&self, real_dt_s: f64) -> f64 {
        if self.paused {
            0.0
        } else {
            real_dt_s * self.speed_multiplier
        }
    }
    pub fn sim_hours(&self) -> f64 {
        self.simulation_time_s / 3600.0
    }
    pub fn sim_days(&self) -> f64 {
        self.simulation_time_s / SECONDS_PER_DAY
    }
    pub fn sim_years(&self) -> f64 {
        self.simulation_time_s / (SECONDS_PER_DAY * 365.2422)
    }
}