use id + new knowledge + don't need u64
This commit is contained in:
parent
0532b47fec
commit
0c439bf2e6
32
Cargo.lock
generated
32
Cargo.lock
generated
@ -29,14 +29,14 @@ dependencies = [
|
||||
"owo-colors",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bytemuck"
|
||||
version = "1.14.0"
|
||||
version = "1.14.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "374d28ec25809ee0e23827c2ab573d729e293f281dfe393500e7ad618baa61c6"
|
||||
checksum = "ea31d69bda4949c1c1562c1e6f042a1caefac98cdc8a298260a2ff41c1e2d42b"
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
@ -50,6 +50,16 @@ version = "0.25.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "151665d9be52f9bb40fc7966565d39666f2d1e69233571b71b87791c7e0528b3"
|
||||
|
||||
[[package]]
|
||||
name = "id"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.itzana.me/Quaternions/id?rev=1f710976cc786c8853dab73d6e1cee53158deeb0#1f710976cc786c8853dab73d6e1cee53158deeb0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.48",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "owo-colors"
|
||||
version = "3.5.0"
|
||||
@ -58,9 +68,9 @@ checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.76"
|
||||
version = "1.0.78"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c"
|
||||
checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
@ -87,6 +97,7 @@ name = "strafesnet_snf"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"binrw",
|
||||
"id",
|
||||
"strafesnet_common",
|
||||
]
|
||||
|
||||
@ -101,6 +112,17 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.48"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.12"
|
||||
|
@ -7,4 +7,5 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
binrw = "0.13.3"
|
||||
id = { git = "https://git.itzana.me/Quaternions/id", rev = "1f710976cc786c8853dab73d6e1cee53158deeb0" }
|
||||
strafesnet_common = { git = "https://git.itzana.me/StrafesNET/common", rev = "5ee826d9487b5e2bea4b3cf99a68ce9a95d72f72" }
|
||||
|
11
src/bot.rs
11
src/bot.rs
@ -3,7 +3,7 @@ use binrw::{BinReaderExt, binrw};
|
||||
pub enum Error{
|
||||
InvalidHeader,
|
||||
InvalidSegment(binrw::Error),
|
||||
InvalidSegmentId(u64),
|
||||
InvalidSegmentId(SegmentId),
|
||||
File(crate::file::Error),
|
||||
}
|
||||
|
||||
@ -64,7 +64,8 @@ mod simulation{
|
||||
|
||||
#[binrw]
|
||||
#[brw(little)]
|
||||
struct SegmentId(u64);
|
||||
#[derive(Clone,Copy,id::Id)]
|
||||
pub struct SegmentId(u32);
|
||||
|
||||
#[binrw]
|
||||
#[brw(little)]
|
||||
@ -86,9 +87,9 @@ impl<R:BinReaderExt> StreamableBot<R>{
|
||||
Err(Error::InvalidHeader)
|
||||
}
|
||||
pub fn load_segment(&mut self,segment_id:SegmentId)->Result<Segment,Error>{
|
||||
let block_id=*self.segment_id_to_block_id.get(segment_id.0 as usize).ok_or(Error::InvalidSegmentId(segment_id.0))?;
|
||||
let mut block=self.file.take_block(block_id).map_err(|e|Error::File(e))?;
|
||||
let segment=block.read_le().map_err(|e|Error::InvalidSegment(e))?;
|
||||
let block_id=*self.segment_id_to_block_id.get(segment_id.get() as usize).ok_or(Error::InvalidSegmentId(segment_id))?;
|
||||
let mut block=self.file.take_block(block_id).map_err(Error::File)?;
|
||||
let segment=block.read_le().map_err(Error::InvalidSegment)?;
|
||||
Ok(segment)
|
||||
}
|
||||
}
|
24
src/file.rs
24
src/file.rs
@ -5,7 +5,7 @@ use binrw::{binrw, BinReaderExt, io::TakeSeekExt};
|
||||
pub enum Error{
|
||||
InvalidHeader(binrw::Error),
|
||||
UnexpectedEOF,
|
||||
InvalidBlockId(u64),
|
||||
InvalidBlockId(BlockId),
|
||||
Seek(std::io::Error),
|
||||
}
|
||||
|
||||
@ -58,14 +58,16 @@ struct Header{
|
||||
priming:u64,
|
||||
/// uuid for this file
|
||||
resource:u128,
|
||||
#[bw(try_calc(u64::try_from(block_location.len()-1)))]
|
||||
block_count:u64,
|
||||
#[bw(try_calc(u32::try_from(block_location.len()-1)))]
|
||||
block_count:u32,
|
||||
#[br(count=block_count+1)]
|
||||
block_location:Vec<u64>,
|
||||
}
|
||||
|
||||
#[derive(Clone,Copy,Hash,Eq,PartialEq)]
|
||||
pub struct BlockId(u64);
|
||||
#[binrw]
|
||||
#[brw(little)]
|
||||
#[derive(Clone,Copy,Hash,id::Id,Eq,PartialEq)]
|
||||
pub struct BlockId(u32);
|
||||
|
||||
pub(crate) struct File<R:BinReaderExt>{
|
||||
header:Header,
|
||||
@ -76,17 +78,17 @@ pub(crate) struct File<R:BinReaderExt>{
|
||||
impl<R:BinReaderExt> File<R>{
|
||||
pub(crate) fn new(mut input:R)->Result<File<R>,Error>{
|
||||
Ok(File{
|
||||
header:input.read_le().map_err(|e|Error::InvalidHeader(e))?,
|
||||
header:input.read_le().map_err(Error::InvalidHeader)?,
|
||||
data:input,
|
||||
})
|
||||
}
|
||||
pub(crate) fn take_block(&mut self,block_id:BlockId)->Result<binrw::io::TakeSeek<&mut R>,Error>{
|
||||
if self.header.block_location.len() as u64<=block_id.0{
|
||||
return Err(Error::InvalidBlockId(block_id.0))
|
||||
if self.header.block_location.len() as u32<=block_id.get(){
|
||||
return Err(Error::InvalidBlockId(block_id))
|
||||
}
|
||||
let block_start=self.header.block_location[block_id.0 as usize];
|
||||
let block_end=self.header.block_location[block_id.0 as usize+1];
|
||||
self.data.seek(std::io::SeekFrom::Start(block_start)).map_err(|e|Error::Seek(e))?;
|
||||
let block_start=self.header.block_location[block_id.get() as usize];
|
||||
let block_end=self.header.block_location[block_id.get() as usize+1];
|
||||
self.data.seek(std::io::SeekFrom::Start(block_start)).map_err(Error::Seek)?;
|
||||
Ok((&mut self.data).take_seek(block_end-block_start))
|
||||
}
|
||||
pub(crate) fn fourcc(&self)->FourCC{
|
||||
|
20
src/lib.rs
20
src/lib.rs
@ -20,31 +20,31 @@ pub enum SNF<R:BinReaderExt>{
|
||||
}
|
||||
|
||||
pub fn read_snf<R:BinReaderExt>(input:R)->Result<SNF<R>,Error>{
|
||||
let file=file::File::new(input).map_err(|e|Error::Header(e))?;
|
||||
let file=file::File::new(input).map_err(Error::Header)?;
|
||||
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))?),
|
||||
file::FourCC::Map=>SNF::Map(map::StreamableMap::new(file).map_err(Error::Map)?),
|
||||
file::FourCC::Bot=>SNF::Bot(bot::StreamableBot::new(file).map_err(Error::Bot)?),
|
||||
file::FourCC::Demo=>SNF::Demo(demo::StreamableDemo::new(file).map_err(Error::Demo)?),
|
||||
})
|
||||
}
|
||||
pub fn read_map<R:BinReaderExt>(input:R)->Result<map::StreamableMap<R>,Error>{
|
||||
let file=file::File::new(input).map_err(|e|Error::Header(e))?;
|
||||
let file=file::File::new(input).map_err(Error::Header)?;
|
||||
match file.fourcc(){
|
||||
file::FourCC::Map=>Ok(map::StreamableMap::new(file).map_err(|e|Error::Map(e))?),
|
||||
file::FourCC::Map=>Ok(map::StreamableMap::new(file).map_err(Error::Map)?),
|
||||
_=>Err(Error::UnexpectedFourCC)
|
||||
}
|
||||
}
|
||||
pub fn read_bot<R:BinReaderExt>(input:R)->Result<bot::StreamableBot<R>,Error>{
|
||||
let file=file::File::new(input).map_err(|e|Error::Header(e))?;
|
||||
let file=file::File::new(input).map_err(Error::Header)?;
|
||||
match file.fourcc(){
|
||||
file::FourCC::Bot=>Ok(bot::StreamableBot::new(file).map_err(|e|Error::Bot(e))?),
|
||||
file::FourCC::Bot=>Ok(bot::StreamableBot::new(file).map_err(Error::Bot)?),
|
||||
_=>Err(Error::UnexpectedFourCC)
|
||||
}
|
||||
}
|
||||
pub fn read_demo<R:BinReaderExt>(input:R)->Result<demo::StreamableDemo<R>,Error>{
|
||||
let file=file::File::new(input).map_err(|e|Error::Header(e))?;
|
||||
let file=file::File::new(input).map_err(Error::Header)?;
|
||||
match file.fourcc(){
|
||||
file::FourCC::Demo=>Ok(demo::StreamableDemo::new(file).map_err(|e|Error::Demo(e))?),
|
||||
file::FourCC::Demo=>Ok(demo::StreamableDemo::new(file).map_err(Error::Demo)?),
|
||||
_=>Err(Error::UnexpectedFourCC)
|
||||
}
|
||||
}
|
||||
|
17
src/map.rs
17
src/map.rs
@ -4,7 +4,7 @@ use binrw::{BinReaderExt, binrw};
|
||||
|
||||
pub enum Error{
|
||||
InvalidHeader,
|
||||
InvalidNodeId(u64),
|
||||
InvalidBvhNodeId(BvhNodeId),
|
||||
InvalidRegion(binrw::Error),
|
||||
File(crate::file::Error),
|
||||
}
|
||||
@ -77,9 +77,14 @@ mod image{
|
||||
|
||||
struct ModelUuid(u128);
|
||||
struct ImageUuid(u128);
|
||||
pub struct BvhNodeId(u64);
|
||||
|
||||
#[binrw]
|
||||
#[brw(little)]
|
||||
#[derive(Clone,Copy,id::Id)]
|
||||
pub struct BvhNodeId(u32);
|
||||
struct BvhNode{
|
||||
//
|
||||
//aabb
|
||||
//child
|
||||
}
|
||||
#[binrw]
|
||||
#[brw(little)]
|
||||
@ -106,9 +111,9 @@ impl<R:BinReaderExt> StreamableMap<R>{
|
||||
//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.0 as usize).ok_or(Error::InvalidNodeId(node_id.0))?;
|
||||
let mut block=self.file.take_block(block_id).map_err(|e|Error::File(e))?;
|
||||
let region:Region=block.read_le().map_err(|e|Error::InvalidRegion(e))?;
|
||||
let block_id=*self.node_id_to_block_id.get(node_id.get() as usize).ok_or(Error::InvalidBvhNodeId(node_id))?;
|
||||
let mut block=self.file.take_block(block_id).map_err(Error::File)?;
|
||||
let region:Region=block.read_le().map_err(Error::InvalidRegion)?;
|
||||
Ok(region.models)
|
||||
}
|
||||
// pub fn load_resource(&mut self,resource_id:ResourceId)->Resource{
|
||||
|
Loading…
Reference in New Issue
Block a user