2024-02-14 02:02:32 +00:00
|
|
|
mod bsp;
|
2024-02-15 01:11:41 +00:00
|
|
|
pub mod data;
|
2024-02-14 02:02:32 +00:00
|
|
|
|
2024-02-15 01:11:41 +00:00
|
|
|
pub use data::Bsp;
|
2024-02-14 02:02:32 +00:00
|
|
|
|
|
|
|
#[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-14 02:02:32 +00:00
|
|
|
}
|
|
|
|
|
2024-02-15 01:11:41 +00:00
|
|
|
pub fn convert<AcquireRenderConfigId,AcquireMeshId>(
|
2024-02-14 02:02:32 +00:00
|
|
|
bsp:&Bsp,
|
2024-02-15 09:41:26 +00:00
|
|
|
acquire_render_config_id:AcquireRenderConfigId,
|
2024-02-14 02:02:32 +00:00
|
|
|
acquire_mesh_id:AcquireMeshId
|
2024-02-15 01:11:41 +00:00
|
|
|
)->bsp::PartialMap1
|
2024-02-14 02:02:32 +00:00
|
|
|
where
|
2024-02-15 01:11:41 +00:00
|
|
|
AcquireRenderConfigId:FnMut(Option<&str>)->strafesnet_common::model::RenderConfigId,
|
2024-02-14 02:02:32 +00:00
|
|
|
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)
|
2024-02-14 02:02:32 +00:00
|
|
|
}
|