mirror of
https://codeberg.org/icewind/vbsp.git
synced 2026-06-03 18:54:05 +02:00
validate internal references on parse
This commit is contained in:
parent
d1c9087c37
commit
db738c5eb3
6 changed files with 157 additions and 40 deletions
|
|
@ -51,6 +51,12 @@ pub struct DisplacementNeighbour {
|
|||
pub sub_neighbours: [Option<DisplacementSubNeighbour>; 2],
|
||||
}
|
||||
|
||||
impl DisplacementNeighbour {
|
||||
pub fn iter(&self) -> impl Iterator<Item = &DisplacementSubNeighbour> {
|
||||
self.sub_neighbours.iter().filter_map(Option::as_ref)
|
||||
}
|
||||
}
|
||||
|
||||
impl BinRead for DisplacementNeighbour {
|
||||
type Args = ();
|
||||
|
||||
|
|
@ -133,9 +139,18 @@ pub enum NeighbourOrientation {
|
|||
|
||||
#[derive(Debug, Clone, BinRead)]
|
||||
pub struct DisplacementCornerNeighbour {
|
||||
pub neighbours: [u16; 4],
|
||||
neighbours: [u16; 4],
|
||||
#[br(align_after = align_of::< DisplacementCornerNeighbour > ())]
|
||||
pub neighbour_count: u8,
|
||||
neighbour_count: u8,
|
||||
}
|
||||
|
||||
impl DisplacementCornerNeighbour {
|
||||
pub fn neighbours(&self) -> impl Iterator<Item = u16> + '_ {
|
||||
self.neighbours
|
||||
.iter()
|
||||
.copied()
|
||||
.take(self.neighbour_count as usize)
|
||||
}
|
||||
}
|
||||
|
||||
static_assertions::const_assert_eq!(size_of::<DisplacementCornerNeighbour>(), 10);
|
||||
|
|
|
|||
|
|
@ -405,8 +405,8 @@ pub struct SurfaceEdge {
|
|||
}
|
||||
|
||||
impl SurfaceEdge {
|
||||
pub fn edge_index(&self) -> usize {
|
||||
self.edge.abs() as usize
|
||||
pub fn edge_index(&self) -> u32 {
|
||||
self.edge.abs() as u32
|
||||
}
|
||||
|
||||
pub fn direction(&self) -> EdgeDirection {
|
||||
|
|
@ -439,6 +439,12 @@ pub struct Face {
|
|||
pub smoothing_groups: u32,
|
||||
}
|
||||
|
||||
impl Face {
|
||||
pub fn displacement_index(&self) -> Option<i16> {
|
||||
(self.displacement_info >= 0).then(|| self.displacement_info)
|
||||
}
|
||||
}
|
||||
|
||||
static_assertions::const_assert_eq!(size_of::<Face>(), 56);
|
||||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue