maraiah: use Read for sound files

master
an 2019-06-23 07:35:51 -04:00
parent 5eb8962d2d
commit 2dd4762c2e
2 changed files with 12 additions and 8 deletions

View File

@ -4,13 +4,16 @@ pub mod defs;
pub mod snds;
use crate::{bin::Ident, err::*};
use std::collections::BTreeMap;
use std::{collections::BTreeMap, io::prelude::*};
/// Reads all sounds from a Sound file.
pub fn read(b: &[u8]) -> ResultS<Vec<SoundTable>>
pub fn read(fp: &mut impl Read) -> ResultS<Vec<SoundTable>>
{
let mut b = Vec::new();
fp.read_to_end(&mut b)?;
read_data! {
endian: BIG, buf: b, size: 260, start: 0, data {
endian: BIG, buf: &b, size: 260, start: 0, data {
let version = u32[0];
let magic = Ident[4];
let src_num = u16[8] usize;
@ -23,9 +26,10 @@ pub fn read(b: &[u8]) -> ResultS<Vec<SoundTable>>
}
let mut sc = Vec::with_capacity(src_num);
let mut p = 260;
for _ in 0..src_num {
for i in 0..src_num {
let p = 260 + i * 64;
let mut st = SoundTable::new();
for _ in 0..snd_num {
@ -36,8 +40,6 @@ pub fn read(b: &[u8]) -> ResultS<Vec<SoundTable>>
st.insert(idx, def);
}
p += 64;
}
sc.push(st);

View File

@ -8,7 +8,9 @@ fn snd_must_not_process()
for inp in &RANDOM {
assert!(snd::defs::read(inp).is_err());
assert!(snd::snds::read(inp).is_err());
assert!(snd::read(inp).is_err());
let mut inp = std::io::BufReader::new(&inp[..]);
assert!(snd::read(&mut inp).is_err());
}
}