it was completely wrong
This commit is contained in:
@ -150,7 +150,7 @@ impl<R:BinReaderExt> StreamableBot<R>{
|
||||
}
|
||||
}
|
||||
|
||||
const MAX_BLOCK_SIZE:u64=64*1024;//64 kB
|
||||
const MAX_BLOCK_SIZE:usize=64*1024;//64 kB
|
||||
pub fn write_bot<W:BinWriterExt>(mut writer:W,instructions:impl IntoIterator<Item=TimedPhysicsInstruction>)->Result<(),Error>{
|
||||
// decide which instructions to put in which segment
|
||||
// write segment 1 to block 1
|
||||
@ -168,10 +168,13 @@ pub fn write_bot<W:BinWriterExt>(mut writer:W,instructions:impl IntoIterator<Ite
|
||||
let mut segment_header_infos=Vec::new();
|
||||
let mut raw_segments=std::io::Cursor::new(Vec::new());
|
||||
|
||||
let mut last_time=Time::ZERO;
|
||||
let mut last_position=raw_segments.position();
|
||||
// block info
|
||||
let mut start_time=Time::ZERO;
|
||||
let mut start_position=raw_segments.position() as usize;
|
||||
let mut instruction_count=0;
|
||||
|
||||
let mut last_position=start_position;
|
||||
|
||||
let mut iter=instructions.into_iter();
|
||||
|
||||
macro_rules! collect_instruction{
|
||||
@ -180,24 +183,25 @@ pub fn write_bot<W:BinWriterExt>(mut writer:W,instructions:impl IntoIterator<Ite
|
||||
let instruction_writable:newtypes::physics::TimedInstruction=$instruction.try_into().map_err(Error::InstructionConvert)?;
|
||||
instruction_writable.write_le(&mut raw_segments).map_err(Error::InstructionWrite)?;
|
||||
instruction_count+=1;
|
||||
let position=raw_segments.position();
|
||||
let position=raw_segments.position() as usize;
|
||||
// exceeds max block size
|
||||
if MAX_BLOCK_SIZE<position-last_position{
|
||||
segment_header_infos.push(SegmentHeaderInfo{
|
||||
time:last_time,
|
||||
time:start_time,
|
||||
instruction_count,
|
||||
range:position as usize..last_position as usize,
|
||||
range:start_position..last_position,
|
||||
});
|
||||
start_position=last_position;
|
||||
instruction_count=0;
|
||||
last_position=position;
|
||||
last_time=time;
|
||||
start_time=time;
|
||||
}
|
||||
last_position=position;
|
||||
}
|
||||
}
|
||||
|
||||
// unroll one loop iteration to grab the starting time
|
||||
if let Some(instruction)=iter.next(){
|
||||
last_time=instruction.time;
|
||||
start_time=instruction.time;
|
||||
collect_instruction!(instruction);
|
||||
}
|
||||
|
||||
@ -205,13 +209,14 @@ pub fn write_bot<W:BinWriterExt>(mut writer:W,instructions:impl IntoIterator<Ite
|
||||
collect_instruction!(instruction);
|
||||
}
|
||||
//last block, whatever size it happens to be
|
||||
let position=raw_segments.position();
|
||||
segment_header_infos.push(SegmentHeaderInfo{
|
||||
time:last_time,
|
||||
instruction_count,
|
||||
range:position as usize..last_position as usize,
|
||||
});
|
||||
|
||||
{
|
||||
let final_position=raw_segments.position() as usize;
|
||||
segment_header_infos.push(SegmentHeaderInfo{
|
||||
time:start_time,
|
||||
instruction_count,
|
||||
range:start_position..final_position,
|
||||
});
|
||||
}
|
||||
// drop cursor
|
||||
let raw_segments=raw_segments.into_inner();
|
||||
|
||||
|
Reference in New Issue
Block a user