fn cache_sprite(&mut self, index: u8) {
        let sprite = self.oam[index as usize];
        let height = self.sprite_size.height();
        let start  = sprite.top_line();
        let end    = start + (height as i32);

        for y in (start..end) {
            if y < 0 || y >= 144 {
                // Sprite line is not displayed
                continue;
            }

            let y = y as usize;

            let l = self.line_cache[y].len();

            if self.line_cache[y][l - 1].is_some() {
                // We reached the sprite limit for that line, we can
                // display no more.
                continue;
            }

            // Insert sprite into the cache for this line. We order
            // the sprites from left to right and from highest to
            // lowest priority.
            for i in (0..l) {
                match self.line_cache[y][i] {
                    None => {
                        // This cache entry is empty, use it to hold
                        // our sprite and move on to the next line
                        self.line_cache[y][i] = Some(index);
                        break;
                    }
                    Some(other) => {
                        let other_sprite = &self.oam[other as usize];

                        // When sprites overlap the one with the
                        // smallest x pos is on top. If the x values
                        // are equal then the offset in OAM is used.
                        if sprite.x_pos() < other_sprite.x_pos() ||
                           (sprite.x_pos() == other_sprite.x_pos() &&
                            index < other) {
                            // Our sprite is higher priority, move the
                            // rest of the cacheline one place. We
                            // know that the last item is None since
                            // it's checked above.
                            for j in (i..(l - 1)).rev() {
                                self.line_cache[y][j + 1] =
                                    self.line_cache[y][j];
                            }

                            self.line_cache[y][i] = Some(index);
                            break;
                        }
                    }
                }
            }
        }
    }
/// Insert sprite at `index` into the line cache
Insert sprite at `index` into the line cache
Insert sprite at ` index ` into the line cache
fn cache_sprite(&mut self, index: u8) {
        let sprite = self.oam[index as usize];
        let height = self.sprite_size.height();
        let start  = sprite.top_line();
        let end    = start + (height as i32);
        for y in (start..end) {
            if y < 0 || y >= 144 {
                // Sprite line is not displayed
                continue;
            }
            let y = y as usize;
            let l = self.line_cache[y].len();
            if self.line_cache[y][l - 1].is_some() {
                // We reached the sprite limit for that line, we can
                // display no more.
                continue;
            }
            // Insert sprite into the cache for this line. We order
            // the sprites from left to right and from highest to
            // lowest priority.
            for i in (0..l) {
                match self.line_cache[y][i] {
                    None => {
                        // This cache entry is empty, use it to hold
                        // our sprite and move on to the next line
                        self.line_cache[y][i] = Some(index);
                        break;
                    }
                    Some(other) => {
                        let other_sprite = &self.oam[other as usize];
                        // When sprites overlap the one with the
                        // smallest x pos is on top. If the x values
                        // are equal then the offset in OAM is used.
                        if sprite.x_pos() < other_sprite.x_pos() ||
                           (sprite.x_pos() == other_sprite.x_pos() &&
                            index < other) {
                            // Our sprite is higher priority, move the
                            // rest of the cacheline one place. We
                            // know that the last item is None since
                            // it's checked above.
                            for j in (i..(l - 1)).rev() {
                                self.line_cache[y][j + 1] =
                                    self.line_cache[y][j];
                            }
                            self.line_cache[y][i] = Some(index);
                            break;
                        }
                    }
                }
            }
        }
    }
fn cache_sprite ( & mut self , index : u8 ) { let sprite = self . oam [ index as usize ] ; let height = self . sprite_size . height ( ) ; let start = sprite . top_line ( ) ; let end = start + ( height as i32 ) ; for y in ( start .. end ) { if y < 0 || y >= 144 { // Sprite line is not displayed continue ; } let y = y as usize ; let l = self . line_cache [ y ] . len ( ) ; if self . line_cache [ y ] [ l - 1 ] . is_some ( ) { // We reached the sprite limit for that line, we can // display no more. continue ; } // Insert sprite into the cache for this line. We order // the sprites from left to right and from highest to // lowest priority. for i in ( 0 .. l ) { match self . line_cache [ y ] [ i ] { None => { // This cache entry is empty, use it to hold // our sprite and move on to the next line self . line_cache [ y ] [ i ] = Some ( index ) ; break ; } Some ( other ) => { let other_sprite = & self . oam [ other as usize ] ; // When sprites overlap the one with the // smallest x pos is on top. If the x values // are equal then the offset in OAM is used. if sprite . x_pos ( ) < other_sprite . x_pos ( ) || ( sprite . x_pos ( ) == other_sprite . x_pos ( ) && index < other ) { // Our sprite is higher priority, move the // rest of the cacheline one place. We // know that the last item is None since // it's checked above. for j in ( i .. ( l - 1 ) ) . rev ( ) { self . line_cache [ y ] [ j + 1 ] = self . line_cache [ y ] [ j ] ; } self . line_cache [ y ] [ i ] = Some ( index ) ; break ; } } } } } }
Insert sprite at `index` into the line cache
Insert sprite at ` index ` into the line cache
&mut self
index
u8
&mut self
index
u8