1
0
Fork 0
mirror of https://codeberg.org/icewind/vbsp.git synced 2026-06-03 10:44:07 +02:00

add LeafV0

This commit is contained in:
Quaternions 2025-02-17 18:28:10 -08:00 committed by Robin Appelman
commit 1bc218ab6a

View file

@ -50,6 +50,7 @@ impl BinRead for Leaves {
args: Self::Args<'_>, args: Self::Args<'_>,
) -> BinResult<Self> { ) -> BinResult<Self> {
let item_size = match args.version { let item_size = match args.version {
0 => size_of::<LeafV0>(),
1 => size_of::<LeafV1>(), 1 => size_of::<LeafV1>(),
version => { version => {
return Err(binrw::Error::Custom { return Err(binrw::Error::Custom {
@ -202,6 +203,43 @@ pub struct CompressedLightCube {
pub color: [ColorRGBExp32; 6], pub color: [ColorRGBExp32; 6],
} }
#[derive(Default, Debug, Clone, BinRead)]
pub struct LeafV0 {
pub contents: i32,
pub cluster: i16,
pub area_and_flags: i16,
// first 9 bits is area, last 7 bits is flags
pub mins: [i16; 3],
pub maxs: [i16; 3],
pub first_leaf_face: u16,
pub leaf_face_count: u16,
pub first_leaf_brush: u16,
pub leaf_brush_count: u16,
pub leaf_watter_data_id: i16,
#[br(align_after = align_of::< LeafV0 > ())]
pub cube: CompressedLightCube,
}
static_assertions::const_assert_eq!(size_of::<LeafV0>(), 56);
impl From<LeafV0> for Leaf {
fn from(value: LeafV0) -> Self {
Self {
contents: value.contents,
cluster: value.cluster,
area_and_flags: value.area_and_flags,
mins: value.mins,
maxs: value.maxs,
first_leaf_face: value.first_leaf_face,
leaf_face_count: value.leaf_face_count,
first_leaf_brush: value.first_leaf_brush,
leaf_brush_count: value.leaf_brush_count,
leaf_watter_data_id: value.leaf_watter_data_id,
cube: value.cube,
}
}
}
#[derive(Default, Debug, Clone, BinRead)] #[derive(Default, Debug, Clone, BinRead)]
pub struct LeafV1 { pub struct LeafV1 {
pub contents: i32, pub contents: i32,
@ -275,6 +313,7 @@ impl BinRead for Leaf {
args: Self::Args<'_>, args: Self::Args<'_>,
) -> BinResult<Self> { ) -> BinResult<Self> {
match args.version { match args.version {
0 => LeafV0::read_options(reader, endian, ()).map(Leaf::from),
1 => LeafV1::read_options(reader, endian, ()).map(Leaf::from), 1 => LeafV1::read_options(reader, endian, ()).map(Leaf::from),
version => Err(binrw::Error::Custom { version => Err(binrw::Error::Custom {
err: Box::new(crate::error::UnsupportedLumpVersion { err: Box::new(crate::error::UnsupportedLumpVersion {