pub struct FrameCounter { /* private fields */ }
Implementations§
Source§impl FrameCounter
impl FrameCounter
Sourcepub fn new(frame_rate: f64) -> Self
pub fn new(frame_rate: f64) -> Self
Creates a new FrameCounter with the given starting framerate.
§Arguments
frame_rate
- initial frame rate guess.
Sourcepub fn tick(&mut self)
pub fn tick(&mut self)
Updates the frame measurements
Examples found in repository?
More examples
examples/limiter.rs (line 11)
7pub fn main() {
8 let mut frame_counter = FrameCounter::default();
9
10 loop {
11 frame_counter.tick();
12
13 dummy_workload();
14
15 // hot loop, do not trigger scheduler
16 frame_counter.sleep_until_framerate(60f64);
17
18 println!("fps stats - {}", frame_counter);
19 }
20}
Sourcepub fn wait_until_framerate(&self, framerate: f64)
pub fn wait_until_framerate(&self, framerate: f64)
Waits in a hot-loop until the desired frame rate is achieved.
This function will not call std::thread:sleep
to prevent
the OS from scheduling this thread.
This means the function will consume an entire core on the CPU.
§Example:
use frame_counter::FrameCounter;
pub fn dummy_workload() {
std::thread::sleep(std::time::Duration::from_millis(1));
}
pub fn main() {
let mut frame_counter = FrameCounter::default();
loop {
frame_counter.tick();
dummy_workload();
frame_counter.wait_until_framerate(60f64);
println!("fps stats - {}", frame_counter);
}
}
Sourcepub fn sleep_until_framerate(&self, framerate: f64)
pub fn sleep_until_framerate(&self, framerate: f64)
Waits in a cold-loop until the desired frame rate is achieved.
This function will call std::thread:sleep
to prevent
the process from consuming the entire CPU Core.
§Example:
use frame_counter::FrameCounter;
pub fn dummy_workload() {
std::thread::sleep(std::time::Duration::from_millis(1));
}
pub fn main() {
let mut frame_counter = FrameCounter::default();
loop {
frame_counter.tick();
dummy_workload();
frame_counter.sleep_until_framerate(60f64);
println!("fps stats - {}", frame_counter);
}
}
Examples found in repository?
examples/limiter.rs (line 16)
7pub fn main() {
8 let mut frame_counter = FrameCounter::default();
9
10 loop {
11 frame_counter.tick();
12
13 dummy_workload();
14
15 // hot loop, do not trigger scheduler
16 frame_counter.sleep_until_framerate(60f64);
17
18 println!("fps stats - {}", frame_counter);
19 }
20}
Sourcepub fn frame_time(&self) -> Duration
pub fn frame_time(&self) -> Duration
Returns the frame time of the last frame as a Duration
.
Sourcepub fn avg_frame_time(&self) -> Duration
pub fn avg_frame_time(&self) -> Duration
Returns the average frame time over the last second as a Duration
.
Sourcepub fn frame_rate(&self) -> f64
pub fn frame_rate(&self) -> f64
Returns the frame rate of the last frame.
Sourcepub fn avg_frame_rate(&self) -> f64
pub fn avg_frame_rate(&self) -> f64
Returns the average frame rate of the last second.
Trait Implementations§
Source§impl Default for FrameCounter
impl Default for FrameCounter
Auto Trait Implementations§
impl Freeze for FrameCounter
impl RefUnwindSafe for FrameCounter
impl Send for FrameCounter
impl Sync for FrameCounter
impl Unpin for FrameCounter
impl UnwindSafe for FrameCounter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more