Struct game_loop::GameLoop

source ·
pub struct GameLoop<G, T: TimeTrait, W> {
    pub game: G,
    pub updates_per_second: u32,
    pub max_frame_time: f64,
    pub exit_next_iteration: bool,
    pub window: W,
    pub window_occluded: bool,
    /* private fields */
}

Fields§

§game: G§updates_per_second: u32§max_frame_time: f64§exit_next_iteration: bool§window: W§window_occluded: bool

Implementations§

source§

impl<G, T: TimeTrait, W> GameLoop<G, T, W>

source

pub fn new( game: G, updates_per_second: u32, max_frame_time: f64, window: W ) -> Self

source

pub fn next_frame<U, R>(&mut self, update: U, render: R) -> bool
where U: FnMut(&mut GameLoop<G, T, W>), R: FnMut(&mut GameLoop<G, T, W>),

source

pub fn re_accumulate(&mut self)

source

pub fn exit(&mut self)

Examples found in repository?
examples/game_of_life.rs (line 21)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
fn main() {
    let mut game = GameOfLife::new(12, 12);

    // Make some of the cells alive.
    game.set(5, 5);
    game.set(5, 6);
    game.set(5, 7);
    game.set(6, 6);

    // Run the game loop with 2 updates per second.
    let g = game_loop(game, 2, 1.0, |g| {
        g.game.update();
    }, |g| {
        // Pass the blending factor (even though this example doesn't use it).
        g.game.render(g.blending_factor());

        // Exit after 10 seconds.
        if g.running_time() > 10.0 {
            g.exit();
        }
    });

    // Use the 'g' variable to query the game loop after it finishes.
    println!("Exiting after {} seconds", g.running_time());
    println!("");
    println!("Last frame time: {}", g.last_frame_time());
    println!("Number of updates: {}", g.number_of_updates());
    println!("Number of renders: {}", g.number_of_renders());
}
source

pub fn set_updates_per_second(&mut self, new_updates_per_second: u32)

source

pub fn fixed_time_step(&self) -> f64

source

pub fn number_of_updates(&self) -> u64

Examples found in repository?
examples/game_of_life.rs (line 29)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
fn main() {
    let mut game = GameOfLife::new(12, 12);

    // Make some of the cells alive.
    game.set(5, 5);
    game.set(5, 6);
    game.set(5, 7);
    game.set(6, 6);

    // Run the game loop with 2 updates per second.
    let g = game_loop(game, 2, 1.0, |g| {
        g.game.update();
    }, |g| {
        // Pass the blending factor (even though this example doesn't use it).
        g.game.render(g.blending_factor());

        // Exit after 10 seconds.
        if g.running_time() > 10.0 {
            g.exit();
        }
    });

    // Use the 'g' variable to query the game loop after it finishes.
    println!("Exiting after {} seconds", g.running_time());
    println!("");
    println!("Last frame time: {}", g.last_frame_time());
    println!("Number of updates: {}", g.number_of_updates());
    println!("Number of renders: {}", g.number_of_renders());
}
source

pub fn number_of_renders(&self) -> u64

Examples found in repository?
examples/game_of_life.rs (line 30)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
fn main() {
    let mut game = GameOfLife::new(12, 12);

    // Make some of the cells alive.
    game.set(5, 5);
    game.set(5, 6);
    game.set(5, 7);
    game.set(6, 6);

    // Run the game loop with 2 updates per second.
    let g = game_loop(game, 2, 1.0, |g| {
        g.game.update();
    }, |g| {
        // Pass the blending factor (even though this example doesn't use it).
        g.game.render(g.blending_factor());

        // Exit after 10 seconds.
        if g.running_time() > 10.0 {
            g.exit();
        }
    });

    // Use the 'g' variable to query the game loop after it finishes.
    println!("Exiting after {} seconds", g.running_time());
    println!("");
    println!("Last frame time: {}", g.last_frame_time());
    println!("Number of updates: {}", g.number_of_updates());
    println!("Number of renders: {}", g.number_of_renders());
}
source

