strafe-project/lib/bsp_loader/src/lib.rs

37 lines
920 B
Rust
Raw Normal View History

mod bsp;
2024-02-15 01:11:41 +00:00
pub mod data;
2024-02-15 01:11:41 +00:00
pub use data::Bsp;
#[derive(Debug)]
pub enum ReadError{
Bsp(vbsp::BspError),
Io(std::io::Error),
}
impl std::fmt::Display for ReadError{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"{self:?}")
}
}
impl std::error::Error for ReadError{}
pub fn read<R:std::io::Read>(mut input:R)->Result<Bsp,ReadError>{
let mut s=Vec::new();
//TODO: mmap
input.read_to_end(&mut s).map_err(ReadError::Io)?;
2024-02-15 01:11:41 +00:00
vbsp::Bsp::read(s.as_slice()).map(Bsp::new).map_err(ReadError::Bsp)
}
2024-02-15 01:11:41 +00:00
pub fn convert<AcquireRenderConfigId,AcquireMeshId>(
bsp:&Bsp,
acquire_render_config_id:AcquireRenderConfigId,
acquire_mesh_id:AcquireMeshId
2024-02-15 01:11:41 +00:00
)->bsp::PartialMap1
where
2024-02-15 01:11:41 +00:00
AcquireRenderConfigId:FnMut(Option<&str>)->strafesnet_common::model::RenderConfigId,
AcquireMeshId:FnMut(&str)->strafesnet_common::model::MeshId,
{
2024-02-15 01:11:41 +00:00
bsp::convert_bsp(bsp.as_ref(),acquire_render_config_id,acquire_mesh_id)
}