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: ___(),
}
}
pub fn fps(&self) -> int { self.fps.nb() }
pub fn ups(&self) -> int { self.ups.nb() }
}
#[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;
}
}