bbodi / rustarok

Multiplayer, fast-paced Moba style game
275 stars 29 forks source link

Sprite loading with and without RLE encoding seem to be doing the same thing #16

Closed drgomesp closed 3 years ago

drgomesp commented 4 years ago

I'm trying to understand the code for sprite loading, and I've been struggling to understand the different implementations for loading indexed images with and without RLE encoding.

Both https://github.com/bbodi/rustarok/blob/7ea7abfa5631f74ad31ce0c2f0f8730c9ef70765/client/src/grf/spr.rs#L44 and https://github.com/bbodi/rustarok/blob/7ea7abfa5631f74ad31ce0c2f0f8730c9ef70765/client/src/grf/spr.rs#L46 seem to be doing the same thing, with slightly different implementations:

 fn read_indexed_frames(buf: &mut BinaryReader, indexed_frame_count: usize) -> Vec<SprFrame> {
    (0..indexed_frame_count)
        .map(|_i| {
            let width = buf.next_u16();
            let height = buf.next_u16();
            let frame = SprFrame {
                typ: SpriteType::PAL,
                width: width as usize,
                height: height as usize,
                data_index: buf.tell(),
            };
            buf.skip(width as u32 * height as u32);
            //                buf.next(width as u32 * height as u32).to_vec();
            frame
        })
        .collect()
}
fn read_indexed_frames_rle(
    reader: &mut BinaryReader,
    indexed_frame_count: usize,
) -> Vec<SprFrame> {
    (0..indexed_frame_count)
        .map(|_i| {
            let width = reader.next_u16();
            let height = reader.next_u16();
            let data_index = reader.tell();
            let size = reader.next_u16();
            reader.skip(size as u32);
             SprFrame {
                typ: SpriteType::PAL,
                width: width as usize,
                height: height as usize,
                data_index,
            }
        })
        .collect()
}

Am I not seeing something, or maybe is this how they are actually supposed to be?