some code

This commit is contained in:
Quaternions 2024-01-18 16:39:58 -08:00
parent 2d420d7676
commit 5ea8a2db5f
5 changed files with 70 additions and 14 deletions

View File

@ -1,4 +1,5 @@
pub enum Error{ pub enum Error{
InvalidHeader,
InvalidSegment, InvalidSegment,
} }
@ -53,6 +54,9 @@ pub struct StreamableBot{
timeline:timeline::Timeline<SegmentId>, timeline:timeline::Timeline<SegmentId>,
} }
impl StreamableBot{ impl StreamableBot{
pub fn new(file:crate::file::File)->Result<Self,Error>{
Err(Error::InvalidHeader)
}
pub fn load_segment(&mut self,segment_id:u64)->Result<Segment,Error>{ pub fn load_segment(&mut self,segment_id:u64)->Result<Segment,Error>{
//load region from disk //load region from disk
//parse the models and determine what resources need to be loaded //parse the models and determine what resources need to be loaded

View File

@ -1,5 +1,5 @@
pub enum Error{ pub enum Error{
// InvalidHeader,
} }
/* /*
@ -20,4 +20,9 @@ how to do worldstate for deathrun!?
pub struct StreamableDemo{ pub struct StreamableDemo{
map:Box<crate::map::StreamableMap>, map:Box<crate::map::StreamableMap>,
bots:Vec<crate::bot::StreamableBot>, bots:Vec<crate::bot::StreamableBot>,
}
impl StreamableDemo{
pub fn new(file:crate::file::File)->Result<Self,Error>{
Err(Error::InvalidHeader)
}
} }

View File

@ -33,16 +33,16 @@ for block_id in 0..num_blocks{
//each block is compressed with zstd or gz or something //each block is compressed with zstd or gz or something
*/ */
#[derive(Clone,Copy)]
pub enum Magic{ pub(crate) enum FourCC{
Map, //"SNFM" Map,
Bot, //"SNFB" Bot,
Demo, //"SNFD" Demo,
} }
pub struct Header{ struct Header{
/// Type of file /// Type of file
magic:Magic, fourcc:FourCC,
/// Type version /// Type version
version:u32, version:u32,
/// Minimum data required to know the location of all streamable resources for this specific file /// Minimum data required to know the location of all streamable resources for this specific file
@ -51,11 +51,28 @@ pub struct Header{
resource:u128, resource:u128,
} }
pub struct BlockLayout{ pub(crate) struct BlockLayout{
count:u64, count:u64,
location:Vec<u64>, location:Vec<u64>,
} }
pub struct File{ pub(crate) struct File{
//??? header:Header,
block_layout:BlockLayout,
//reference to the data
}
impl File{
pub(crate) fn new<R:std::io::Read+std::io::Seek>(input:R)->Result<Self,Error>{
Self{
header:input.read_le()?,
block_layout:input.read_le()?,
}
}
pub(crate) fn read_block(&mut self,block_id:u64)->Result<Vec<u8>,Error>{
Err(Error::UnexpectedEOF)
}
pub(crate) fn fourcc(&self)->FourCC{
self.header.fourcc
}
} }

View File

@ -6,6 +6,7 @@ pub mod bot;
pub mod demo; pub mod demo;
pub enum Error{ pub enum Error{
UnexpectedFourCC,
Header(file::Error), Header(file::Error),
Map(map::Error), Map(map::Error),
Bot(bot::Error), Bot(bot::Error),
@ -18,9 +19,34 @@ pub enum SNF{
Demo(demo::StreamableDemo), Demo(demo::StreamableDemo),
} }
pub fn read<R:Read>(input:R)->Result<SNF,Error>{ pub fn read_snf<R:Read>(input:R)->Result<SNF,Error>{
//let header:file::Header=input.read()?; let file=file::File::read(input).map_err(|e|Error::Header(e))?;
Err(Error::Header(file::Error::InvalidMagic)) Ok(match file.fourcc(){
file::FourCC::Map=>SNF::Map(map::StreamableMap::new(file).map_err(|e|Error::Map(e))?),
file::FourCC::Bot=>SNF::Bot(bot::StreamableBot::new(file).map_err(|e|Error::Bot(e))?),
file::FourCC::Demo=>SNF::Demo(demo::StreamableDemo::new(file).map_err(|e|Error::Demo(e))?),
})
}
pub fn read_map<R:Read>(input:R)->Result<map::StreamableMap,Error>{
let file=file::File::read(input).map_err(|e|Error::Header(e))?;
match file.fourcc(){
file::FourCC::Map=>Ok(map::StreamableMap::new(file).map_err(|e|Error::Map(e))?),
_=>Err(Error::UnexpectedFourCC)
}
}
pub fn read_bot<R:Read>(input:R)->Result<bot::StreamableBot,Error>{
let file=file::File::read(input).map_err(|e|Error::Header(e))?;
match file.fourcc(){
file::FourCC::Bot=>Ok(bot::StreamableBot::new(file).map_err(|e|Error::Bot(e))?),
_=>Err(Error::UnexpectedFourCC)
}
}
pub fn read_demo<R:Read>(input:R)->Result<demo::StreamableDemo,Error>{
let file=file::File::read(input).map_err(|e|Error::Header(e))?;
match file.fourcc(){
file::FourCC::Demo=>Ok(demo::StreamableDemo::new(file).map_err(|e|Error::Demo(e))?),
_=>Err(Error::UnexpectedFourCC)
}
} }
#[cfg(test)] #[cfg(test)]

View File

@ -1,4 +1,5 @@
pub enum Error{ pub enum Error{
InvalidHeader,
InvalidNode, InvalidNode,
} }
@ -82,6 +83,9 @@ pub struct StreamableMap{
resource_image:std::collections::HashMap<ImageUuid,image::Image>, resource_image:std::collections::HashMap<ImageUuid,image::Image>,
} }
impl StreamableMap{ impl StreamableMap{
pub fn new(file:crate::file::File)->Result<Self,Error>{
Err(Error::InvalidHeader)
}
pub fn load_node(&mut self,node_id:BvhNodeId)->Result<Vec<model::ModelInstance>,Error>{ pub fn load_node(&mut self,node_id:BvhNodeId)->Result<Vec<model::ModelInstance>,Error>{
//load region from disk //load region from disk
//parse the models and determine what resources need to be loaded //parse the models and determine what resources need to be loaded