/// Run the app
/// Starts the game loop
Run the app
Starts the game loop
Run the app Starts the game loop
pub fn start<M>(
        &mut self,
        receiver: Receiver<M>,
        handle_input: &'static (dyn Fn(Receiver<M>, Arc<Mutex<I>>) -> I + Sync),
    ) where
        M: Send,
        I: Send + Copy,
    {
        self.is_running = true;
        // game configuration
        self.game.world_config();
        let input_copy = Arc::clone(&self.input);
        // Spawn a handler for client input
        thread::spawn(move || {
            handle_input(receiver, input_copy);
        });
        // game loop
        while self.is_running {
            // self.last_time += 1.0;
            let sleep_time = self.frames_per_second - self.last_time.elapsed();
            thread::sleep(sleep_time);
            // initial time
            self.last_time = Instant::now();
            // update
            self.game
                .update(*self.input.lock().unwrap(), Arc::clone(&self.shared_state));
            // Reset input
            self.game.reset_input(Arc::clone(&self.input));
            // render
            // End the game
            self.is_running = !self.game.end_game();
        }
    }
pub fn start < M > ( & mut self , receiver : Receiver < M > , handle_input : & ' static ( dyn Fn ( Receiver < M > , Arc < Mutex < I > > ) -> I + Sync ) , ) where M : Send , I : Send + Copy , { self . is_running = true ; // game configuration self . game . world_config ( ) ; let input_copy = Arc :: clone ( & self . input ) ; // Spawn a handler for client input thread :: spawn ( move | | { handle_input ( receiver , input_copy ) ; } ) ; // game loop while self . is_running { // self.last_time += 1.0; let sleep_time = self . frames_per_second - self . last_time . elapsed ( ) ; thread :: sleep ( sleep_time ) ; // initial time self . last_time = Instant :: now ( ) ; // update self . game . update ( * self . input . lock ( ) . unwrap ( ) , Arc :: clone ( & self . shared_state ) ) ; // Reset input self . game . reset_input ( Arc :: clone ( & self . input ) ) ; // render // End the game self . is_running = ! self . game . end_game ( ) ; } }
Run the app
Starts the game loop
Run the app Starts the game loop
&mut self
receiver
Receiver<M>
handle_input
&'static (dyn Fn(Receiver<M>, Arc<Mutex<I>>) -> I + Sync)