1
0
Fork 0
mirror of https://codeberg.org/icewind/vbsp.git synced 2026-06-03 18:54:05 +02:00

update dependencies

This commit is contained in:
Robin Appelman 2023-11-12 00:11:26 +01:00
commit b9177ea51b
6 changed files with 165 additions and 112 deletions

View file

@ -1,7 +1,7 @@
use super::vector::Vector;
use crate::data::try_read_enum;
use crate::error::InvalidNeighbourError;
use binrw::{BinRead, BinResult, ReadOptions};
use binrw::{BinRead, BinResult, Endian};
use bitflags::bitflags;
use num_enum::TryFromPrimitive;
use std::fmt::Debug;
@ -60,17 +60,17 @@ impl DisplacementNeighbour {
}
impl BinRead for DisplacementNeighbour {
type Args = ();
type Args<'a> = ();
fn read_options<R: Read + Seek>(
reader: &mut R,
options: &ReadOptions,
args: Self::Args,
endian: Endian,
args: Self::Args<'_>,
) -> BinResult<Self> {
Ok(DisplacementNeighbour {
sub_neighbours: [
read_option_sub_neighbour(reader, options, args)?,
read_option_sub_neighbour(reader, options, args)?,
read_option_sub_neighbour(reader, endian, args)?,
read_option_sub_neighbour(reader, endian, args)?,
],
})
}
@ -78,10 +78,10 @@ impl BinRead for DisplacementNeighbour {
fn read_option_sub_neighbour<R: Read + Seek>(
reader: &mut R,
options: &ReadOptions,
endian: Endian,
args: (),
) -> BinResult<Option<DisplacementSubNeighbour>> {
let neighbour_index = u16::read_options(reader, options, args)?;
let neighbour_index = u16::read_options(reader, endian, args)?;
// for non-connected sub-neighbours, the orientations and spans sometimes contain garbage
// so we just skip over it
@ -93,7 +93,7 @@ fn read_option_sub_neighbour<R: Read + Seek>(
} else {
reader.seek(SeekFrom::Current(-2))?;
Ok(Some(DisplacementSubNeighbour::read_options(
reader, options, args,
reader, endian, args,
)?))
}
}
@ -134,16 +134,16 @@ pub enum NeighbourSpan {
}
impl BinRead for NeighbourSpan {
type Args = ();
type Args<'a> = ();
fn read_options<R: Read + Seek>(
reader: &mut R,
options: &ReadOptions,
args: Self::Args,
endian: Endian,
args: Self::Args<'_>,
) -> BinResult<Self> {
try_read_enum(
reader,
options,
endian,
args,
InvalidNeighbourError::InvalidNeighbourSpan,
)
@ -160,16 +160,16 @@ pub enum NeighbourOrientation {
}
impl BinRead for NeighbourOrientation {
type Args = ();
type Args<'a> = ();
fn read_options<R: Read + Seek>(
reader: &mut R,
options: &ReadOptions,
args: Self::Args,
endian: Endian,
args: Self::Args<'static>,
) -> BinResult<Self> {
try_read_enum(
reader,
options,
endian,
args,
InvalidNeighbourError::InvalidNeighbourOrientation,
)
@ -217,9 +217,11 @@ pub struct DisplacementTriangle {
pub tags: DisplacementTriangleFlags,
}
#[derive(BinRead, Debug, Clone, Copy)]
pub struct DisplacementTriangleFlags(u8);
bitflags! {
#[derive(BinRead)]
pub struct DisplacementTriangleFlags: u8 {
impl DisplacementTriangleFlags: u8 {
const SURFACE = 0x01;
const WALKABLE = 0x02;
const BULDABLE = 0x04;

View file

@ -1,6 +1,6 @@
use crate::error::UnsupportedLumpVersion;
use crate::{lzma_decompress_with_header, BspError, FixedString, Vector};
use binrw::{BinRead, BinReaderExt, BinResult, ReadOptions};
use binrw::{BinRead, BinReaderExt, BinResult, Endian};
use bitflags::bitflags;
use cgmath::{Deg, Quaternion, Rotation3};
use std::borrow::Cow;
@ -15,7 +15,10 @@ pub struct GameLumpHeader {
}
impl GameLumpHeader {
pub fn find<T: GameLumpType<Args = (u16,)>>(&self, data: &[u8]) -> Option<Result<T, BspError>> {
pub fn find<T: GameLumpType<Args<'static> = (u16,)>>(
&self,
data: &[u8],
) -> Option<Result<T, BspError>> {
let (i, lump) = self
.lumps
.iter()
@ -67,9 +70,11 @@ pub struct GameLump {
pub length: i32,
}
#[derive(BinRead, Debug, Clone, Copy)]
pub struct GameLumpFlags(u16);
bitflags! {
#[derive(BinRead)]
pub struct GameLumpFlags: u16 {
impl GameLumpFlags: u16 {
const COMPRESSED = 0b0000_0000_0000_0000_0001;
}
}
@ -143,18 +148,16 @@ impl StaticPropLump {
}
impl BinRead for StaticPropLump {
type Args = (u16,);
type Args<'a> = (u16,);
fn read_options<R: Read + Seek>(
reader: &mut R,
options: &ReadOptions,
args: Self::Args,
endian: Endian,
args: Self::Args<'static>,
) -> BinResult<Self> {
match args.0 {
6 => StaticPropLumpV6::read_options(reader, options, ()).map(StaticPropLump::from),
7 | 10 => {
StaticPropLumpV10::read_options(reader, options, ()).map(StaticPropLump::from)
}
6 => StaticPropLumpV6::read_options(reader, endian, ()).map(StaticPropLump::from),
7 | 10 => StaticPropLumpV10::read_options(reader, endian, ()).map(StaticPropLump::from),
version => Err(binrw::Error::Custom {
err: Box::new(UnsupportedLumpVersion {
lump_type: "static props",
@ -166,13 +169,15 @@ impl BinRead for StaticPropLump {
}
}
#[derive(BinRead, Debug, Clone, Copy)]
pub struct StaticPropLumpFlags(u32);
bitflags! {
#[derive(BinRead)]
pub struct StaticPropLumpFlags: u32 {
const FLAG_FADES = 0x1;
const USE_LIGHTING_ORIGIN = 0x2;
impl StaticPropLumpFlags: u32 {
const FLAG_FADES = 0x1;
const USE_LIGHTING_ORIGIN = 0x2;
const NO_DRAW = 0x4;
const IGNORE_NORMALS = 0x8;
const IGNORE_NORMALS = 0x8;
const NO_SHADOW = 0x10;
const SCREEN_SPACE_FADE = 0x20;
const NO_PER_VERTEX_LIGHTING = 0x40;
@ -224,9 +229,11 @@ fn test_static_prop_lump_v6_bytes() {
super::test_read_bytes::<StaticPropLumpV6>();
}
#[derive(BinRead, Debug, Clone, Copy)]
struct StaticPropLumpFlagsV6(u8);
bitflags! {
#[derive(BinRead)]
struct StaticPropLumpFlagsV6: u8 {
impl StaticPropLumpFlagsV6: u8 {
const FLAG_FADES = 0x1;
const USE_LIGHTING_ORIGIN = 0x2;
const NO_DRAW = 0x4;

View file

@ -11,10 +11,10 @@ use crate::bspfile::LumpType;
use crate::{BspResult, StringError};
use arrayvec::ArrayString;
use binrw::error::CustomError;
use binrw::{BinRead, BinResult, ReadOptions};
use binrw::{BinRead, BinResult, Endian};
use bitflags::bitflags;
use bv::BitVec;
use num_enum::TryFromPrimitive;
use num_enum::{TryFromPrimitive, TryFromPrimitiveError};
use std::borrow::Cow;
use std::cmp::min;
use std::fmt;
@ -30,7 +30,8 @@ use zip::ZipArchive;
#[cfg(test)]
fn test_read_bytes<T: BinRead>()
where
T::Args: Default,
T::Args<'static>: Default,
<T as BinRead>::Args<'static>: Clone,
{
use binrw::BinReaderExt;
use std::any::type_name;
@ -84,9 +85,11 @@ pub struct LeafFace {
pub face: u16,
}
#[derive(BinRead, Debug, Clone, Copy)]
pub struct TextureFlags(u32);
bitflags! {
#[derive(BinRead)]
pub struct TextureFlags: u32 {
impl TextureFlags: u32 {
const LIGHT = 0b0000_0000_0000_0000_0001; // value will hold the light strength
const SKY2D = 0b0000_0000_0000_0000_0010; // don't draw, indicate we should skylight + draw 2d sky but don't draw the 3d skybox
const SKY = 0b0000_0000_0000_0000_0100; // don't draw, but add the skybox
@ -129,18 +132,18 @@ impl<const LEN: usize> Display for FixedString<LEN> {
}
impl<const LEN: usize> BinRead for FixedString<LEN> {
type Args = ();
type Args<'a> = ();
fn read_options<R: Read + binrw::io::Seek>(
reader: &mut R,
options: &ReadOptions,
args: Self::Args,
endian: Endian,
args: Self::Args<'static>,
) -> BinResult<Self> {
use std::str;
let start = reader.stream_position().unwrap();
let name_buf = <[u8; LEN]>::read_options(reader, options, args)?;
let name_buf = <[u8; LEN]>::read_options(reader, endian, args)?;
let zero_pos =
name_buf
@ -269,9 +272,11 @@ impl Brush {
}
}
#[derive(BinRead, Debug, Clone, Copy)]
pub struct BrushFlags(u32);
bitflags! {
#[derive(BinRead)]
pub struct BrushFlags: u32 {
impl BrushFlags: u32 {
const EMPTY = 0; // No contents
const SOLID = 0x1; // an eye is never valid in a solid
const WINDOW = 0x2; // translucent, but not watery (glass)
@ -475,19 +480,19 @@ impl Packfile {
fn try_read_enum<Enum, Reader, Error, ErrorFn>(
reader: &mut Reader,
options: &ReadOptions,
args: <<Enum as TryFromPrimitive>::Primitive as BinRead>::Args,
endian: Endian,
args: <<Enum as TryFromPrimitive>::Primitive as BinRead>::Args<'static>,
err_map: ErrorFn,
) -> BinResult<Enum>
where
Reader: Read + Seek,
Enum: TryFromPrimitive,
Enum: TryFromPrimitive<Error = TryFromPrimitiveError<Enum>>,
Enum::Primitive: BinRead,
ErrorFn: FnOnce(Enum::Primitive) -> Error,
Error: CustomError + 'static,
{
let start = reader.stream_position().unwrap();
let raw = <Enum::Primitive>::read_options(reader, options, args)?;
let raw = <Enum::Primitive>::read_options(reader, endian, args)?;
Enum::try_from_primitive(raw)
.map_err(|e| err_map(e.number))