Struct frame_counter::FrameCounter[][src]

pub struct FrameCounter { /* fields omitted */ }

Implementations

impl FrameCounter[src]

pub fn new(frame_rate: f64) -> Self[src]

Creates a new FrameCounter with the given starting framerate.

Arguments

  • frame_rate - initial frame rate guess.

pub fn tick(&mut self)[src]

Updates the frame measurements

pub fn wait_until_framerate(&self, framerate: f64)[src]

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);
    }
}

pub fn sleep_until_framerate(&self, framerate: f64)[src]

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);
    }
}

pub fn frame_time(&self) -> Duration[src]

Returns the frame time of the last frame as a Duration.

pub fn avg_frame_time(&self) -> Duration[src]

Returns the average frame time over the last second as a Duration.

pub fn frame_rate(&self) -> f64[src]

Returns the frame rate of the last frame.

pub fn avg_frame_rate(&self) -> f64[src]

Returns the average frame rate of the last second.

Trait Implementations

impl Default for FrameCounter[src]

fn default() -> Self[src]

Creates a new FrameCounter with a starting framerate of 100.

impl Display for FrameCounter[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.