Struct tiny_game_loop::GameLoop
source · pub struct GameLoop { /* private fields */ }
Expand description
Implemented based on https://gafferongames.com/post/fix_your_timestep.
Implementations§
source§impl GameLoop
impl GameLoop
sourcepub fn new(target_frame_time: Duration, max_frame_time: Duration) -> Self
pub fn new(target_frame_time: Duration, max_frame_time: Duration) -> Self
Create a new GameLoop
instance.
sourcepub fn set_target_frame_time(&mut self, time: Duration)
pub fn set_target_frame_time(&mut self, time: Duration)
Set the desired (minimum) time between application updates.
sourcepub fn set_max_frame_time(&mut self, time: Duration)
pub fn set_max_frame_time(&mut self, time: Duration)
Set the maximum time between application updates. The real time can still be longer.
sourcepub fn update(&mut self, elapsed: Duration) -> UpdateResult
pub fn update(&mut self, elapsed: Duration) -> UpdateResult
Perform all calculations for an update.
You can do something like:
loop {
// handling events, input or whatever
let elapsed = instance.elapsed(); // using `std::time::Instance` to measure time between updates
instance = Instance::now();
let update_result = game_loop.update(elapsed).run(|update_result| {
// your actual update logic
});
// rendering logic
}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for GameLoop
impl RefUnwindSafe for GameLoop
impl Send for GameLoop
impl Sync for GameLoop
impl Unpin for GameLoop
impl UnwindSafe for GameLoop
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