/// Runs the server loop, blocking until the server
/// is shut down.
Runs the server loop, blocking until the server
is shut down.
Runs the server loop blocking until the server is shut down .
fn run_loop(world: &mut World, dispatcher: &mut Dispatcher, shutdown_rx: Receiver<()>) {
    loop {
        if shutdown_rx.try_recv().is_ok() {
            // Shut down
            return;
        }
        let start_time = current_time_in_millis();
        dispatcher.dispatch(&world);
        world.maintain();
        world.fetch_mut::<Util>().reset();
        // Increment tick count
        let mut tick_count = world.write_resource::<TickCount>();
        tick_count.0 += 1;
        // Sleep correct amount
        let end_time = current_time_in_millis();
        let elapsed = end_time - start_time;
        if elapsed > TICK_TIME {
            debug!("Running behind! Starting next tick immediately");
            continue; // Behind - start next tick immediately
        }
        // Sleep in 1ms increments until we've slept enough
        let mut sleep_time = (TICK_TIME - elapsed) as i64;
        let mut last_sleep_time = current_time_in_millis();
        while sleep_time > 0 {
            std::thread::sleep(Duration::from_millis(1));
            sleep_time -= (current_time_in_millis() - last_sleep_time) as i64;
            last_sleep_time = current_time_in_millis();
        }
    }
}
fn run_loop ( world : & mut World , dispatcher : & mut Dispatcher , shutdown_rx : Receiver < ( ) > ) { loop { if shutdown_rx . try_recv ( ) . is_ok ( ) { // Shut down return ; } let start_time = current_time_in_millis ( ) ; dispatcher . dispatch ( & world ) ; world . maintain ( ) ; world . fetch_mut :: < Util > ( ) . reset ( ) ; // Increment tick count let mut tick_count = world . write_resource :: < TickCount > ( ) ; tick_count . 0 += 1 ; // Sleep correct amount let end_time = current_time_in_millis ( ) ; let elapsed = end_time - start_time ; if elapsed > TICK_TIME { debug ! ( " " ) ; continue ; // Behind - start next tick immediately } // Sleep in 1ms increments until we've slept enough let mut sleep_time = ( TICK_TIME - elapsed ) as i64 ; let mut last_sleep_time = current_time_in_millis ( ) ; while sleep_time > 0 { std :: thread :: sleep ( Duration :: from_millis ( 1 ) ) ; sleep_time -= ( current_time_in_millis ( ) - last_sleep_time ) as i64 ; last_sleep_time = current_time_in_millis ( ) ; } } }
Runs the server loop, blocking until the server
is shut down.
Runs the server loop blocking until the server is shut down .
world
&mut World
dispatcher
&mut Dispatcher
shutdown_rx
Receiver<()>