pub struct GameLoop { /* private fields */ }Expand description
Game loop manager implementing fixed timestep with interpolation
§Example
use jugar_core::{GameLoop, GameLoopConfig};
let mut game_loop = GameLoop::new(GameLoopConfig::default_60fps());
// Game loop
let current_time = 0.1; // From platform
let result = game_loop.update(current_time);
// Run physics ticks
for _ in 0..result.physics_ticks {
// physics.step(game_loop.config().fixed_dt);
}
// Render with interpolation
if result.should_render {
let alpha = game_loop.alpha();
// render(alpha);
}Implementations§
Source§impl GameLoop
impl GameLoop
Sourcepub const fn new(config: GameLoopConfig) -> Self
pub const fn new(config: GameLoopConfig) -> Self
Creates a new game loop with the given configuration
Sourcepub const fn config(&self) -> &GameLoopConfig
pub const fn config(&self) -> &GameLoopConfig
Returns the configuration
Sourcepub const fn state(&self) -> &GameLoopState
pub const fn state(&self) -> &GameLoopState
Returns the current state
Sourcepub fn update(&mut self, current_time: f32) -> FrameResult
pub fn update(&mut self, current_time: f32) -> FrameResult
Updates the game loop with the current time
Returns the number of physics ticks to run.
Sourcepub const fn accumulator(&self) -> f32
pub const fn accumulator(&self) -> f32
Returns the current accumulator value
This is used by the probar introspection module.
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