mirror of
https://github.com/maplibre/maplibre-rs.git
synced 2025-12-08 19:05:57 +00:00
Fix fps meter
This commit is contained in:
parent
7c70ab0ce5
commit
8998b59d63
@ -2,7 +2,7 @@ use std::time::{Duration, Instant};
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use js_sys;
|
||||
use log::{info, trace};
|
||||
use log::{info};
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub struct FPSMeter {
|
||||
@ -12,8 +12,28 @@ pub struct FPSMeter {
|
||||
pub time_secs: f64,
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub struct FPSMeter {
|
||||
start: Instant,
|
||||
next_report: Instant,
|
||||
frame_count: u32,
|
||||
pub time_secs: f64,
|
||||
}
|
||||
|
||||
|
||||
impl FPSMeter {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn new() -> Self {
|
||||
let start = Instant::now();
|
||||
Self {
|
||||
start,
|
||||
next_report: start + Duration::from_secs(1),
|
||||
frame_count: 0,
|
||||
time_secs: 0.0,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub fn new() -> Self {
|
||||
let start = (js_sys::Date::now() / 1000.0) as f64;
|
||||
Self {
|
||||
@ -24,6 +44,19 @@ impl FPSMeter {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn update_and_print(&mut self) {
|
||||
self.frame_count += 1;
|
||||
let now = Instant::now();
|
||||
self.time_secs = (now - self.start).as_secs_f64();
|
||||
if now >= self.next_report {
|
||||
info!("{} FPS", self.frame_count);
|
||||
self.frame_count = 0;
|
||||
self.next_report = now + Duration::from_secs(1);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub fn update_and_print(&mut self) {
|
||||
self.frame_count += 1;
|
||||
let now = (js_sys::Date::now() / 1000.0) as f64;
|
||||
@ -35,36 +68,3 @@ impl FPSMeter {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub struct FPSMeter {
|
||||
start: Instant,
|
||||
next_report: Instant,
|
||||
frame_count: u32,
|
||||
pub time_secs: f32,
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
impl FPSMeter {
|
||||
pub fn new() -> Self {
|
||||
let start = Instant::now();
|
||||
Self {
|
||||
start,
|
||||
next_report: start + Duration::from_secs(1),
|
||||
frame_count: 0,
|
||||
time_secs: 0.0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_and_print(&mut self) {
|
||||
self.frame_count += 1;
|
||||
let now = Instant::now();
|
||||
self.time_secs = (now - self.start).as_secs_f32();
|
||||
if now >= self.next_report {
|
||||
info!("{} FPS", self.frame_count);
|
||||
self.frame_count = 0;
|
||||
self.next_report = now + Duration::from_secs(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user