This commit is contained in:
Quaternions 2024-07-23 19:32:29 -07:00
parent 4f90956e16
commit 9cef23c519

View File

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