strafe-client/src/map.rs

122 lines
2.8 KiB
Rust
Raw Normal View History

2024-02-02 04:27:12 +00:00
//use strafesnet_common::model;
//use strafesnet_common::gameplay_modes;
2024-01-19 03:28:01 +00:00
use binrw::{BinReaderExt, binrw};
2024-01-16 03:09:34 +00:00
pub enum Error{
2024-01-19 00:39:58 +00:00
InvalidHeader,
InvalidBvhNodeId(BvhNodeId),
2024-01-19 03:28:01 +00:00
InvalidRegion(binrw::Error),
File(crate::file::Error),
2024-01-16 03:09:34 +00:00
}
/* block types
BLOCK_MAP_HEADER:
DefaultStyleInfo style_info
//bvh goes here
u64 num_nodes
//node 0 parent node is implied to be None
for node_id in 1..num_nodes{
u64 parent_node
}
2024-01-18 23:24:00 +00:00
//NOTE: alternate realities are not necessary.
//portals/wormholes simply use an in-model and and out-model.
//skyboxes are inverted models with a special shader.
2024-01-17 02:50:02 +00:00
//ideally spacial blocks are sorted from distance to start zone
//texture blocks are inserted before the first spacial block they are used in
2024-01-16 03:09:34 +00:00
u64 num_spacial_blocks
for spacial_block_id in 0..num_spacial_blocks{
u64 node_id
u64 block_id //data block
Aabb block_extents
}
2024-01-17 02:50:02 +00:00
//if the map file references external resources, num_resources = 0
u64 num_resources
for resource_id in 0..num_resources{
u64 block_id
u128 resource_id
}
2024-01-16 03:09:34 +00:00
BLOCK_MAP_RESOURCE:
2024-01-17 02:50:02 +00:00
Resource resource_type
2024-01-16 03:09:34 +00:00
//an individual one of the following:
2024-02-09 07:13:53 +00:00
- model (Mesh)
2024-01-16 03:09:34 +00:00
- shader (compiled SPIR-V)
- image (JpegXL)
- sound (Opus)
- video (AV1)
- animation (Trey thing)
2024-01-17 02:50:02 +00:00
BLOCK_MAP_REGION:
u64 num_models
for model_id in 0..num_models{
u128 model_resource_uuid
ModelInstance mode_instance
}
2024-01-16 03:09:34 +00:00
*/
2024-01-17 04:07:11 +00:00
2024-01-19 03:28:01 +00:00
//error hiding mock code
2024-02-02 04:27:12 +00:00
mod gameplay_modes{
pub struct Modes{}
}
mod model{
2024-02-09 07:13:53 +00:00
pub struct Mesh{}
2024-02-02 04:27:12 +00:00
#[super::binrw]
#[brw(little)]
pub struct Model{}
}
2024-01-17 04:07:11 +00:00
mod image{
pub struct Image{}
}
//serious code
struct ModelUuid(u128);
struct ImageUuid(u128);
#[binrw]
#[brw(little)]
#[derive(Clone,Copy,id::Id)]
pub struct BvhNodeId(u32);
2024-01-18 23:33:22 +00:00
struct BvhNode{
//aabb
//child
2024-01-18 23:33:22 +00:00
}
2024-01-19 03:28:01 +00:00
#[binrw]
#[brw(little)]
struct Region{
2024-07-24 00:18:10 +00:00
//consider including a bvh in the region instead of needing to rebalance the physics bvh on the fly
2024-01-19 03:28:01 +00:00
model_count:u32,
#[br(count=model_count)]
2024-01-30 06:56:20 +00:00
models:Vec<model::Model>,
2024-01-19 03:28:01 +00:00
}
2024-01-18 23:33:22 +00:00
2024-01-19 03:28:01 +00:00
pub struct StreamableMap<R:BinReaderExt>{
file:crate::file::File<R>,
2024-01-30 06:56:20 +00:00
//this includes every platform... move the unconstrained datas to their appropriate data block?
modes:gameplay_modes::Modes,
2024-01-18 23:33:22 +00:00
bvh:BvhNode,
2024-01-19 03:28:01 +00:00
node_id_to_block_id:Vec<crate::file::BlockId>,
2024-01-18 23:33:22 +00:00
}
2024-01-19 03:28:01 +00:00
impl<R:BinReaderExt> StreamableMap<R>{
pub(crate) fn new(file:crate::file::File<R>)->Result<Self,Error>{
2024-01-19 00:39:58 +00:00
Err(Error::InvalidHeader)
}
2024-01-30 06:56:20 +00:00
pub fn load_node(&mut self,node_id:BvhNodeId)->Result<Vec<model::Model>,Error>{
2024-01-18 23:33:22 +00:00
//load region from disk
//parse the models and determine what resources need to be loaded
//load resources into self.resources
//return Region
let block_id=*self.node_id_to_block_id.get(node_id.get() as usize).ok_or(Error::InvalidBvhNodeId(node_id))?;
2024-07-24 00:18:03 +00:00
let mut block=self.file.block_reader(block_id).map_err(Error::File)?;
let region:Region=block.read_le().map_err(Error::InvalidRegion)?;
2024-01-19 03:28:01 +00:00
Ok(region.models)
2024-01-18 23:33:22 +00:00
}
2024-02-02 04:27:12 +00:00
// pub fn load_resource(&mut self,resource_id:ResourceId)->Resource{
// //
// }
2024-01-16 03:09:34 +00:00
}