FpsCounter: Use a const instead of generating a new time::Duration each tick
Former-commit-id: e0b6ec4bbc97119f6e82d1219d1406626b50e890
This commit is contained in:
parent
884f39ca8f
commit
810ff89ea7
|
@ -66,6 +66,8 @@ pub struct FpsCounter {
|
||||||
timer: time::Instant,
|
timer: time::Instant,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SECOND: time::Duration = time::Duration::from_secs(1);
|
||||||
|
|
||||||
impl Default for FpsCounter {
|
impl Default for FpsCounter {
|
||||||
fn default() -> FpsCounter {
|
fn default() -> FpsCounter {
|
||||||
FpsCounter {
|
FpsCounter {
|
||||||
|
@ -78,7 +80,7 @@ impl Default for FpsCounter {
|
||||||
impl FpsCounter {
|
impl FpsCounter {
|
||||||
pub fn tick(&mut self) -> Option<u32> {
|
pub fn tick(&mut self) -> Option<u32> {
|
||||||
self.count += 1;
|
self.count += 1;
|
||||||
if self.timer.elapsed() >= time::Duration::from_secs(1) {
|
if self.timer.elapsed() >= SECOND {
|
||||||
let fps = self.count;
|
let fps = self.count;
|
||||||
self.timer = time::Instant::now();
|
self.timer = time::Instant::now();
|
||||||
self.count = 0;
|
self.count = 0;
|
||||||
|
|
Reference in a new issue