diff --git a/src/file.rs b/src/file.rs index 91c7229..1cc2d8e 100644 --- a/src/file.rs +++ b/src/file.rs @@ -76,7 +76,7 @@ pub struct Header{ #[binrw] #[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(crate) struct File{ diff --git a/src/map.rs b/src/map.rs index b758d98..97e74f5 100644 --- a/src/map.rs +++ b/src/map.rs @@ -263,6 +263,15 @@ impl StreamableMap{ read_texture(&mut self.file,block_id) } pub fn into_complete_map(mut self)->Result{ + 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 let mut meshes=Vec::with_capacity(self.resource_blocks.meshes.len()); for mesh_id in 0..self.resource_blocks.meshes.len() as u32{ @@ -277,13 +286,6 @@ impl StreamableMap{ let block_id=self.resource_blocks.textures[&texture_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{ modes:self.modes, attributes:self.attributes,