Compare commits
13 Commits
write
...
workaround
| Author | SHA1 | Date | |
|---|---|---|---|
| b6fede20bf | |||
| 020eae4781 | |||
| 5d25400942 | |||
| a00b6a63c9 | |||
| 931cef52b1 | |||
| 3e8c5167dc | |||
| 2262c6feac | |||
| fa7e7d58bf | |||
| 0705e879db | |||
| d3e114c7b6 | |||
| e1cdddc892 | |||
| 4abeefa7e8 | |||
| 47aef14ff3 |
@@ -1,5 +1,6 @@
|
||||
use binrw::{BinReaderExt, binrw};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error{
|
||||
InvalidHeader,
|
||||
InvalidSegment(binrw::Error),
|
||||
@@ -64,7 +65,7 @@ mod simulation{
|
||||
|
||||
#[binrw]
|
||||
#[brw(little)]
|
||||
#[derive(Clone,Copy,id::Id)]
|
||||
#[derive(Clone,Copy,Debug,id::Id)]
|
||||
pub struct SegmentId(u32);
|
||||
|
||||
#[binrw]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use binrw::BinReaderExt;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error{
|
||||
InvalidHeader,
|
||||
}
|
||||
@@ -27,4 +28,4 @@ impl<R:BinReaderExt> StreamableDemo<R>{
|
||||
pub(crate) fn new(file:crate::file::File<R>)->Result<Self,Error>{
|
||||
Err(Error::InvalidHeader)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
12
src/file.rs
12
src/file.rs
@@ -2,12 +2,19 @@
|
||||
|
||||
use binrw::{binrw, BinReaderExt, io::TakeSeekExt};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error{
|
||||
InvalidHeader(binrw::Error),
|
||||
UnexpectedEOF,
|
||||
InvalidBlockId(BlockId),
|
||||
Seek(std::io::Error),
|
||||
}
|
||||
impl std::fmt::Display for Error{
|
||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||
write!(f,"{self:?}")
|
||||
}
|
||||
}
|
||||
impl std::error::Error for Error{}
|
||||
|
||||
/* spec
|
||||
|
||||
@@ -40,7 +47,7 @@ for block_id in 1..num_blocks{
|
||||
*/
|
||||
#[binrw]
|
||||
#[brw(little)]
|
||||
#[derive(Clone,Copy)]
|
||||
#[derive(Clone,Copy,Debug)]
|
||||
pub(crate) enum FourCC{
|
||||
#[brw(magic=b"SNFM")]
|
||||
Map,
|
||||
@@ -51,6 +58,7 @@ pub(crate) enum FourCC{
|
||||
}
|
||||
#[binrw]
|
||||
#[brw(little)]
|
||||
#[derive(Debug)]
|
||||
pub struct Header{
|
||||
/// Type of file
|
||||
pub fourcc:FourCC,
|
||||
@@ -68,7 +76,7 @@ pub struct Header{
|
||||
|
||||
#[binrw]
|
||||
#[brw(little)]
|
||||
#[derive(Clone,Copy,Hash,id::Id,Eq,PartialEq)]
|
||||
#[derive(Clone,Copy,Debug,Hash,id::Id,Eq,Ord,PartialEq,PartialOrd)]
|
||||
pub struct BlockId(u32);
|
||||
|
||||
pub(crate) struct File<R:BinReaderExt>{
|
||||
|
||||
@@ -7,6 +7,7 @@ pub mod map;
|
||||
pub mod bot;
|
||||
pub mod demo;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error{
|
||||
UnexpectedFourCC,
|
||||
Header(file::Error),
|
||||
@@ -14,6 +15,12 @@ pub enum Error{
|
||||
Bot(bot::Error),
|
||||
Demo(demo::Error),
|
||||
}
|
||||
impl std::fmt::Display for Error{
|
||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||
write!(f,"{self:?}")
|
||||
}
|
||||
}
|
||||
impl std::error::Error for Error{}
|
||||
|
||||
pub enum SNF<R:BinReaderExt>{
|
||||
Map(map::StreamableMap<R>),
|
||||
|
||||
94
src/map.rs
94
src/map.rs
@@ -9,15 +9,23 @@ use strafesnet_common::aabb::Aabb;
|
||||
use strafesnet_common::bvh::BvhNode;
|
||||
use strafesnet_common::gameplay_modes;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error{
|
||||
InvalidHeader(binrw::Error),
|
||||
InvalidBlockId(BlockId),
|
||||
InvalidMeshId(model::MeshId),
|
||||
InvalidModelId(model::ModelId),
|
||||
InvalidTextureId(model::TextureId),
|
||||
InvalidData(binrw::Error),
|
||||
IO(std::io::Error),
|
||||
File(crate::file::Error),
|
||||
}
|
||||
impl std::fmt::Display for Error{
|
||||
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||
write!(f,"{self:?}")
|
||||
}
|
||||
}
|
||||
impl std::error::Error for Error{}
|
||||
|
||||
/* block types
|
||||
|
||||
@@ -137,7 +145,7 @@ struct ResourceExternalHeader{
|
||||
struct MapHeader{
|
||||
num_spacial_blocks:u32,
|
||||
num_resource_blocks:u32,
|
||||
num_resources_external:u32,
|
||||
//num_resources_external:u32,
|
||||
num_modes:u32,
|
||||
num_attributes:u32,
|
||||
num_render_configs:u32,
|
||||
@@ -145,8 +153,8 @@ struct MapHeader{
|
||||
spacial_blocks:Vec<SpacialBlockHeader>,
|
||||
#[br(count=num_resource_blocks)]
|
||||
resource_blocks:Vec<ResourceBlockHeader>,
|
||||
#[br(count=num_resources_external)]
|
||||
external_resources:Vec<ResourceExternalHeader>,
|
||||
//#[br(count=num_resources_external)]
|
||||
//external_resources:Vec<ResourceExternalHeader>,
|
||||
#[br(count=num_modes)]
|
||||
modes:Vec<newtypes::gameplay_modes::Mode>,
|
||||
#[br(count=num_attributes)]
|
||||
@@ -161,18 +169,20 @@ struct Region{
|
||||
//consider including a bvh in the region instead of needing to rebalance the physics bvh on the fly
|
||||
model_count:u32,
|
||||
#[br(count=model_count)]
|
||||
models:Vec<newtypes::model::Model>,
|
||||
models:Vec<(u32,newtypes::model::Model)>,
|
||||
}
|
||||
|
||||
//code deduplication reused in into_complete_map
|
||||
fn read_region<R:BinReaderExt>(file:&mut crate::file::File<R>,block_id:BlockId)->Result<Vec<model::Model>,Error>{
|
||||
fn read_region<R:BinReaderExt>(file:&mut crate::file::File<R>,block_id:BlockId)->Result<Vec<(model::ModelId,model::Model)>,Error>{
|
||||
//load region from disk
|
||||
//parse the models and determine what resources need to be loaded
|
||||
//load resources into self.resources
|
||||
//return Region
|
||||
let mut block=file.block_reader(block_id).map_err(Error::File)?;
|
||||
let region:Region=block.read_le().map_err(Error::InvalidData)?;
|
||||
Ok(region.models.into_iter().map(Into::into).collect())
|
||||
Ok(region.models.into_iter().map(|(model_id,model)|
|
||||
(model::ModelId::new(model_id),model.into())
|
||||
).collect())
|
||||
}
|
||||
fn read_mesh<R:BinReaderExt>(file:&mut crate::file::File<R>,block_id:BlockId)->Result<model::Mesh,Error>{
|
||||
let mut block=file.block_reader(block_id).map_err(Error::File)?;
|
||||
@@ -244,7 +254,7 @@ impl<R:BinReaderExt> StreamableMap<R>{
|
||||
self.bvh.the_tester(aabb,&mut |&block_id|block_ids.push(block_id));
|
||||
block_ids
|
||||
}
|
||||
pub fn load_region(&mut self,block_id:BlockId)->Result<Vec<model::Model>,Error>{
|
||||
pub fn load_region(&mut self,block_id:BlockId)->Result<Vec<(model::ModelId,model::Model)>,Error>{
|
||||
read_region(&mut self.file,block_id)
|
||||
}
|
||||
pub fn load_mesh(&mut self,mesh_id:model::MeshId)->Result<model::Mesh,Error>{
|
||||
@@ -256,20 +266,33 @@ impl<R:BinReaderExt> StreamableMap<R>{
|
||||
read_texture(&mut self.file,block_id)
|
||||
}
|
||||
pub fn into_complete_map(mut self)->Result<strafesnet_common::map::CompleteMap,Error>{
|
||||
//load all meshes
|
||||
let meshes=self.resource_blocks.meshes.into_values().map(|block_id|
|
||||
read_mesh(&mut self.file,block_id)
|
||||
).collect::<Result<Vec<_>,_>>()?;
|
||||
//load all textures
|
||||
let textures=self.resource_blocks.textures.into_values().map(|block_id|
|
||||
read_texture(&mut self.file,block_id)
|
||||
).collect::<Result<Vec<_>,_>>()?;
|
||||
let mut block_ids=Vec::new();
|
||||
self.bvh.into_visitor(&mut |block_id|block_ids.push(block_id));
|
||||
//count on reading the file in sequential order being fastest
|
||||
block_ids.sort_unstable();
|
||||
//load all regions
|
||||
let mut models=Vec::new();
|
||||
let mut model_pairs=HashMap::new();
|
||||
for block_id in block_ids{
|
||||
models.append(&mut read_region(&mut self.file,block_id)?);
|
||||
model_pairs.extend(read_region(&mut self.file,block_id)?);
|
||||
}
|
||||
let mut models=Vec::with_capacity(model_pairs.len());
|
||||
for model_id in 0..model_pairs.len() as u32{
|
||||
let model_id=model::ModelId::new(model_id);
|
||||
models.push(model_pairs.remove(&model_id).ok_or(Error::InvalidModelId(model_id))?);
|
||||
}
|
||||
//load all meshes
|
||||
let mut meshes=Vec::with_capacity(self.resource_blocks.meshes.len());
|
||||
for mesh_id in 0..self.resource_blocks.meshes.len() as u32{
|
||||
let mesh_id=model::MeshId::new(mesh_id);
|
||||
let block_id=self.resource_blocks.meshes[&mesh_id];
|
||||
meshes.push(read_mesh(&mut self.file,block_id)?);
|
||||
};
|
||||
//load all textures
|
||||
let mut textures=Vec::with_capacity(self.resource_blocks.textures.len());
|
||||
for texture_id in 0..self.resource_blocks.textures.len() as u32{
|
||||
let texture_id=model::TextureId::new(texture_id);
|
||||
let block_id=self.resource_blocks.textures[&texture_id];
|
||||
textures.push(read_texture(&mut self.file,block_id)?);
|
||||
}
|
||||
Ok(strafesnet_common::map::CompleteMap{
|
||||
modes:self.modes,
|
||||
@@ -287,7 +310,7 @@ fn collect_spacial_blocks(
|
||||
block_location:&mut Vec<u64>,
|
||||
block_headers:&mut Vec<SpacialBlockHeader>,
|
||||
sequential_block_data:&mut std::io::Cursor<&mut Vec<u8>>,
|
||||
bvh_node:strafesnet_common::bvh::BvhWeightNode<usize,newtypes::model::Model>
|
||||
bvh_node:strafesnet_common::bvh::BvhWeightNode<usize,(model::ModelId,newtypes::model::Model)>
|
||||
)->Result<(),Error>{
|
||||
//inspect the node weights top-down.
|
||||
//When a node weighs less than the limit,
|
||||
@@ -296,11 +319,11 @@ fn collect_spacial_blocks(
|
||||
let mut models=Vec::new();
|
||||
let mut model_count=0;
|
||||
let extents=bvh_node.aabb().clone().into();
|
||||
bvh_node.into_visitor(&mut |model|{
|
||||
bvh_node.into_visitor(&mut |(model_id,model)|{
|
||||
model_count+=1;
|
||||
models.push(model);
|
||||
models.push((model_id.get(),model));
|
||||
});
|
||||
let id=BlockId::new(block_headers.len() as u32);
|
||||
let id=BlockId::new(block_headers.len() as u32+1);
|
||||
block_headers.push(SpacialBlockHeader{
|
||||
id,
|
||||
extents,
|
||||
@@ -328,23 +351,28 @@ fn collect_spacial_blocks(
|
||||
/// otherwise sort by distance to start zone
|
||||
pub fn write_map<W:BinWriterExt>(mut writer:W,map:strafesnet_common::map::CompleteMap)->Result<(),Error>{
|
||||
//serialize models and make a bvh that knows the file size of the branch
|
||||
let boxen=map.models.into_iter().map(|model|{
|
||||
let boxen=map.models.into_iter().enumerate().map(|(model_id,model)|{
|
||||
//grow your own aabb
|
||||
let mesh=map.meshes.get(model.mesh.get() as usize).ok_or(Error::InvalidMeshId(model.mesh))?;
|
||||
let mut aabb=strafesnet_common::aabb::Aabb::default();
|
||||
for &pos in &mesh.unique_pos{
|
||||
aabb.grow(model.transform.transform_point3(pos));
|
||||
}
|
||||
Ok((model.into(),aabb))
|
||||
Ok(((model::ModelId::new(model_id as u32),model.into()),aabb))
|
||||
}).collect::<Result<Vec<_>,_>>()?;
|
||||
let bvh=strafesnet_common::bvh::generate_bvh(boxen).weigh_contents(&|_|std::mem::size_of::<newtypes::model::Model>());
|
||||
//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 sequential_block_data=Vec::new();
|
||||
let mut cursor_to_data=std::io::Cursor::new(&mut sequential_block_data);
|
||||
collect_spacial_blocks(&mut block_location,&mut spacial_blocks,&mut cursor_to_data,bvh)?;
|
||||
let mut block_count=spacial_blocks.len() as u32;//continue block id
|
||||
let mut block_count=spacial_blocks.len() as u32+1;//continue block id
|
||||
let mut resource_blocks=Vec::new();//for map header
|
||||
//meshes
|
||||
for mesh in map.meshes.into_iter(){
|
||||
@@ -371,13 +399,13 @@ pub fn write_map<W:BinWriterExt>(mut writer:W,map:strafesnet_common::map::Comple
|
||||
let map_header=MapHeader{
|
||||
num_spacial_blocks:spacial_blocks.len() as u32,
|
||||
num_resource_blocks:resource_blocks.len() as u32,
|
||||
num_resources_external:0,
|
||||
//num_resources_external:0,
|
||||
num_modes:map.modes.modes.len() as u32,
|
||||
num_attributes:map.attributes.len() as u32,
|
||||
num_render_configs:map.render_configs.len() as u32,
|
||||
spacial_blocks,
|
||||
resource_blocks,
|
||||
external_resources:Vec::new(),
|
||||
//external_resources:Vec::new(),
|
||||
modes:map.modes.modes.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(),
|
||||
@@ -385,25 +413,27 @@ pub fn write_map<W:BinWriterExt>(mut writer:W,map:strafesnet_common::map::Comple
|
||||
let mut file_header=crate::file::Header{
|
||||
fourcc:crate::file::FourCC::Map,
|
||||
version:0,
|
||||
priming:0,//TODO
|
||||
priming:0,
|
||||
resource:0,
|
||||
block_count,
|
||||
block_location,
|
||||
};
|
||||
//probe header lengths
|
||||
//probe header length
|
||||
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)?;
|
||||
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)?;
|
||||
|
||||
//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;
|
||||
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;
|
||||
}
|
||||
|
||||
//write file header
|
||||
//write (updated) file header
|
||||
writer.write_le(&file_header).map_err(Error::InvalidData)?;
|
||||
//write map header
|
||||
writer.write(&map_header_data).map_err(Error::IO)?;
|
||||
|
||||
@@ -1,24 +1,44 @@
|
||||
use super::integer::{Time,Planar64,Planar64Vec3};
|
||||
|
||||
#[binrw::binrw]
|
||||
#[brw(little,repr=u8)]
|
||||
pub enum Boolio{
|
||||
True,
|
||||
False
|
||||
}
|
||||
impl Into<bool> for Boolio{
|
||||
fn into(self)->bool{
|
||||
match self{
|
||||
Boolio::True=>true,
|
||||
Boolio::False=>false,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<bool> for Boolio{
|
||||
fn from(value:bool)->Self{
|
||||
match value{
|
||||
true=>Boolio::True,
|
||||
false=>Boolio::False,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[binrw::binrw]
|
||||
#[brw(little)]
|
||||
pub struct ContactingLadder{
|
||||
pub sticky:Option<()>,
|
||||
pub sticky:Boolio,
|
||||
}
|
||||
impl Into<strafesnet_common::gameplay_attributes::ContactingLadder> for ContactingLadder{
|
||||
fn into(self)->strafesnet_common::gameplay_attributes::ContactingLadder{
|
||||
strafesnet_common::gameplay_attributes::ContactingLadder{
|
||||
sticky:self.sticky.is_some(),
|
||||
sticky:self.sticky.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<strafesnet_common::gameplay_attributes::ContactingLadder> for ContactingLadder{
|
||||
fn from(value:strafesnet_common::gameplay_attributes::ContactingLadder)->Self{
|
||||
Self{
|
||||
sticky:match value.sticky{
|
||||
true=>Some(()),
|
||||
false=>None,
|
||||
}
|
||||
sticky:value.sticky.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,10 +46,15 @@ impl From<strafesnet_common::gameplay_attributes::ContactingLadder> for Contacti
|
||||
#[binrw::binrw]
|
||||
#[brw(little)]
|
||||
pub enum ContactingBehaviour{
|
||||
#[brw(magic=0u8)]
|
||||
Surf,
|
||||
#[brw(magic=1u8)]
|
||||
Ladder(ContactingLadder),
|
||||
#[brw(magic=2u8)]
|
||||
NoJump,
|
||||
#[brw(magic=3u8)]
|
||||
Cling,
|
||||
#[brw(magic=4u8)]
|
||||
Elastic(u32),
|
||||
}
|
||||
impl Into<strafesnet_common::gameplay_attributes::ContactingBehaviour> for ContactingBehaviour{
|
||||
@@ -118,7 +143,9 @@ impl From<strafesnet_common::gameplay_attributes::Accelerator> for Accelerator{
|
||||
#[binrw::binrw]
|
||||
#[brw(little)]
|
||||
pub enum Booster{
|
||||
#[brw(magic=0u8)]
|
||||
Velocity(Planar64Vec3),
|
||||
#[brw(magic=1u8)]
|
||||
Energy{direction:Planar64Vec3,energy:Planar64},
|
||||
}
|
||||
impl Into<strafesnet_common::gameplay_attributes::Booster> for Booster{
|
||||
@@ -180,18 +207,24 @@ impl From<strafesnet_common::gameplay_attributes::TrajectoryChoice> for Trajecto
|
||||
#[binrw::binrw]
|
||||
#[brw(little)]
|
||||
pub enum SetTrajectory{
|
||||
#[brw(magic=0u8)]
|
||||
AirTime(Time),
|
||||
#[brw(magic=1u8)]
|
||||
Height(Planar64),
|
||||
#[brw(magic=2u8)]
|
||||
DotVelocity{direction:Planar64Vec3,dot:Planar64},
|
||||
#[brw(magic=3u8)]
|
||||
TargetPointTime{
|
||||
target_point:Planar64Vec3,
|
||||
time:Time,
|
||||
},
|
||||
#[brw(magic=4u8)]
|
||||
TargetPointSpeed{
|
||||
target_point:Planar64Vec3,
|
||||
speed:Planar64,
|
||||
trajectory_choice:TrajectoryChoice,
|
||||
},
|
||||
#[brw(magic=5u8)]
|
||||
Velocity(Planar64Vec3),
|
||||
}
|
||||
impl Into<strafesnet_common::gameplay_attributes::SetTrajectory> for SetTrajectory{
|
||||
@@ -283,31 +316,50 @@ impl From<strafesnet_common::gameplay_attributes::Wormhole> for Wormhole{
|
||||
}
|
||||
}
|
||||
|
||||
#[binrw::binrw]
|
||||
#[brw(little)]
|
||||
pub struct GeneralAttributesHeader{
|
||||
pub booster:u8,
|
||||
pub trajectory:u8,
|
||||
pub wormhole:u8,
|
||||
pub accelerator:u8,
|
||||
}
|
||||
#[binrw::binrw]
|
||||
#[brw(little)]
|
||||
pub struct GeneralAttributes{
|
||||
pub booster:Option<Booster>,
|
||||
pub trajectory:Option<SetTrajectory>,
|
||||
pub wormhole:Option<Wormhole>,
|
||||
pub accelerator:Option<Accelerator>,
|
||||
pub header:GeneralAttributesHeader,
|
||||
#[br(count=header.booster)]
|
||||
pub booster:Vec<Booster>,
|
||||
#[br(count=header.trajectory)]
|
||||
pub trajectory:Vec<SetTrajectory>,
|
||||
#[br(count=header.wormhole)]
|
||||
pub wormhole:Vec<Wormhole>,
|
||||
#[br(count=header.accelerator)]
|
||||
pub accelerator:Vec<Accelerator>,
|
||||
}
|
||||
impl Into<strafesnet_common::gameplay_attributes::GeneralAttributes> for GeneralAttributes{
|
||||
fn into(self)->strafesnet_common::gameplay_attributes::GeneralAttributes{
|
||||
fn into(mut self)->strafesnet_common::gameplay_attributes::GeneralAttributes{
|
||||
strafesnet_common::gameplay_attributes::GeneralAttributes{
|
||||
booster:self.booster.map(Into::into),
|
||||
trajectory:self.trajectory.map(Into::into),
|
||||
wormhole:self.wormhole.map(Into::into),
|
||||
accelerator:self.accelerator.map(Into::into),
|
||||
booster:self.booster.pop().map(Into::into),
|
||||
trajectory:self.trajectory.pop().map(Into::into),
|
||||
wormhole:self.wormhole.pop().map(Into::into),
|
||||
accelerator:self.accelerator.pop().map(Into::into),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<strafesnet_common::gameplay_attributes::GeneralAttributes> for GeneralAttributes{
|
||||
fn from(value:strafesnet_common::gameplay_attributes::GeneralAttributes)->Self{
|
||||
Self{
|
||||
booster:value.booster.map(Into::into),
|
||||
trajectory:value.trajectory.map(Into::into),
|
||||
wormhole:value.wormhole.map(Into::into),
|
||||
accelerator:value.accelerator.map(Into::into),
|
||||
header:GeneralAttributesHeader{
|
||||
booster:value.booster.is_some() as u8,
|
||||
trajectory:value.trajectory.is_some() as u8,
|
||||
wormhole:value.wormhole.is_some() as u8,
|
||||
accelerator:value.accelerator.is_some() as u8,
|
||||
},
|
||||
booster:super::gameplay_style::stupid(value.booster.map(Into::into)),
|
||||
trajectory:super::gameplay_style::stupid(value.trajectory.map(Into::into)),
|
||||
wormhole:super::gameplay_style::stupid(value.wormhole.map(Into::into)),
|
||||
accelerator:super::gameplay_style::stupid(value.accelerator.map(Into::into)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -315,19 +367,22 @@ impl From<strafesnet_common::gameplay_attributes::GeneralAttributes> for General
|
||||
#[binrw::binrw]
|
||||
#[brw(little)]
|
||||
pub struct ContactingAttributes{
|
||||
pub contact_behaviour:Option<ContactingBehaviour>,
|
||||
pub contact_behaviour_enabled:u8,
|
||||
#[br(count=contact_behaviour_enabled)]
|
||||
pub contact_behaviour:Vec<ContactingBehaviour>,
|
||||
}
|
||||
impl Into<strafesnet_common::gameplay_attributes::ContactingAttributes> for ContactingAttributes{
|
||||
fn into(self)->strafesnet_common::gameplay_attributes::ContactingAttributes{
|
||||
fn into(mut self)->strafesnet_common::gameplay_attributes::ContactingAttributes{
|
||||
strafesnet_common::gameplay_attributes::ContactingAttributes{
|
||||
contact_behaviour:self.contact_behaviour.map(Into::into),
|
||||
contact_behaviour:self.contact_behaviour.pop().map(Into::into),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<strafesnet_common::gameplay_attributes::ContactingAttributes> for ContactingAttributes{
|
||||
fn from(value:strafesnet_common::gameplay_attributes::ContactingAttributes)->Self{
|
||||
Self{
|
||||
contact_behaviour:value.contact_behaviour.map(Into::into),
|
||||
contact_behaviour_enabled:value.contact_behaviour.is_some() as u8,
|
||||
contact_behaviour:super::gameplay_style::stupid(value.contact_behaviour.map(Into::into)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -335,19 +390,22 @@ impl From<strafesnet_common::gameplay_attributes::ContactingAttributes> for Cont
|
||||
#[binrw::binrw]
|
||||
#[brw(little)]
|
||||
pub struct IntersectingAttributes{
|
||||
pub water:Option<IntersectingWater>,
|
||||
pub water_enabled:u8,
|
||||
#[br(count=water_enabled)]
|
||||
pub water:Vec<IntersectingWater>,
|
||||
}
|
||||
impl Into<strafesnet_common::gameplay_attributes::IntersectingAttributes> for IntersectingAttributes{
|
||||
fn into(self)->strafesnet_common::gameplay_attributes::IntersectingAttributes{
|
||||
fn into(mut self)->strafesnet_common::gameplay_attributes::IntersectingAttributes{
|
||||
strafesnet_common::gameplay_attributes::IntersectingAttributes{
|
||||
water:self.water.map(Into::into),
|
||||
water:self.water.pop().map(Into::into),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<strafesnet_common::gameplay_attributes::IntersectingAttributes> for IntersectingAttributes{
|
||||
fn from(value:strafesnet_common::gameplay_attributes::IntersectingAttributes)->Self{
|
||||
Self{
|
||||
water:value.water.map(Into::into),
|
||||
water_enabled:value.water.is_some() as u8,
|
||||
water:super::gameplay_style::stupid(value.water.map(Into::into)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -355,11 +413,14 @@ impl From<strafesnet_common::gameplay_attributes::IntersectingAttributes> for In
|
||||
#[binrw::binrw]
|
||||
#[brw(little)]
|
||||
pub enum CollisionAttributes{
|
||||
#[brw(magic=0u8)]
|
||||
Decoration,
|
||||
#[brw(magic=1u8)]
|
||||
Contact{
|
||||
contacting:ContactingAttributes,
|
||||
general:GeneralAttributes,
|
||||
},
|
||||
#[brw(magic=2u8)]
|
||||
Intersect{
|
||||
intersecting:IntersectingAttributes,
|
||||
general:GeneralAttributes,
|
||||
|
||||
@@ -40,16 +40,18 @@ impl From<strafesnet_common::gameplay_modes::StageElementBehaviour> for StageEle
|
||||
pub struct StageElement{
|
||||
pub stage_id:u32,//which stage spawn to send to
|
||||
pub behaviour:StageElementBehaviour,
|
||||
pub jump_limit:Option<u8>,
|
||||
pub force:Option<()>,//allow setting to lower spawn id i.e. 7->3
|
||||
pub jump_limit_enabled:u8,
|
||||
#[br(count=jump_limit_enabled)]
|
||||
pub jump_limit:Vec<u8>,
|
||||
pub force:super::gameplay_attributes::Boolio,//allow setting to lower spawn id i.e. 7->3
|
||||
}
|
||||
impl Into<strafesnet_common::gameplay_modes::StageElement> for StageElement{
|
||||
fn into(self)->strafesnet_common::gameplay_modes::StageElement{
|
||||
fn into(mut self)->strafesnet_common::gameplay_modes::StageElement{
|
||||
strafesnet_common::gameplay_modes::StageElement::new(
|
||||
strafesnet_common::gameplay_modes::StageId::new(self.stage_id),
|
||||
self.force.is_some(),
|
||||
self.force.into(),
|
||||
self.behaviour.into(),
|
||||
self.jump_limit,
|
||||
self.jump_limit.pop(),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -58,8 +60,9 @@ impl From<strafesnet_common::gameplay_modes::StageElement> for StageElement{
|
||||
Self{
|
||||
stage_id:value.stage_id().get(),
|
||||
behaviour:value.behaviour().into(),
|
||||
jump_limit:value.jump_limit(),
|
||||
force:match value.force(){true=>Some(()),false=>None},
|
||||
jump_limit_enabled:value.jump_limit().is_some() as u8,
|
||||
jump_limit:super::gameplay_style::stupid(value.jump_limit()),
|
||||
force:value.force().into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,7 +117,8 @@ impl From<strafesnet_common::gameplay_modes::Stage> for Stage{
|
||||
}
|
||||
|
||||
#[binrw::binrw]
|
||||
#[brw(little,repr=u8)]
|
||||
#[brw(little,repr=u32)]
|
||||
#[repr(u32)]
|
||||
pub enum Zone{
|
||||
Start,
|
||||
Finish,
|
||||
@@ -141,6 +145,7 @@ impl From<strafesnet_common::gameplay_modes::Zone> for Zone{
|
||||
|
||||
#[binrw::binrw]
|
||||
#[brw(little)]
|
||||
#[derive(Debug)]
|
||||
pub struct ModeHeader{
|
||||
pub zones:u32,
|
||||
pub stages:u32,
|
||||
|
||||
@@ -2,34 +2,52 @@ use super::integer::{Time,Ratio64,Planar64,Planar64Vec3};
|
||||
|
||||
pub type Controls=u32;
|
||||
|
||||
#[binrw::binrw]
|
||||
#[brw(little)]
|
||||
pub struct StyleModifiersHeader{
|
||||
pub strafe:u8,
|
||||
pub rocket:u8,
|
||||
pub jump:u8,
|
||||
pub walk:u8,
|
||||
pub ladder:u8,
|
||||
pub swim:u8,
|
||||
}
|
||||
|
||||
#[binrw::binrw]
|
||||
#[brw(little)]
|
||||
pub struct StyleModifiers{
|
||||
pub header:StyleModifiersHeader,
|
||||
pub controls_mask:Controls,
|
||||
pub controls_mask_state:Controls,
|
||||
pub strafe:Option<StrafeSettings>,
|
||||
pub rocket:Option<PropulsionSettings>,
|
||||
pub jump:Option<JumpSettings>,
|
||||
pub walk:Option<WalkSettings>,
|
||||
pub ladder:Option<LadderSettings>,
|
||||
pub swim:Option<PropulsionSettings>,
|
||||
#[br(count=header.strafe)]
|
||||
pub strafe:Vec<StrafeSettings>,
|
||||
#[br(count=header.rocket)]
|
||||
pub rocket:Vec<PropulsionSettings>,
|
||||
#[br(count=header.jump)]
|
||||
pub jump:Vec<JumpSettings>,
|
||||
#[br(count=header.walk)]
|
||||
pub walk:Vec<WalkSettings>,
|
||||
#[br(count=header.ladder)]
|
||||
pub ladder:Vec<LadderSettings>,
|
||||
#[br(count=header.swim)]
|
||||
pub swim:Vec<PropulsionSettings>,
|
||||
pub gravity:Planar64Vec3,
|
||||
pub hitbox:Hitbox,
|
||||
pub camera_offset:Planar64Vec3,
|
||||
pub mass:Planar64,
|
||||
}
|
||||
impl Into<strafesnet_common::gameplay_style::StyleModifiers> for StyleModifiers{
|
||||
fn into(self)->strafesnet_common::gameplay_style::StyleModifiers{
|
||||
fn into(mut self)->strafesnet_common::gameplay_style::StyleModifiers{
|
||||
strafesnet_common::gameplay_style::StyleModifiers{
|
||||
//TODO: fail gracefully in binrw instead of panicing here
|
||||
controls_mask:strafesnet_common::controls_bitflag::Controls::from_bits(self.controls_mask).unwrap(),
|
||||
controls_mask_state:strafesnet_common::controls_bitflag::Controls::from_bits(self.controls_mask_state).unwrap(),
|
||||
strafe:self.strafe.map(Into::into),
|
||||
rocket:self.rocket.map(Into::into),
|
||||
jump:self.jump.map(Into::into),
|
||||
walk:self.walk.map(Into::into),
|
||||
ladder:self.ladder.map(Into::into),
|
||||
swim:self.swim.map(Into::into),
|
||||
strafe:self.strafe.pop().map(Into::into),
|
||||
rocket:self.rocket.pop().map(Into::into),
|
||||
jump:self.jump.pop().map(Into::into),
|
||||
walk:self.walk.pop().map(Into::into),
|
||||
ladder:self.ladder.pop().map(Into::into),
|
||||
swim:self.swim.pop().map(Into::into),
|
||||
gravity:strafesnet_common::integer::Planar64Vec3::raw_array(self.gravity),
|
||||
hitbox:self.hitbox.into(),
|
||||
camera_offset:strafesnet_common::integer::Planar64Vec3::raw_array(self.camera_offset),
|
||||
@@ -37,17 +55,31 @@ impl Into<strafesnet_common::gameplay_style::StyleModifiers> for StyleModifiers{
|
||||
}
|
||||
}
|
||||
}
|
||||
pub(crate) fn stupid<T>(o:Option<T>)->Vec<T>{
|
||||
match o{
|
||||
Some(v)=>vec![v],
|
||||
None=>Vec::new(),
|
||||
}
|
||||
}
|
||||
impl From<strafesnet_common::gameplay_style::StyleModifiers> for StyleModifiers{
|
||||
fn from(value:strafesnet_common::gameplay_style::StyleModifiers)->Self{
|
||||
Self{
|
||||
header:StyleModifiersHeader{
|
||||
strafe:value.strafe.is_some() as u8,
|
||||
rocket:value.rocket.is_some() as u8,
|
||||
jump:value.jump.is_some() as u8,
|
||||
walk:value.walk.is_some() as u8,
|
||||
ladder:value.ladder.is_some() as u8,
|
||||
swim:value.swim.is_some() as u8,
|
||||
},
|
||||
controls_mask:value.controls_mask.bits(),
|
||||
controls_mask_state:value.controls_mask_state.bits(),
|
||||
strafe:value.strafe.map(Into::into),
|
||||
rocket:value.rocket.map(Into::into),
|
||||
jump:value.jump.map(Into::into),
|
||||
walk:value.walk.map(Into::into),
|
||||
ladder:value.ladder.map(Into::into),
|
||||
swim:value.swim.map(Into::into),
|
||||
strafe:stupid(value.strafe.map(Into::into)),
|
||||
rocket:stupid(value.rocket.map(Into::into)),
|
||||
jump:stupid(value.jump.map(Into::into)),
|
||||
walk:stupid(value.walk.map(Into::into)),
|
||||
ladder:stupid(value.ladder.map(Into::into)),
|
||||
swim:stupid(value.swim.map(Into::into)),
|
||||
gravity:value.gravity.get().to_array(),
|
||||
hitbox:value.hitbox.into(),
|
||||
camera_offset:value.camera_offset.get().to_array(),
|
||||
@@ -142,15 +174,17 @@ impl From<strafesnet_common::gameplay_style::ControlsActivation> for ControlsAct
|
||||
pub struct StrafeSettings{
|
||||
enable:ControlsActivation,
|
||||
mv:Planar64,
|
||||
air_accel_limit:Option<Planar64>,
|
||||
air_accel_limit_enabled:u8,
|
||||
#[br(count=air_accel_limit_enabled)]
|
||||
air_accel_limit:Vec<Planar64>,
|
||||
tick_rate:Ratio64,
|
||||
}
|
||||
impl Into<strafesnet_common::gameplay_style::StrafeSettings> for StrafeSettings{
|
||||
fn into(self)->strafesnet_common::gameplay_style::StrafeSettings{
|
||||
fn into(mut self)->strafesnet_common::gameplay_style::StrafeSettings{
|
||||
strafesnet_common::gameplay_style::StrafeSettings::new(
|
||||
self.enable.into(),
|
||||
strafesnet_common::integer::Planar64::raw(self.mv),
|
||||
self.air_accel_limit.map(strafesnet_common::integer::Planar64::raw),
|
||||
self.air_accel_limit.pop().map(strafesnet_common::integer::Planar64::raw),
|
||||
self.tick_rate.into(),
|
||||
)
|
||||
}
|
||||
@@ -161,7 +195,8 @@ impl From<strafesnet_common::gameplay_style::StrafeSettings> for StrafeSettings{
|
||||
Self{
|
||||
enable:enable.into(),
|
||||
mv:mv.get(),
|
||||
air_accel_limit:air_accel_limit.map(|a|a.get()),
|
||||
air_accel_limit_enabled:air_accel_limit.is_some() as u8,
|
||||
air_accel_limit:stupid(air_accel_limit.map(|a|a.get())),
|
||||
tick_rate:tick_rate.into(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,19 +60,22 @@ impl From<strafesnet_common::model::PolygonGroup> for PolygonGroup{
|
||||
#[binrw::binrw]
|
||||
#[brw(little)]
|
||||
pub struct RenderConfig{
|
||||
pub texture:Option<u32>,
|
||||
pub texture_enabled:u8,
|
||||
#[br(count=texture_enabled)]
|
||||
pub texture:Vec<u32>,
|
||||
}
|
||||
impl Into<strafesnet_common::model::RenderConfig> for RenderConfig{
|
||||
fn into(self)->strafesnet_common::model::RenderConfig{
|
||||
fn into(mut self)->strafesnet_common::model::RenderConfig{
|
||||
strafesnet_common::model::RenderConfig{
|
||||
texture:self.texture.map(strafesnet_common::model::TextureId::new),
|
||||
texture:self.texture.pop().map(strafesnet_common::model::TextureId::new),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<strafesnet_common::model::RenderConfig> for RenderConfig{
|
||||
fn from(value:strafesnet_common::model::RenderConfig)->Self{
|
||||
Self{
|
||||
texture:value.texture.map(|texture_id|texture_id.get()),
|
||||
texture_enabled:value.texture.is_some() as u8,
|
||||
texture:super::gameplay_style::stupid(value.texture.map(|texture_id|texture_id.get())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user