fix block_location
This commit is contained in:
parent
d3e114c7b6
commit
0705e879db
22
src/map.rs
22
src/map.rs
@ -346,7 +346,12 @@ pub fn write_map<W:BinWriterExt>(mut writer:W,map:strafesnet_common::map::Comple
|
|||||||
}).collect::<Result<Vec<_>,_>>()?;
|
}).collect::<Result<Vec<_>,_>>()?;
|
||||||
let bvh=strafesnet_common::bvh::generate_bvh(boxen).weigh_contents(&|_|std::mem::size_of::<newtypes::model::Model>());
|
let bvh=strafesnet_common::bvh::generate_bvh(boxen).weigh_contents(&|_|std::mem::size_of::<newtypes::model::Model>());
|
||||||
//build blocks
|
//build blocks
|
||||||
let mut block_location=vec![0];//for file header
|
//block location is initialized with two values
|
||||||
|
//the first value represents the location of the first byte after the file header
|
||||||
|
//the second value represents the first byte of the second data block
|
||||||
|
//the first data block is always the map header, so the difference is the map header size.
|
||||||
|
//this information is filled in later after the sizes are known.
|
||||||
|
let mut block_location=vec![0,0];//for file header
|
||||||
let mut spacial_blocks=Vec::new();//for map header
|
let mut spacial_blocks=Vec::new();//for map header
|
||||||
let mut sequential_block_data=Vec::new();
|
let mut sequential_block_data=Vec::new();
|
||||||
let mut cursor_to_data=std::io::Cursor::new(&mut sequential_block_data);
|
let mut cursor_to_data=std::io::Cursor::new(&mut sequential_block_data);
|
||||||
@ -389,28 +394,33 @@ pub fn write_map<W:BinWriterExt>(mut writer:W,map:strafesnet_common::map::Comple
|
|||||||
attributes:map.attributes.into_iter().map(Into::into).collect(),
|
attributes:map.attributes.into_iter().map(Into::into).collect(),
|
||||||
render_configs:map.render_configs.into_iter().map(Into::into).collect(),
|
render_configs:map.render_configs.into_iter().map(Into::into).collect(),
|
||||||
};
|
};
|
||||||
|
//the map header is a block!
|
||||||
|
block_count+=1;
|
||||||
|
assert_eq!(block_count as usize+1,block_location.len());
|
||||||
let mut file_header=crate::file::Header{
|
let mut file_header=crate::file::Header{
|
||||||
fourcc:crate::file::FourCC::Map,
|
fourcc:crate::file::FourCC::Map,
|
||||||
version:0,
|
version:0,
|
||||||
priming:0,//TODO
|
priming:0,
|
||||||
resource:0,
|
resource:0,
|
||||||
block_count,
|
block_count,
|
||||||
block_location,
|
block_location,
|
||||||
};
|
};
|
||||||
//probe header lengths
|
//probe header length
|
||||||
let mut file_header_data=Vec::new();
|
let mut file_header_data=Vec::new();
|
||||||
binrw::BinWrite::write_le(&file_header,&mut std::io::Cursor::new(&mut file_header_data)).map_err(Error::InvalidData)?;
|
binrw::BinWrite::write_le(&file_header,&mut std::io::Cursor::new(&mut file_header_data)).map_err(Error::InvalidData)?;
|
||||||
let mut map_header_data=Vec::new();
|
let mut map_header_data=Vec::new();
|
||||||
binrw::BinWrite::write_le(&map_header,&mut std::io::Cursor::new(&mut map_header_data)).map_err(Error::InvalidData)?;
|
binrw::BinWrite::write_le(&map_header,&mut std::io::Cursor::new(&mut map_header_data)).map_err(Error::InvalidData)?;
|
||||||
|
|
||||||
//update file header according to probe data
|
//update file header according to probe data
|
||||||
let offset=file_header_data.len() as u64+map_header_data.len() as u64;
|
let mut offset=file_header_data.len() as u64;
|
||||||
file_header.priming=offset;
|
file_header.priming=offset;
|
||||||
for position in &mut file_header.block_location{
|
file_header.block_location[0]=offset;
|
||||||
|
offset+=map_header_data.len() as u64;
|
||||||
|
for position in &mut file_header.block_location[1..]{
|
||||||
*position+=offset;
|
*position+=offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
//write file header
|
//write (updated) file header
|
||||||
writer.write_le(&file_header).map_err(Error::InvalidData)?;
|
writer.write_le(&file_header).map_err(Error::InvalidData)?;
|
||||||
//write map header
|
//write map header
|
||||||
writer.write(&map_header_data).map_err(Error::IO)?;
|
writer.write(&map_header_data).map_err(Error::IO)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user