fn tick(&mut self) {
        let mut state = self.state.borrow_mut();

        if !state.win.is_open() {
            info!("window closed, exiting");
            process::exit(0);
        }

        // Render the screen
        let mut screen_buf = [0u32; 64 * 32];
        for (i, &pix) in state.fb.iter().enumerate() {
            if pix {
                screen_buf[i] = 0xffffffff;
            }
        }
        state.win.update_with_buffer(&screen_buf);

        // Decrease counters
        if state.delay_timer > 0 {
            state.delay_timer -= 1;
        }
        if state.sound_timer > 0 {
            state.sound_timer -= 1;
        }

        // Sleep so we tick at 60 Hz
        let time_since_last_tick = self.last_tick.elapsed();
        let frame_time = Duration::from_millis(1000 / 60);
        if time_since_last_tick < frame_time {
            let left_time = frame_time - time_since_last_tick;
            sleep(left_time);
        }

        self.last_tick = Instant::now();

        // Print timing info
        trace!("ran at {} ops/second", self.ops * 60);
        self.ops = 0;
    }
/// Called in intervals by the main loop
Called in intervals by the main loop
Called in intervals by the main loop
fn tick(&mut self) {
        let mut state = self.state.borrow_mut();
        if !state.win.is_open() {
            info!("window closed, exiting");
            process::exit(0);
        }
        // Render the screen
        let mut screen_buf = [0u32; 64 * 32];
        for (i, &pix) in state.fb.iter().enumerate() {
            if pix {
                screen_buf[i] = 0xffffffff;
            }
        }
        state.win.update_with_buffer(&screen_buf);
        // Decrease counters
        if state.delay_timer > 0 {
            state.delay_timer -= 1;
        }
        if state.sound_timer > 0 {
            state.sound_timer -= 1;
        }
        // Sleep so we tick at 60 Hz
        let time_since_last_tick = self.last_tick.elapsed();
        let frame_time = Duration::from_millis(1000 / 60);
        if time_since_last_tick < frame_time {
            let left_time = frame_time - time_since_last_tick;
            sleep(left_time);
        }
        self.last_tick = Instant::now();
        // Print timing info
        trace!("ran at {} ops/second", self.ops * 60);
        self.ops = 0;
    }
fn tick ( & mut self ) { let mut state = self . state . borrow_mut ( ) ; if ! state . win . is_open ( ) { info ! ( " " ) ; process :: exit ( 0 ) ; } // Render the screen let mut screen_buf = [ 0u32 ; 64 * 32 ] ; for ( i , & pix ) in state . fb . iter ( ) . enumerate ( ) { if pix { screen_buf [ i ] = 0xffffffff ; } } state . win . update_with_buffer ( & screen_buf ) ; // Decrease counters if state . delay_timer > 0 { state . delay_timer -= 1 ; } if state . sound_timer > 0 { state . sound_timer -= 1 ; } // Sleep so we tick at 60 Hz let time_since_last_tick = self . last_tick . elapsed ( ) ; let frame_time = Duration :: from_millis ( 1000 / 60 ) ; if time_since_last_tick < frame_time { let left_time = frame_time - time_since_last_tick ; sleep ( left_time ) ; } self . last_tick = Instant :: now ( ) ; // Print timing info trace ! ( " " self ops 60 ) ; self . ops = 0 ; }
Called in intervals by the main loop
Called in intervals by the main loop
&mut self
&mut self