[−][src]Struct gameloop::GameLoop
Represents the core loop for the duration of the game.
Example
// run at 20 ticks per second let game_loop = GameLoop::new(20, 5).unwrap(); // begin core game loop loop { // handle window events for action in game_loop.actions() { match action { FrameAction::Tick => /* simulate 1 game tick */ FrameAction::Render { interpolation } => /* render the game state interpolated between previous and next tick */ } } }
Implementations
impl GameLoop
[src]
pub fn new(tps: usize, max_frameskip: usize) -> Result<Self, GameLoopError>
[src]
Create a new game loop.
Arguments
tps
: game ticks per secondmax_frameskip
: maximum number of consecutive ticks before a render is mandatory. As deWiTTERS explains:
When running on slow hardware, the framerate can drop until the game update loop will reach MAX_FRAMESKIP. In practice this means that when our render FPS drops below 5 (= FRAMES_PER_SECOND / MAX_FRAMESKIP), the actual game will slow down.
Example
// 20 ticks per second, 5 max frame skip let game_loop = GameLoop::new(20, 5); assert!(game_loop.is_ok()); // tps and max_frameskip must be >= 1 assert!(GameLoop::new(0, 1).is_err()); assert!(GameLoop::new(1, 0).is_err());
pub fn actions(&self) -> impl Iterator<Item = FrameAction> + '_
[src]
The heart of the game loop, this returns an iterator of FrameAction
s. These indicate
when your game should tick and render to maintain the fixed tick rate while rendering
as fast as possible.
Call this once per game loop iteration.
Example
let game_loop = /* initialize game loop */ loop { // handle window events for action in game_loop.actions() { match action { FrameAction::Tick => /* simulate 1 game tick */ FrameAction::Render { interpolation } => /* render the game state interpolated between previous and next tick */ } } }
Auto Trait Implementations
impl !RefUnwindSafe for GameLoop
impl Send for GameLoop
impl !Sync for GameLoop
impl Unpin for GameLoop
impl UnwindSafe for GameLoop
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,