Sending the IQM file into nom
parent
90484feee5
commit
8b25b2fadd
43
src/main.rs
43
src/main.rs
|
@ -11,13 +11,48 @@ use sdl2::keyboard::Keycode;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::ffi::{c_void, CStr, CString};
|
use std::ffi::{c_void, CStr, CString};
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::Read;
|
||||||
|
use std::path::Path;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
pub fn parse_iqm (input: &str) -> IResult<&str, ()> {
|
pub fn parse_iqm (input: &[u8]) -> IResult<&[u8], ()> {
|
||||||
let (input, _) = tag("#")(input)?;
|
let (input, _) = tag (b"INTERQUAKEMODEL\0")(input)?;
|
||||||
Ok ((input, ()))
|
Ok ((input, ()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct IqmBuffer {
|
||||||
|
data: Vec <u8>,
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load_small_file <P> (name: P) -> Vec <u8>
|
||||||
|
where P: AsRef <Path>
|
||||||
|
{
|
||||||
|
let mut f = File::open (name).unwrap ();
|
||||||
|
let len = f.metadata ().unwrap ().len ();
|
||||||
|
|
||||||
|
if len > 1024 * 1024 {
|
||||||
|
panic! ("File is too big");
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut data = vec! [0u8; len.try_into ().unwrap ()];
|
||||||
|
|
||||||
|
f.read (&mut data [..]).unwrap ();
|
||||||
|
|
||||||
|
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
|
||||||
|
@ -326,6 +361,8 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn iqm () {
|
pub fn iqm () {
|
||||||
assert_eq! (parse_iqm ("#"), Ok (("", ())));
|
assert_eq! (parse_iqm (b"INTERQUAKEMODEL\0"), Ok ((&b"" [..], ())));
|
||||||
|
|
||||||
|
IqmBuffer::from_buffer (load_small_file ("pumpking.iqm"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue