hexga_engine 0.0.11-beta.53

A multimedia game and software engine for handling graphics, audio, and input.
Documentation
use super::*;

pub mod prelude
{
    pub use super::perf;
    pub(crate) use super::*;
}

pub fn perf() -> impl DerefMut<Target = AppPerf> { APP.get_mut().guard_map_mut(|a| a.perf()) }

#[derive(Clone, PartialEq, Debug)]
pub struct AppPerf
{
    fps: TimeCounter,
    ups: TimeCounter,
}

impl AppPerf
{
    pub(crate) fn new() -> Self
    {
        AppPerf {
            fps: ___(),
            ups: ___(),
        }
    }

    /// Return the previous number of frame per second
    pub fn fps(&self) -> int { self.fps.nb() }

    /// Return the previous update per second
    pub fn ups(&self) -> int { self.ups.nb() }
}

/*
impl ScopedFlow for AppPerf
{
    fn begin_flow_update(&mut self, dt: DeltaTime) { self.ups.count(); }
    fn end_flow_update(&mut self, dt: DeltaTime) { }
    fn begin_flow_draw(&mut self) { self.fps.count(); }
    fn end_flow_draw(&mut self) { }
}
*/

#[derive(Debug, Clone, Copy, PartialEq)]
pub(crate) struct TimeCounter
{
    timer: Time,
    counter: int,
    last_counter: int,
}
impl Default for TimeCounter
{
    fn default() -> Self
    {
        Self {
            timer: Time::since_launch(),
            counter: 0,
            last_counter: 0,
        }
    }
}
impl TimeCounter
{
    pub fn nb(&self) -> int { self.last_counter }
    pub fn count(&mut self)
    {
        let now = Time::since_launch();
        if now - self.timer >= 1.secs()
        {
            self.timer = now;
            self.last_counter = self.counter;
            self.counter = 0;
        }
        self.counter += 1;
    }
}