Compare commits
2 Commits
3e737282dc
...
0532b47fec
Author | SHA1 | Date | |
---|---|---|---|
0532b47fec | |||
40e7717aec |
46
src/bot.rs
46
src/bot.rs
@ -41,24 +41,24 @@ mod simulation{
|
||||
#[brw(little)]
|
||||
pub struct Instruction{}
|
||||
}
|
||||
mod instruction{
|
||||
#[super::binrw]
|
||||
#[brw(little)]
|
||||
pub struct TimedInstruction<Instruction:binrw::BinRead+binrw::BinWrite>{
|
||||
time:u64,
|
||||
instruction:Instruction
|
||||
}
|
||||
}
|
||||
mod timeline{
|
||||
#[super::binrw]
|
||||
#[brw(little)]
|
||||
pub struct Timeline<Instruction:binrw::BinRead+binrw::BinWrite>{
|
||||
#[bw(try_calc(u32::try_from(instructions.len())))]
|
||||
instruction_count:u32,
|
||||
#[br(count=instruction_count)]
|
||||
instructions:Vec<super::instruction::TimedInstruction<Instruction>>
|
||||
}
|
||||
}
|
||||
// mod instruction{
|
||||
// #[super::binrw]
|
||||
// #[brw(little)]
|
||||
// pub struct TimedInstruction<Instruction:binrw::BinRead+binrw::BinWrite>{
|
||||
// time:u64,
|
||||
// instruction:Instruction
|
||||
// }
|
||||
// }
|
||||
// mod timeline{
|
||||
// #[super::binrw]
|
||||
// #[brw(little)]
|
||||
// pub struct Timeline<Instruction:binrw::BinRead+binrw::BinWrite>{
|
||||
// #[bw(try_calc(u32::try_from(instructions.len())))]
|
||||
// instruction_count:u32,
|
||||
// #[br(count=instruction_count)]
|
||||
// instructions:Vec<super::instruction::TimedInstruction<Instruction>>
|
||||
// }
|
||||
// }
|
||||
|
||||
//serious code
|
||||
|
||||
@ -70,15 +70,15 @@ struct SegmentId(u64);
|
||||
#[brw(little)]
|
||||
pub struct Segment{
|
||||
state:simulation::State,
|
||||
#[bw(try_calc(u32::try_from(instructions.len())))]
|
||||
instruction_count:u32,
|
||||
#[br(count=instruction_count)]
|
||||
instructions:Vec<instruction::TimedInstruction<simulation::Instruction>>
|
||||
//#[bw(try_calc(u32::try_from(instructions.len())))]
|
||||
//instruction_count:u32,
|
||||
//#[br(count=instruction_count)]
|
||||
//instructions:Vec<instruction::TimedInstruction<simulation::Instruction>>
|
||||
}
|
||||
|
||||
pub struct StreamableBot<R:BinReaderExt>{
|
||||
file:crate::file::File<R>,
|
||||
timeline:timeline::Timeline<SegmentId>,
|
||||
//timeline:timeline::Timeline<SegmentId>,
|
||||
segment_id_to_block_id:Vec<crate::file::BlockId>,
|
||||
}
|
||||
impl<R:BinReaderExt> StreamableBot<R>{
|
||||
|
11
src/file.rs
11
src/file.rs
@ -5,7 +5,7 @@ use binrw::{binrw, BinReaderExt, io::TakeSeekExt};
|
||||
pub enum Error{
|
||||
InvalidHeader(binrw::Error),
|
||||
UnexpectedEOF,
|
||||
InvalidBlockId(usize),
|
||||
InvalidBlockId(u64),
|
||||
Seek(std::io::Error),
|
||||
}
|
||||
|
||||
@ -64,7 +64,8 @@ struct Header{
|
||||
block_location:Vec<u64>,
|
||||
}
|
||||
|
||||
pub struct BlockId(usize);
|
||||
#[derive(Clone,Copy,Hash,Eq,PartialEq)]
|
||||
pub struct BlockId(u64);
|
||||
|
||||
pub(crate) struct File<R:BinReaderExt>{
|
||||
header:Header,
|
||||
@ -80,11 +81,11 @@ impl<R:BinReaderExt> File<R>{
|
||||
})
|
||||
}
|
||||
pub(crate) fn take_block(&mut self,block_id:BlockId)->Result<binrw::io::TakeSeek<&mut R>,Error>{
|
||||
if self.header.block_location.len()<=block_id.0{
|
||||
if self.header.block_location.len() as u64<=block_id.0{
|
||||
return Err(Error::InvalidBlockId(block_id.0))
|
||||
}
|
||||
let block_start=self.header.block_location[block_id.0];
|
||||
let block_end=self.header.block_location[block_id.0+1];
|
||||
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))?;
|
||||
Ok((&mut self.data).take_seek(block_end-block_start))
|
||||
}
|
||||
|
19
src/map.rs
19
src/map.rs
@ -1,5 +1,5 @@
|
||||
use strafesnet_common::model;
|
||||
use strafesnet_common::gameplay_modes;
|
||||
//use strafesnet_common::model;
|
||||
//use strafesnet_common::gameplay_modes;
|
||||
use binrw::{BinReaderExt, binrw};
|
||||
|
||||
pub enum Error{
|
||||
@ -60,6 +60,15 @@ for model_id in 0..num_models{
|
||||
|
||||
|
||||
//error hiding mock code
|
||||
mod gameplay_modes{
|
||||
pub struct Modes{}
|
||||
}
|
||||
mod model{
|
||||
pub struct IndexedModel{}
|
||||
#[super::binrw]
|
||||
#[brw(little)]
|
||||
pub struct Model{}
|
||||
}
|
||||
mod image{
|
||||
pub struct Image{}
|
||||
}
|
||||
@ -102,7 +111,7 @@ impl<R:BinReaderExt> StreamableMap<R>{
|
||||
let region:Region=block.read_le().map_err(|e|Error::InvalidRegion(e))?;
|
||||
Ok(region.models)
|
||||
}
|
||||
pub fn load_resource(&mut self,resource_id:ResourceId)->Resource{
|
||||
//
|
||||
}
|
||||
// pub fn load_resource(&mut self,resource_id:ResourceId)->Resource{
|
||||
// //
|
||||
// }
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user