some code
This commit is contained in:
parent
2d420d7676
commit
5ea8a2db5f
@ -1,4 +1,5 @@
|
||||
pub enum Error{
|
||||
InvalidHeader,
|
||||
InvalidSegment,
|
||||
}
|
||||
|
||||
@ -53,6 +54,9 @@ pub struct StreamableBot{
|
||||
timeline:timeline::Timeline<SegmentId>,
|
||||
}
|
||||
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>{
|
||||
//load region from disk
|
||||
//parse the models and determine what resources need to be loaded
|
||||
|
@ -1,5 +1,5 @@
|
||||
pub enum Error{
|
||||
//
|
||||
InvalidHeader,
|
||||
}
|
||||
|
||||
/*
|
||||
@ -20,4 +20,9 @@ how to do worldstate for deathrun!?
|
||||
pub struct StreamableDemo{
|
||||
map:Box<crate::map::StreamableMap>,
|
||||
bots:Vec<crate::bot::StreamableBot>,
|
||||
}
|
||||
impl StreamableDemo{
|
||||
pub fn new(file:crate::file::File)->Result<Self,Error>{
|
||||
Err(Error::InvalidHeader)
|
||||
}
|
||||
}
|
37
src/file.rs
37
src/file.rs
@ -33,16 +33,16 @@ for block_id in 0..num_blocks{
|
||||
//each block is compressed with zstd or gz or something
|
||||
|
||||
*/
|
||||
|
||||
pub enum Magic{
|
||||
Map, //"SNFM"
|
||||
Bot, //"SNFB"
|
||||
Demo, //"SNFD"
|
||||
#[derive(Clone,Copy)]
|
||||
pub(crate) enum FourCC{
|
||||
Map,
|
||||
Bot,
|
||||
Demo,
|
||||
}
|
||||
|
||||
pub struct Header{
|
||||
struct Header{
|
||||
/// Type of file
|
||||
magic:Magic,
|
||||
fourcc:FourCC,
|
||||
/// Type version
|
||||
version:u32,
|
||||
/// Minimum data required to know the location of all streamable resources for this specific file
|
||||
@ -51,11 +51,28 @@ pub struct Header{
|
||||
resource:u128,
|
||||
}
|
||||
|
||||
pub struct BlockLayout{
|
||||
pub(crate) struct BlockLayout{
|
||||
count: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
|
||||
}
|
||||
}
|
||||
|
32
src/lib.rs
32
src/lib.rs
@ -6,6 +6,7 @@ pub mod bot;
|
||||
pub mod demo;
|
||||
|
||||
pub enum Error{
|
||||
UnexpectedFourCC,
|
||||
Header(file::Error),
|
||||
Map(map::Error),
|
||||
Bot(bot::Error),
|
||||
@ -18,9 +19,34 @@ pub enum SNF{
|
||||
Demo(demo::StreamableDemo),
|
||||
}
|
||||
|
||||
pub fn read<R:Read>(input:R)->Result<SNF,Error>{
|
||||
//let header:file::Header=input.read()?;
|
||||
Err(Error::Header(file::Error::InvalidMagic))
|
||||
pub fn read_snf<R:Read>(input:R)->Result<SNF,Error>{
|
||||
let file=file::File::read(input).map_err(|e|Error::Header(e))?;
|
||||
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)]
|
||||
|
@ -1,4 +1,5 @@
|
||||
pub enum Error{
|
||||
InvalidHeader,
|
||||
InvalidNode,
|
||||
}
|
||||
|
||||
@ -82,6 +83,9 @@ pub struct StreamableMap{
|
||||
resource_image:std::collections::HashMap<ImageUuid,image::Image>,
|
||||
}
|
||||
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>{
|
||||
//load region from disk
|
||||
//parse the models and determine what resources need to be loaded
|
||||
|
Loading…
Reference in New Issue
Block a user