From 4863605af7a268091a09cdcbefd2bea0e21534c8 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 29 Jul 2024 17:11:40 -0700 Subject: [PATCH] source and roblox map loading feature flags --- Cargo.toml | 10 +++++++--- src/file.rs | 8 ++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1343216..4508ddf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,10 @@ description = "StrafesNET game client for bhop and surf." authors = ["Rhys Lloyd "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +default = [] +source = ["dep:strafesnet_deferred_loader", "dep:strafesnet_bsp_loader"] +roblox = ["dep:strafesnet_deferred_loader", "dep:strafesnet_rbx_loader"] [dependencies] bytemuck = { version = "1.13.1", features = ["derive"] } @@ -17,10 +21,10 @@ glam = "0.28.0" id = { version = "0.1.0", registry = "strafesnet" } parking_lot = "0.12.1" pollster = "0.3.0" -strafesnet_bsp_loader = { version = "0.1.3", registry = "strafesnet" } +strafesnet_bsp_loader = { version = "0.1.3", registry = "strafesnet", optional = true } strafesnet_common = { version = "0.2.0", registry = "strafesnet" } -strafesnet_deferred_loader = { version = "0.3.1", features = ["legacy"], registry = "strafesnet" } -strafesnet_rbx_loader = { version = "0.3.2", registry = "strafesnet" } +strafesnet_deferred_loader = { version = "0.3.1", features = ["legacy"], registry = "strafesnet", optional = true } +strafesnet_rbx_loader = { version = "0.3.2", registry = "strafesnet", optional = true } strafesnet_snf = { version = "0.1.0", registry = "strafesnet" } wgpu = "22.0.0" winit = "0.30.4" diff --git a/src/file.rs b/src/file.rs index 8262949..affb652 100644 --- a/src/file.rs +++ b/src/file.rs @@ -2,7 +2,9 @@ use std::io::Read; #[derive(Debug)] pub enum ReadError{ + #[cfg(feature="roblox")] Roblox(strafesnet_rbx_loader::ReadError), + #[cfg(feature="source")] Source(strafesnet_bsp_loader::ReadError), StrafesNET(strafesnet_snf::Error), StrafesNETMap(strafesnet_snf::map::Error), @@ -17,7 +19,9 @@ impl std::fmt::Display for ReadError{ impl std::error::Error for ReadError{} pub enum DataStructure{ + #[cfg(feature="roblox")] Roblox(strafesnet_rbx_loader::Dom), + #[cfg(feature="source")] Source(strafesnet_bsp_loader::Bsp), StrafesNET(strafesnet_common::map::CompleteMap), } @@ -26,7 +30,9 @@ pub fn read(input:R)->Result{ let mut buf=std::io::BufReader::new(input); let peek=std::io::BufRead::fill_buf(&mut buf).map_err(ReadError::Io)?; match &peek[0..4]{ + #[cfg(feature="roblox")] b"Ok(DataStructure::Roblox(strafesnet_rbx_loader::read(buf).map_err(ReadError::Roblox)?)), + #[cfg(feature="source")] b"VBSP"=>Ok(DataStructure::Source(strafesnet_bsp_loader::read(buf).map_err(ReadError::Source)?)), b"SNFM"=>Ok(DataStructure::StrafesNET( strafesnet_snf::read_map(buf).map_err(ReadError::StrafesNET)? @@ -54,6 +60,7 @@ pub fn load>(path:P)->ResultOk(map), + #[cfg(feature="roblox")] DataStructure::Roblox(dom)=>{ let mut loader=strafesnet_deferred_loader::roblox_legacy(); @@ -86,6 +93,7 @@ pub fn load>(path:P)->Result{ let mut loader=strafesnet_deferred_loader::source_legacy();