use std::time::Instant;

pub struct Metrics {
    previous: Instant,
    elapsed: f64,
}

impl Metrics {
    pub fn elapsed(&self) -> f64 {
        self.elapsed
    }

    pub fn measure(&mut self) {
        let frame_time = self.previous.elapsed().as_secs_f64();

        self.elapsed += frame_time;
        self.previous = Instant::now();
    }

    pub fn reset_elapsed(&mut self) {
        self.elapsed = 0.;
    }
}

impl Default for Metrics {
    fn default() -> Self {
        let previous = Instant::now();
        let elapsed = 0.;

        Self { previous, elapsed }
    }
}
