1
0
Fork 0
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:
Quaternions 2025-02-16 14:12:16 -08:00
commit d0a1666539
2 changed files with 9 additions and 19 deletions

View file

@ -11,23 +11,8 @@ pub struct BspFile<'a> {
impl<'a> BspFile<'a> {
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 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()?;
Ok(BspFile {

View file

@ -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)]
#[br(little)]
pub struct Header {
pub v: u8,
pub b: u8,
pub s: u8,
pub p: u8,
#[brw(magic = b"VBSP")]
pub version: BspVersion,
}
#[derive(Clone, Copy, Debug, Default, BinRead)]