diff --git a/src/map.rs b/src/map.rs index 6d818a1..c43105c 100644 --- a/src/map.rs +++ b/src/map.rs @@ -1,3 +1,5 @@ +use std::collections::HashMap; + use crate::newtypes; use crate::file::BlockId; use binrw::{binrw,BinReaderExt}; @@ -43,6 +45,7 @@ for spacial_block_id in 0..num_spacial_blocks{ //the first 8 bits of resource_uuid describe the type (mesh, texture, etc) //if the map file references only external resources, num_resource_blocks = 0 for resource_idx in 0..num_resource_blocks{ + Resource resource_type u32 block_id } for resource_idx in 0..num_resources_external{ @@ -72,12 +75,28 @@ for model_id in 0..num_models{ #[brw(little,repr=u8)] enum Resource{ Mesh, - Image, + Texture, Shader, Sound, Video, Animation, } +#[binrw] +#[brw(little)] +struct ResourceId(u128); + +struct ResourceMap{ + meshes:HashMap, + textures:HashMap, +} +impl Default for ResourceMap{ + fn default()->Self{ + Self{ + meshes:HashMap::new(), + textures:HashMap::new(), + } + } +} #[binrw] #[brw(little)] @@ -94,7 +113,7 @@ struct ResourceBlockHeader{ #[binrw] #[brw(little)] struct ResourceExternalHeader{ - resource_uuid:u128, + resource_uuid:ResourceId, } #[binrw] @@ -131,6 +150,9 @@ pub struct StreamableMap{ //this includes every platform... move the unconstrained datas to their appropriate data block? modes:gameplay_modes::Modes, bvh:BvhNode, + //something something resources hashmaps + resource_blocks:ResourceMap, + resource_external:ResourceMap, } impl StreamableMap{ pub(crate) fn new(mut file:crate::file::File)->Result{ @@ -140,10 +162,13 @@ impl StreamableMap{ let bvh=header.spacial_blocks.into_iter().map(|spacial_block| (spacial_block.id,spacial_block.extents.into()) ).collect(); + //TODO: generate mesh ids and texture ids from resource list order Ok(Self{ file, modes:strafesnet_common::gameplay_modes::Modes::new(modes), bvh:strafesnet_common::bvh::generate_bvh(bvh), + resource_blocks:Default::default(), + resource_external:Default::default(), }) } pub fn get_intersecting_region_block_ids(&self,aabb:&Aabb)->Vec{ @@ -160,7 +185,12 @@ impl StreamableMap{ let region:Region=block.read_le().map_err(Error::InvalidRegion)?; Ok(region.models.into_iter().map(Into::into).collect()) } - // pub fn load_resource(&mut self,resource_id:ResourceId)->Resource{ - // // - // } + /* + pub fn load_mesh(&mut self,mesh_id:model::MeshId)->Result{ + let block_id=self.resource_blocks.meshes.get(mesh_id).ok_or_err(Error::NotFound)?; + let mut block=self.file.block_reader(block_id).map_err(Error::File)?; + let mesh:newtypes::model::Mesh=block.read_le().map_err(Error::InvalidRegion)?; + Ok(mesh.into()) + } + */ }