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 new_with_fps(fps: u32, max_frame_time: Duration) -> Self
pub fn new_with_fps(fps: u32, max_frame_time: Duration) -> Self
Create a new GameLoop
instance specifying FPS instead of frame time for convenience.
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_fps(&mut self, fps: u32)
pub fn set_fps(&mut self, fps: u32)
Set the desired (maximum) FPS. Overrides target_frame_time
since they are inversions of each other.
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