2024-02-14 02:02:32 +00:00
|
|
|
mod bsp;
|
|
|
|
|
|
|
|
pub struct Bsp(vbsp::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)?;
|
|
|
|
|
|
|
|
vbsp::Bsp::read(s.as_slice()).map(Bsp).map_err(ReadError::Bsp)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn convert<AcquireTextureId,AcquireMeshId>(
|
|
|
|
bsp:&Bsp,
|
|
|
|
acquire_texture_id:AcquireTextureId,
|
|
|
|
acquire_mesh_id:AcquireMeshId
|
|
|
|
)->strafesnet_common::map::CompleteMap
|
|
|
|
where
|
|
|
|
AcquireTextureId:FnMut(&str)->strafesnet_common::model::TextureId,
|
|
|
|
AcquireMeshId:FnMut(&str)->strafesnet_common::model::MeshId,
|
|
|
|
{
|
|
|
|
bsp::convert(&bsp.0,acquire_texture_id,acquire_mesh_id)
|
|
|
|
}
|