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

Merge pull request #12 from krakow10/proplump5

StaticPropLumpV5 + V4
This commit is contained in:
Robin Appelman 2025-02-21 14:51:39 +01:00 committed by GitHub
commit d586ad882f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 84 deletions

View file

@ -5,7 +5,6 @@ use bitflags::bitflags;
use cgmath::Quaternion; use cgmath::Quaternion;
use std::borrow::Cow; use std::borrow::Cow;
use std::io::{Cursor, Read, Seek}; use std::io::{Cursor, Read, Seek};
use std::mem::size_of;
#[derive(Debug, Clone, BinRead)] #[derive(Debug, Clone, BinRead)]
pub struct GameLumpHeader { pub struct GameLumpHeader {
@ -118,7 +117,7 @@ pub struct StaticPropLumps {
pub props: Vec<StaticPropLump>, pub props: Vec<StaticPropLump>,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone, Default)]
pub struct StaticPropLump { pub struct StaticPropLump {
pub origin: Vector, pub origin: Vector,
angles: Angles, angles: Angles,
@ -153,8 +152,9 @@ impl BinRead for StaticPropLump {
args: Self::Args<'static>, args: Self::Args<'static>,
) -> BinResult<Self> { ) -> BinResult<Self> {
match args.0 { match args.0 {
6 => StaticPropLumpV6::read_options(reader, endian, ()).map(StaticPropLump::from), 4..=7 | 10 => {
7 | 10 => StaticPropLumpV10::read_options(reader, endian, ()).map(StaticPropLump::from), RawStaticPropLump::read_options(reader, endian, (args.0,)).map(StaticPropLump::from)
}
version => Err(binrw::Error::Custom { version => Err(binrw::Error::Custom {
err: Box::new(UnsupportedLumpVersion { err: Box::new(UnsupportedLumpVersion {
lump_type: "static props", lump_type: "static props",
@ -166,7 +166,7 @@ impl BinRead for StaticPropLump {
} }
} }
#[derive(BinRead, Debug, Clone, Copy)] #[derive(BinRead, Debug, Clone, Copy, Default)]
pub struct StaticPropLumpFlags(u32); pub struct StaticPropLumpFlags(u32);
bitflags! { bitflags! {
@ -184,9 +184,10 @@ bitflags! {
} }
#[repr(u8)] #[repr(u8)]
#[derive(BinRead, Debug, Copy, Clone)] #[derive(BinRead, Debug, Copy, Clone, Default)]
#[br(repr = u8)] #[br(repr = u8)]
pub enum SolidType { pub enum SolidType {
#[default]
None = 0, None = 0,
Bsp, Bsp,
Bbox, Bbox,
@ -197,82 +198,40 @@ pub enum SolidType {
Last, Last,
} }
impl From<StaticPropLumpFlagsV6> for StaticPropLumpFlags { // same as StaticPropLump but with derived BinRead, needs to be normalized first
fn from(v6: StaticPropLumpFlagsV6) -> Self {
StaticPropLumpFlags::from_bits_truncate(v6.bits().into())
}
}
#[derive(BinRead)] #[derive(BinRead)]
struct StaticPropLumpV6 { #[br(import(version: u16))]
struct RawStaticPropLump {
pub origin: Vector, pub origin: Vector,
pub angles: Angles, pub angles: Angles,
pub prop_type: u16, pub prop_type: u16,
pub first_leaf: u16, pub first_leaf: u16,
pub leaf_count: u16, pub leaf_count: u16,
pub solid: SolidType, pub solid: SolidType,
pub flags: StaticPropLumpFlagsV6, pub flags_u8: u8,
pub skin: i32,
pub fade_min_distance: f32,
pub fade_max_distance: f32,
pub lighting_origin: Vector,
pub forced_fade_scale: f32,
pub min_dx_level: u16,
pub max_dx_level: u16,
}
#[test]
fn test_static_prop_lump_v6_bytes() {
super::test_read_bytes::<StaticPropLumpV6>();
}
#[derive(BinRead, Debug, Clone, Copy)]
struct StaticPropLumpFlagsV6(u8);
bitflags! {
impl StaticPropLumpFlagsV6: u8 {
const FLAG_FADES = 0x1;
const USE_LIGHTING_ORIGIN = 0x2;
const NO_DRAW = 0x4;
const IGNORE_NORMALS = 0x8;
const NO_SHADOW = 0x10;
const SCREEN_SPACE_FADE = 0x20;
const NO_PER_VERTEX_LIGHTING = 0x40;
const NO_SELF_SHADOWING = 0x80;
}
}
// same as StaticPropLump but with derived BinRead
#[derive(BinRead)]
struct StaticPropLumpV10 {
pub origin: Vector,
pub angles: Angles,
pub prop_type: u16,
pub first_leaf: u16,
pub leaf_count: u16,
// pad, not align
#[br(pad_after = 1)]
pub solid: SolidType,
pub skin: i32, pub skin: i32,
pub fade_min_distance: f32, pub fade_min_distance: f32,
pub fade_max_distance: f32, pub fade_max_distance: f32,
pub lighting_origin: Vector, pub lighting_origin: Vector,
#[br(if(version >= 5))]
pub forced_fade_scale: f32, pub forced_fade_scale: f32,
#[br(if(version >= 6))]
pub min_dx_level: u16, pub min_dx_level: u16,
#[br(if(version >= 6))]
pub max_dx_level: u16, pub max_dx_level: u16,
#[br(if(version >= 7))]
pub flags: StaticPropLumpFlags, pub flags: StaticPropLumpFlags,
#[br(if(version >= 7))]
pub lightmap_resolution: [u16; 2], pub lightmap_resolution: [u16; 2],
} }
#[test] #[test]
fn test_static_prop_lump_bytes() { fn test_static_prop_lump_bytes() {
super::test_read_bytes::<StaticPropLumpV10>(); super::test_read_bytes::<RawStaticPropLump>();
} }
static_assertions::const_assert_eq!(size_of::<StaticPropLumpV10>(), size_of::<StaticPropLump>()); impl From<RawStaticPropLump> for StaticPropLump {
fn from(from: RawStaticPropLump) -> Self {
impl From<StaticPropLumpV6> for StaticPropLump {
fn from(from: StaticPropLumpV6) -> Self {
StaticPropLump { StaticPropLump {
origin: from.origin, origin: from.origin,
angles: from.angles, angles: from.angles,
@ -287,29 +246,7 @@ impl From<StaticPropLumpV6> for StaticPropLump {
forced_fade_scale: from.forced_fade_scale, forced_fade_scale: from.forced_fade_scale,
min_dx_level: from.min_dx_level, min_dx_level: from.min_dx_level,
max_dx_level: from.max_dx_level, max_dx_level: from.max_dx_level,
flags: from.flags.into(), flags: StaticPropLumpFlags(from.flags_u8.into()) | from.flags,
lightmap_resolution: Default::default(),
}
}
}
impl From<StaticPropLumpV10> for StaticPropLump {
fn from(from: StaticPropLumpV10) -> Self {
StaticPropLump {
origin: from.origin,
angles: from.angles,
prop_type: from.prop_type,
first_leaf: from.first_leaf,
leaf_count: from.leaf_count,
solid: from.solid,
skin: from.skin,
fade_min_distance: from.fade_min_distance,
fade_max_distance: from.fade_max_distance,
lighting_origin: from.lighting_origin,
forced_fade_scale: from.forced_fade_scale,
min_dx_level: from.min_dx_level,
max_dx_level: from.max_dx_level,
flags: from.flags,
lightmap_resolution: from.lightmap_resolution, lightmap_resolution: from.lightmap_resolution,
} }
} }

View file

@ -542,7 +542,7 @@ where
}) })
} }
#[derive(Debug, Copy, Clone, BinRead)] #[derive(Debug, Copy, Clone, BinRead, Default)]
pub struct Angles { pub struct Angles {
pitch: f32, pitch: f32,
yaw: f32, yaw: f32,