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>
impl<G, T: TimeTrait, W> GameLoop<G, T, W>
pub fn new( game: G, updates_per_second: u32, max_frame_time: f64, window: W ) -> Self
pub fn next_frame<U, R>(&mut self, update: U, render: R) -> bool
pub fn re_accumulate(&mut self)
sourcepub fn exit(&mut self)
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());
}
pub fn set_updates_per_second(&mut self, new_updates_per_second: u32)
pub fn fixed_time_step(&self) -> f64
sourcepub fn number_of_updates(&self) -> u64
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());
}
sourcepub fn number_of_renders(&self) -> u64
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());
}
sourcepub fn last_frame_time(&self) -> f64
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());
}
sourcepub fn running_time(&self) -> f64
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());
}
pub fn accumulated_time(&self) -> f64
sourcepub fn blending_factor(&self) -> f64
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());
}
pub fn previous_instant(&self) -> T
pub fn current_instant(&self) -> T
Auto Trait Implementations§
impl<G, T, W> Freeze for GameLoop<G, T, W>
impl<G, T, W> RefUnwindSafe for GameLoop<G, T, W>
impl<G, T, W> Send for GameLoop<G, T, W>
impl<G, T, W> Sync for GameLoop<G, T, W>
impl<G, T, W> Unpin for GameLoop<G, T, W>
impl<G, T, W> UnwindSafe for GameLoop<G, T, W>
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