serial file access

This commit is contained in:
Quaternions 2024-07-26 16:13:51 -07:00
parent 3e8c5167dc
commit 931cef52b1
2 changed files with 10 additions and 8 deletions

View File

@ -76,7 +76,7 @@ pub struct Header{
#[binrw] #[binrw]
#[brw(little)] #[brw(little)]
#[derive(Clone,Copy,Debug,Hash,id::Id,Eq,PartialEq)] #[derive(Clone,Copy,Debug,Hash,id::Id,Eq,Ord,PartialEq,PartialOrd)]
pub struct BlockId(u32); pub struct BlockId(u32);
pub(crate) struct File<R:BinReaderExt>{ pub(crate) struct File<R:BinReaderExt>{

View File

@ -263,6 +263,15 @@ impl<R:BinReaderExt> StreamableMap<R>{
read_texture(&mut self.file,block_id) read_texture(&mut self.file,block_id)
} }
pub fn into_complete_map(mut self)->Result<strafesnet_common::map::CompleteMap,Error>{ pub fn into_complete_map(mut self)->Result<strafesnet_common::map::CompleteMap,Error>{
let mut block_ids=Vec::new();
self.bvh.into_visitor(&mut |block_id|block_ids.push(block_id));
//count on reading the file in sequential order being fastest
block_ids.sort();
//load all regions
let mut models=Vec::new();
for block_id in block_ids{
models.append(&mut read_region(&mut self.file,block_id)?);
}
//load all meshes //load all meshes
let mut meshes=Vec::with_capacity(self.resource_blocks.meshes.len()); let mut meshes=Vec::with_capacity(self.resource_blocks.meshes.len());
for mesh_id in 0..self.resource_blocks.meshes.len() as u32{ for mesh_id in 0..self.resource_blocks.meshes.len() as u32{
@ -277,13 +286,6 @@ impl<R:BinReaderExt> StreamableMap<R>{
let block_id=self.resource_blocks.textures[&texture_id]; let block_id=self.resource_blocks.textures[&texture_id];
textures.push(read_texture(&mut self.file,block_id)?); textures.push(read_texture(&mut self.file,block_id)?);
} }
let mut block_ids=Vec::new();
self.bvh.into_visitor(&mut |block_id|block_ids.push(block_id));
//load all regions
let mut models=Vec::new();
for block_id in block_ids{
models.append(&mut read_region(&mut self.file,block_id)?);
}
Ok(strafesnet_common::map::CompleteMap{ Ok(strafesnet_common::map::CompleteMap{
modes:self.modes, modes:self.modes,
attributes:self.attributes, attributes:self.attributes,