pub fn last_frame_time(&self) -> f64

Examples found in repository?
examples/game_of_life.rs (line 28)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
fn main() {
    let mut game = GameOfLife::new(12, 12);

    // Make some of the cells alive.
    game.set(5, 5);
    game.set(5, 6);
    game.set(5, 7);
    game.set(6, 6);

    // Run the game loop with 2 updates per second.
    let g = game_loop(game, 2, 1.0, |g| {
        g.game.update();
    }, |g| {
        // Pass the blending factor (even though this example doesn't use it).
        g.game.render(g.blending_factor());

        // Exit after 10 seconds.
        if g.running_time() > 10.0 {
            g.exit();
        }
    });

    // Use the 'g' variable to query the game loop after it finishes.
    println!("Exiting after {} seconds", g.running_time());
    println!("");
    println!("Last frame time: {}", g.last_frame_time());
    println!("Number of updates: {}", g.number_of_updates());
    println!("Number of renders: {}", g.number_of_renders());
}
source

pub fn running_time(&self) -> f64

Examples found in repository?
examples/game_of_life.rs (line 20)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
fn main() {
    let mut game = GameOfLife::new(12, 12);

    // Make some of the cells alive.
    game.set(5, 5);
    game.set(5, 6);
    game.set(5, 7);
    game.set(6, 6);

    // Run the game loop with 2 updates per second.
    let g = game_loop(game, 2, 1.0, |g| {
        g.game.update();
    }, |g| {
        // Pass the blending factor (even though this example doesn't use it).
        g.game.render(g.blending_factor());

        // Exit after 10 seconds.
        if g.running_time() > 10.0 {
            g.exit();
        }
    });

    // Use the 'g' variable to query the game loop after it finishes.
    println!("Exiting after {} seconds", g.running_time());
    println!("");
    println!("Last frame time: {}", g.last_frame_time());
    println!("Number of updates: {}", g.number_of_updates());
    println!("Number of renders: {}", g.number_of_renders());
}
source

pub fn accumulated_time(&self) -> f64

source

pub fn blending_factor(&self) -> f64

Examples found in repository?
examples/game_of_life.rs (line 17)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
fn main() {
    let mut game = GameOfLife::new(12, 12);

    // Make some of the cells alive.
    game.set(5, 5);
    game.set(5, 6);
    game.set(5, 7);
    game.set(6, 6);

    // Run the game loop with 2 updates per second.
    let g = game_loop(game, 2, 1.0, |g| {
        g.game.update();
    }, |g| {
        // Pass the blending factor (even though this example doesn't use it).
        g.game.render(g.blending_factor());

        // Exit after 10 seconds.
        if g.running_time() > 10.0 {
            g.exit();
        }
    });

    // Use the 'g' variable to query the game loop after it finishes.
    println!("Exiting after {} seconds", g.running_time());
    println!("");
    println!("Last frame time: {}", g.last_frame_time());
    println!("Number of updates: {}", g.number_of_updates());
    println!("Number of renders: {}", g.number_of_renders());
}
source

pub fn previous_instant(&self) -> T

source

pub fn current_instant(&self) -> T

Auto Trait Implementations§

§

impl<G, T, W> Freeze for GameLoop<G, T, W>
where G: Freeze, W: Freeze, T: Freeze,

§

impl<G, T, W> RefUnwindSafe for GameLoop<G, T, W>

§

impl<G, T, W> Send for GameLoop<G, T, W>
where G: Send, W: Send, T: Send,

§

impl<G, T, W> Sync for GameLoop<G, T, W>
where G: Sync, W: Sync, T: Sync,

§

impl<G, T, W> Unpin for GameLoop<G, T, W>
where G: Unpin, W: Unpin, T: Unpin,

§

impl<G, T, W> UnwindSafe for GameLoop<G, T, W>
where G: UnwindSafe, W: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.