mirror of
https://codeberg.org/icewind/vbsp.git
synced 2026-06-03 18:54:05 +02:00
fold BspVersion into Header, use binrw magic for FourCC
This commit is contained in:
parent
f0c226044d
commit
d0a1666539
2 changed files with 9 additions and 19 deletions
|
|
@ -11,23 +11,8 @@ pub struct BspFile<'a> {
|
||||||
|
|
||||||
impl<'a> BspFile<'a> {
|
impl<'a> BspFile<'a> {
|
||||||
pub fn new(data: &'a [u8]) -> BspResult<Self> {
|
pub fn new(data: &'a [u8]) -> BspResult<Self> {
|
||||||
const EXPECTED_HEADER: Header = Header {
|
|
||||||
v: b'V',
|
|
||||||
b: b'B',
|
|
||||||
s: b'S',
|
|
||||||
p: b'P',
|
|
||||||
};
|
|
||||||
// TODO: Use this to decide on the version to parse it as
|
|
||||||
const EXPECTED_VERSION: u32 = 0x14;
|
|
||||||
|
|
||||||
let mut cursor = Cursor::new(data);
|
let mut cursor = Cursor::new(data);
|
||||||
let header: Header = cursor.read_le()?;
|
let header: Header = cursor.read_le()?;
|
||||||
let version: u32 = cursor.read_le()?;
|
|
||||||
|
|
||||||
if header != EXPECTED_HEADER || version != EXPECTED_VERSION {
|
|
||||||
return Err(BspError::UnexpectedHeader(header));
|
|
||||||
}
|
|
||||||
|
|
||||||
let directories = cursor.read_le()?;
|
let directories = cursor.read_le()?;
|
||||||
|
|
||||||
Ok(BspFile {
|
Ok(BspFile {
|
||||||
|
|
|
||||||
|
|
@ -69,13 +69,18 @@ impl Index<LumpType> for Directories {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, BinRead)]
|
||||||
|
#[br(little)]
|
||||||
|
#[brw(repr=u32)]
|
||||||
|
pub enum BspVersion {
|
||||||
|
Version20 = 20,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, BinRead)]
|
#[derive(Debug, Clone, PartialEq, Eq, BinRead)]
|
||||||
#[br(little)]
|
#[br(little)]
|
||||||
pub struct Header {
|
pub struct Header {
|
||||||
pub v: u8,
|
#[brw(magic = b"VBSP")]
|
||||||
pub b: u8,
|
pub version: BspVersion,
|
||||||
pub s: u8,
|
|
||||||
pub p: u8,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default, BinRead)]
|
#[derive(Clone, Copy, Debug, Default, BinRead)]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue