teki_common/utils/fps_calc.rs
1use crate::traits::Timer;
2
3pub struct FpsCalc<T: Timer> {
4 fps: i32,
5 timer: T,
6 ndraw: i32,
7}
8
9impl<T: Timer> FpsCalc<T> {
10 pub fn new(timer: T) -> Self {
11 Self { fps: 0, timer, ndraw: 0 }
12 }
13
14 pub fn update(&mut self) -> bool {
15 self.ndraw += 1;
16 if !self.timer.passed_one_second() {
17 return false;
18 }
19
20 self.fps = self.ndraw;
21 self.ndraw = 0;
22 true
23 }
24
25 pub fn fps(&self) -> i32 {
26 self.fps
27 }
28}