Parsing a few header fields from nom
parent
8b25b2fadd
commit
52e1b71038
44
src/main.rs
44
src/main.rs
|
@ -1,8 +1,7 @@
|
||||||
use nom::{
|
use nom::{
|
||||||
IResult,
|
IResult,
|
||||||
bytes::complete::{tag, take_while_m_n},
|
bytes::complete::{tag},
|
||||||
combinator::map_res,
|
number::complete::{le_u32},
|
||||||
sequence::tuple
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use sdl2::event::Event;
|
use sdl2::event::Event;
|
||||||
|
@ -16,14 +15,27 @@ use std::io::Read;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
pub fn parse_iqm (input: &[u8]) -> IResult<&[u8], ()> {
|
pub struct Iqm {
|
||||||
let (input, _) = tag (b"INTERQUAKEMODEL\0")(input)?;
|
version: u32,
|
||||||
Ok ((input, ()))
|
filesize: u32,
|
||||||
|
flags: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct IqmBuffer {
|
pub fn parse_iqm (input: &[u8]) -> IResult<&[u8], Iqm> {
|
||||||
data: Vec <u8>,
|
let (input, _) = tag (b"INTERQUAKEMODEL\0")(input)?;
|
||||||
|
let (input, version) = le_u32 (input)?;
|
||||||
|
|
||||||
|
// I only know how to parse version 2
|
||||||
|
assert_eq! (version, 2);
|
||||||
|
|
||||||
|
let (input, filesize) = le_u32 (input)?;
|
||||||
|
let (input, flags) = le_u32 (input)?;
|
||||||
|
|
||||||
|
Ok ((input, Iqm {
|
||||||
|
version,
|
||||||
|
filesize,
|
||||||
|
flags,
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_small_file <P> (name: P) -> Vec <u8>
|
pub fn load_small_file <P> (name: P) -> Vec <u8>
|
||||||
|
@ -43,16 +55,6 @@ where P: AsRef <Path>
|
||||||
data
|
data
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IqmBuffer {
|
|
||||||
pub fn from_buffer (data: Vec <u8>) -> IqmBuffer {
|
|
||||||
assert_eq! (parse_iqm (&data [..]), Ok ((&data [16..], ())));
|
|
||||||
|
|
||||||
IqmBuffer {
|
|
||||||
data,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const VERT_SHADER_SRC: &str =
|
const VERT_SHADER_SRC: &str =
|
||||||
"
|
"
|
||||||
#define lowp
|
#define lowp
|
||||||
|
@ -361,8 +363,10 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn iqm () {
|
pub fn iqm () {
|
||||||
assert_eq! (parse_iqm (b"INTERQUAKEMODEL\0"), Ok ((&b"" [..], ())));
|
let data = load_small_file ("pumpking.iqm");
|
||||||
|
let model = parse_iqm (&data [..]).unwrap ().1;
|
||||||
|
|
||||||
IqmBuffer::from_buffer (load_small_file ("pumpking.iqm"));
|
assert_eq! (model.filesize, 90368);
|
||||||
|
assert_eq! (model.flags, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue