pub fn new(tps: usize, max_frameskip: usize) -> Result<Self, GameLoopError> {
        if tps < 1 {
            return Err(GameLoopError::BadTps);
        }

        if max_frameskip < 1 {
            return Err(GameLoopError::BadFrameSkip);
        }

        let start_time = Instant::now();
        let skip_ticks = 1000 / tps;

        debug!(
            "initialized with {} ticks/second ({}ms/tick), with a max frame skip of {}",
            tps, skip_ticks, max_frameskip
        );

        Ok(Self {
            start_time,
            max_frameskip,
            skip_ticks,
            next_game_tick: Cell::new(0),
        })
    }
/// Create a new game loop.
/// # Arguments
/// * `tps`: game ticks per second
/// * `max_frameskip`: maximum number of consecutive ticks before a render is mandatory. As
/// [deWiTTERS](https://dewitters.com/dewitters-gameloop/) 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
/// ```
/// # use ::gameloop::*;;
/// // 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());
/// ```
///
Create a new game loop.
Create a new game loop .
pub fn new(tps: usize, max_frameskip: usize) -> Result<Self, GameLoopError> {
        if tps < 1 {
            return Err(GameLoopError::BadTps);
        }
        if max_frameskip < 1 {
            return Err(GameLoopError::BadFrameSkip);
        }
        let start_time = Instant::now();
        let skip_ticks = 1000 / tps;
        debug!(
            "initialized with {} ticks/second ({}ms/tick), with a max frame skip of {}",
            tps, skip_ticks, max_frameskip
        );
        Ok(Self {
            start_time,
            max_frameskip,
            skip_ticks,
            next_game_tick: Cell::new(0),
        })
    }
pub fn new ( tps : usize , max_frameskip : usize ) -> Result < Self , GameLoopError > { if tps < 1 { return Err ( GameLoopError :: BadTps ) ; } if max_frameskip < 1 { return Err ( GameLoopError :: BadFrameSkip ) ; } let start_time = Instant :: now ( ) ; let skip_ticks = 1000 / tps ; debug ! ( " " tps skip_ticks max_frameskip ) ; Ok ( Self { start_time , max_frameskip , skip_ticks , next_game_tick : Cell :: new ( 0 ) , } ) }
Create a new game loop.
Create a new game loop .
tps
usize
max_frameskip
usize
tps
usize
max_frameskip
usize
example
None
use ::gameloop::*;;
20 ticks per second, 5 max frame skip
let game_loop = GameLoop::new(20, 5);
assert!(game_loop.is_ok()).


20 ticks per second 5 max frame skip let game_loop = GameLoop :: new ( 20 5 ) ; assert! ( game_loop . is_ok () ) .