9 Commits

Author SHA1 Message Date
60cebc0607 whoops forgot file header 2024-07-25 16:06:47 -07:00
a3aa6ea7d5 finish write file 2024-07-25 15:33:55 -07:00
e81909d375 wip write file 2024-07-25 15:03:37 -07:00
340ddad47e done 2024-07-25 12:38:17 -07:00
320b8726ee wip 2024-07-25 12:10:22 -07:00
7479a67e29 wip 2024-07-25 12:08:01 -07:00
c786392275 wip 2024-07-25 11:45:05 -07:00
d4e3235935 boiling wip 2024-07-25 11:33:45 -07:00
a18c56f235 wip 2024-07-25 11:33:45 -07:00
11 changed files with 94 additions and 279 deletions

View File

@@ -1,6 +1,5 @@
use binrw::{BinReaderExt, binrw};
#[derive(Debug)]
pub enum Error{
InvalidHeader,
InvalidSegment(binrw::Error),
@@ -65,7 +64,7 @@ mod simulation{
#[binrw]
#[brw(little)]
#[derive(Clone,Copy,Debug,id::Id)]
#[derive(Clone,Copy,id::Id)]
pub struct SegmentId(u32);
#[binrw]

View File

@@ -1,6 +1,5 @@
use binrw::BinReaderExt;
#[derive(Debug)]
pub enum Error{
InvalidHeader,
}
@@ -28,4 +27,4 @@ impl<R:BinReaderExt> StreamableDemo<R>{
pub(crate) fn new(file:crate::file::File<R>)->Result<Self,Error>{
Err(Error::InvalidHeader)
}
}
}

View File

@@ -2,19 +2,12 @@
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
@@ -47,7 +40,7 @@ for block_id in 1..num_blocks{
*/
#[binrw]
#[brw(little)]
#[derive(Clone,Copy,Debug)]
#[derive(Clone,Copy)]
pub(crate) enum FourCC{
#[brw(magic=b"SNFM")]
Map,
@@ -58,7 +51,6 @@ pub(crate) enum FourCC{
}
#[binrw]
#[brw(little)]
#[derive(Debug)]
pub struct Header{
/// Type of file
pub fourcc:FourCC,
@@ -76,7 +68,7 @@ pub struct Header{
#[binrw]
#[brw(little)]
#[derive(Clone,Copy,Debug,Hash,id::Id,Eq,Ord,PartialEq,PartialOrd)]
#[derive(Clone,Copy,Hash,id::Id,Eq,PartialEq)]
pub struct BlockId(u32);
pub(crate) struct File<R:BinReaderExt>{

View File

@@ -7,7 +7,6 @@ pub mod map;
pub mod bot;
pub mod demo;
#[derive(Debug)]
pub enum Error{
UnexpectedFourCC,
Header(file::Error),
@@ -15,12 +14,6 @@ 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>),

View File

@@ -9,23 +9,15 @@ 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
@@ -145,7 +137,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,
@@ -153,8 +145,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)]
@@ -169,20 +161,18 @@ 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<(u32,newtypes::model::Model)>,
models:Vec<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::ModelId,model::Model)>,Error>{
fn read_region<R:BinReaderExt>(file:&mut crate::file::File<R>,block_id:BlockId)->Result<Vec<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(|(model_id,model)|
(model::ModelId::new(model_id),model.into())
).collect())
Ok(region.models.into_iter().map(Into::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)?;
@@ -254,7 +244,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::ModelId,model::Model)>,Error>{
pub fn load_region(&mut self,block_id:BlockId)->Result<Vec<model::Model>,Error>{
read_region(&mut self.file,block_id)
}
pub fn load_mesh(&mut self,mesh_id:model::MeshId)->Result<model::Mesh,Error>{
@@ -266,33 +256,20 @@ 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 model_pairs=HashMap::new();
let mut models=Vec::new();
for block_id in block_ids{
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)?);
models.append(&mut read_region(&mut self.file,block_id)?);
}
Ok(strafesnet_common::map::CompleteMap{
modes:self.modes,
@@ -310,7 +287,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,(model::ModelId,newtypes::model::Model)>
bvh_node:strafesnet_common::bvh::BvhWeightNode<usize,newtypes::model::Model>
)->Result<(),Error>{
//inspect the node weights top-down.
//When a node weighs less than the limit,
@@ -319,11 +296,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_id,model)|{
bvh_node.into_visitor(&mut |model|{
model_count+=1;
models.push((model_id.get(),model));
models.push(model);
});
let id=BlockId::new(block_headers.len() as u32+1);
let id=BlockId::new(block_headers.len() as u32);
block_headers.push(SpacialBlockHeader{
id,
extents,
@@ -351,28 +328,23 @@ 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().enumerate().map(|(model_id,model)|{
let boxen=map.models.into_iter().map(|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::ModelId::new(model_id as u32),model.into()),aabb))
Ok((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
//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 block_location=vec![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+1;//continue block id
let mut block_count=spacial_blocks.len() as u32;//continue block id
let mut resource_blocks=Vec::new();//for map header
//meshes
for mesh in map.meshes.into_iter(){
@@ -399,13 +371,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(),
@@ -413,27 +385,25 @@ 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,
priming:0,//TODO
resource:0,
block_count,
block_location,
};
//probe header length
//probe header lengths
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 mut offset=file_header_data.len() as u64;
let offset=file_header_data.len() as u64+map_header_data.len() as u64;
file_header.priming=offset;
file_header.block_location[0]=offset;
offset+=map_header_data.len() as u64;
for position in &mut file_header.block_location[1..]{
for position in &mut file_header.block_location{
*position+=offset;
}
//write (updated) file header
//write file header
writer.write_le(&file_header).map_err(Error::InvalidData)?;
//write map header
writer.write(&map_header_data).map_err(Error::IO)?;

View File

@@ -1,4 +1,3 @@
mod common;
pub mod aabb;
pub mod model;
pub mod integer;

View File

@@ -1,26 +0,0 @@
pub const fn flag(b:bool,mask:u8)->u8{
(-(b as i8) as u8)&mask
}
#[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,
}
}
}

View File

@@ -1,22 +1,24 @@
use super::common::{flag,Boolio};
use super::integer::{Time,Planar64,Planar64Vec3};
#[binrw::binrw]
#[brw(little)]
pub struct ContactingLadder{
pub sticky:Boolio,
pub sticky:Option<()>,
}
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.into(),
sticky:self.sticky.is_some(),
}
}
}
impl From<strafesnet_common::gameplay_attributes::ContactingLadder> for ContactingLadder{
fn from(value:strafesnet_common::gameplay_attributes::ContactingLadder)->Self{
Self{
sticky:value.sticky.into(),
sticky:match value.sticky{
true=>Some(()),
false=>None,
}
}
}
}
@@ -24,15 +26,10 @@ 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{
@@ -121,9 +118,7 @@ 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{
@@ -185,24 +180,18 @@ 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{
@@ -297,22 +286,11 @@ impl From<strafesnet_common::gameplay_attributes::Wormhole> for Wormhole{
#[binrw::binrw]
#[brw(little)]
pub struct GeneralAttributes{
pub header:u8,
#[br(if(header&Self::BOOSTER!=0))]
pub booster:Option<Booster>,
#[br(if(header&Self::TRAJECTORY!=0))]
pub trajectory:Option<SetTrajectory>,
#[br(if(header&Self::WORMHOLE!=0))]
pub wormhole:Option<Wormhole>,
#[br(if(header&Self::ACCELERATOR!=0))]
pub accelerator:Option<Accelerator>,
}
impl GeneralAttributes{
const BOOSTER:u8=1<<0;
const TRAJECTORY:u8=1<<1;
const WORMHOLE:u8=1<<2;
const ACCELERATOR:u8=1<<3;
}
impl Into<strafesnet_common::gameplay_attributes::GeneralAttributes> for GeneralAttributes{
fn into(self)->strafesnet_common::gameplay_attributes::GeneralAttributes{
strafesnet_common::gameplay_attributes::GeneralAttributes{
@@ -325,13 +303,7 @@ impl Into<strafesnet_common::gameplay_attributes::GeneralAttributes> for General
}
impl From<strafesnet_common::gameplay_attributes::GeneralAttributes> for GeneralAttributes{
fn from(value:strafesnet_common::gameplay_attributes::GeneralAttributes)->Self{
let header=
flag(value.booster.is_some(),GeneralAttributes::BOOSTER)
|flag(value.trajectory.is_some(),GeneralAttributes::TRAJECTORY)
|flag(value.wormhole.is_some(),GeneralAttributes::WORMHOLE)
|flag(value.accelerator.is_some(),GeneralAttributes::ACCELERATOR);
Self{
header,
booster:value.booster.map(Into::into),
trajectory:value.trajectory.map(Into::into),
wormhole:value.wormhole.map(Into::into),
@@ -343,13 +315,8 @@ impl From<strafesnet_common::gameplay_attributes::GeneralAttributes> for General
#[binrw::binrw]
#[brw(little)]
pub struct ContactingAttributes{
pub header:u8,
#[br(if(header&Self::CONTACTING_BEHAVIOUR!=0))]
pub contact_behaviour:Option<ContactingBehaviour>,
}
impl ContactingAttributes{
const CONTACTING_BEHAVIOUR:u8=1<<0;
}
impl Into<strafesnet_common::gameplay_attributes::ContactingAttributes> for ContactingAttributes{
fn into(self)->strafesnet_common::gameplay_attributes::ContactingAttributes{
strafesnet_common::gameplay_attributes::ContactingAttributes{
@@ -360,7 +327,6 @@ impl Into<strafesnet_common::gameplay_attributes::ContactingAttributes> for Cont
impl From<strafesnet_common::gameplay_attributes::ContactingAttributes> for ContactingAttributes{
fn from(value:strafesnet_common::gameplay_attributes::ContactingAttributes)->Self{
Self{
header:flag(value.contact_behaviour.is_some(),ContactingAttributes::CONTACTING_BEHAVIOUR),
contact_behaviour:value.contact_behaviour.map(Into::into),
}
}
@@ -369,13 +335,8 @@ impl From<strafesnet_common::gameplay_attributes::ContactingAttributes> for Cont
#[binrw::binrw]
#[brw(little)]
pub struct IntersectingAttributes{
pub header:u8,
#[br(if(header&Self::INTERSECTING_WATER!=0))]
pub water:Option<IntersectingWater>,
}
impl IntersectingAttributes{
const INTERSECTING_WATER:u8=1<<0;
}
impl Into<strafesnet_common::gameplay_attributes::IntersectingAttributes> for IntersectingAttributes{
fn into(self)->strafesnet_common::gameplay_attributes::IntersectingAttributes{
strafesnet_common::gameplay_attributes::IntersectingAttributes{
@@ -386,7 +347,6 @@ impl Into<strafesnet_common::gameplay_attributes::IntersectingAttributes> for In
impl From<strafesnet_common::gameplay_attributes::IntersectingAttributes> for IntersectingAttributes{
fn from(value:strafesnet_common::gameplay_attributes::IntersectingAttributes)->Self{
Self{
header:flag(value.water.is_some(),IntersectingAttributes::INTERSECTING_WATER),
water:value.water.map(Into::into),
}
}
@@ -395,14 +355,11 @@ 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,

View File

@@ -1,60 +1,65 @@
use super::common::flag;
#[binrw::binrw]
#[brw(little,repr=u8)]
pub enum StageElementBehaviour{
SpawnAt,//must be standing on top to get effect. except cancollide false
Trigger,
Teleport,
Platform,
//Check(point) acts like a trigger if you haven't hit all the checkpoints on previous stages yet.
//Note that all stage elements act like this, this is just the isolated behaviour.
Check,
Checkpoint,//this is a combined behaviour for Ordered & Unordered in case a model is used multiple times or for both.
}
impl Into<strafesnet_common::gameplay_modes::StageElementBehaviour> for StageElementBehaviour{
fn into(self)->strafesnet_common::gameplay_modes::StageElementBehaviour{
match self{
StageElementBehaviour::SpawnAt=>strafesnet_common::gameplay_modes::StageElementBehaviour::SpawnAt,
StageElementBehaviour::Trigger=>strafesnet_common::gameplay_modes::StageElementBehaviour::Trigger,
StageElementBehaviour::Teleport=>strafesnet_common::gameplay_modes::StageElementBehaviour::Teleport,
StageElementBehaviour::Platform=>strafesnet_common::gameplay_modes::StageElementBehaviour::Platform,
StageElementBehaviour::Check=>strafesnet_common::gameplay_modes::StageElementBehaviour::Check,
StageElementBehaviour::Checkpoint=>strafesnet_common::gameplay_modes::StageElementBehaviour::Checkpoint,
}
}
}
impl From<strafesnet_common::gameplay_modes::StageElementBehaviour> for StageElementBehaviour{
fn from(value:strafesnet_common::gameplay_modes::StageElementBehaviour)->Self{
match value{
strafesnet_common::gameplay_modes::StageElementBehaviour::SpawnAt=>StageElementBehaviour::SpawnAt,
strafesnet_common::gameplay_modes::StageElementBehaviour::Trigger=>StageElementBehaviour::Trigger,
strafesnet_common::gameplay_modes::StageElementBehaviour::Teleport=>StageElementBehaviour::Teleport,
strafesnet_common::gameplay_modes::StageElementBehaviour::Platform=>StageElementBehaviour::Platform,
strafesnet_common::gameplay_modes::StageElementBehaviour::Check=>StageElementBehaviour::Check,
strafesnet_common::gameplay_modes::StageElementBehaviour::Checkpoint=>StageElementBehaviour::Checkpoint,
}
}
}
#[binrw::binrw]
#[brw(little)]
pub struct StageElement{
pub header:u8,
pub stage_id:u32,
#[br(if(header&Self::JUMP_LIMIT!=0))]
pub stage_id:u32,//which stage spawn to send to
pub behaviour:StageElementBehaviour,
pub jump_limit:Option<u8>,
}
impl StageElement{
const BEHAVIOUR:u8=0b00111;
const JUMP_LIMIT:u8=1<<3;
const FORCE:u8=1<<4;
const fn behaviour(&self)->Option<strafesnet_common::gameplay_modes::StageElementBehaviour>{
match self.header&Self::BEHAVIOUR{
0=>Some(strafesnet_common::gameplay_modes::StageElementBehaviour::SpawnAt),
1=>Some(strafesnet_common::gameplay_modes::StageElementBehaviour::Trigger),
2=>Some(strafesnet_common::gameplay_modes::StageElementBehaviour::Teleport),
3=>Some(strafesnet_common::gameplay_modes::StageElementBehaviour::Platform),
4=>Some(strafesnet_common::gameplay_modes::StageElementBehaviour::Check),
5=>Some(strafesnet_common::gameplay_modes::StageElementBehaviour::Checkpoint),
_=>None,
}
}
const fn force(&self)->bool{
self.header&Self::FORCE!=0
}
pub force:Option<()>,//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{
strafesnet_common::gameplay_modes::StageElement::new(
strafesnet_common::gameplay_modes::StageId::new(self.stage_id),
self.force(),
self.behaviour().unwrap(),
self.force.is_some(),
self.behaviour.into(),
self.jump_limit,
)
}
}
impl From<strafesnet_common::gameplay_modes::StageElement> for StageElement{
fn from(value:strafesnet_common::gameplay_modes::StageElement)->Self{
let behaviour=match value.behaviour(){
strafesnet_common::gameplay_modes::StageElementBehaviour::SpawnAt=>0,
strafesnet_common::gameplay_modes::StageElementBehaviour::Trigger=>1,
strafesnet_common::gameplay_modes::StageElementBehaviour::Teleport=>2,
strafesnet_common::gameplay_modes::StageElementBehaviour::Platform=>3,
strafesnet_common::gameplay_modes::StageElementBehaviour::Check=>4,
strafesnet_common::gameplay_modes::StageElementBehaviour::Checkpoint=>5,
};
let header=
behaviour
|flag(value.jump_limit().is_some(),StageElement::JUMP_LIMIT)
|flag(value.force(),StageElement::FORCE);
Self{
header,
stage_id:value.stage_id().get(),
behaviour:value.behaviour().into(),
jump_limit:value.jump_limit(),
force:match value.force(){true=>Some(()),false=>None},
}
}
}

View File

@@ -1,4 +1,3 @@
use super::common::flag;
use super::integer::{Time,Ratio64,Planar64,Planar64Vec3};
pub type Controls=u32;
@@ -6,34 +5,19 @@ pub type Controls=u32;
#[binrw::binrw]
#[brw(little)]
pub struct StyleModifiers{
pub header:u8,
pub controls_mask:Controls,
pub controls_mask_state:Controls,
#[br(if(header&Self::STRAFE!=0))]
pub strafe:Option<StrafeSettings>,
#[br(if(header&Self::ROCKET!=0))]
pub rocket:Option<PropulsionSettings>,
#[br(if(header&Self::JUMP!=0))]
pub jump:Option<JumpSettings>,
#[br(if(header&Self::WALK!=0))]
pub walk:Option<WalkSettings>,
#[br(if(header&Self::LADDER!=0))]
pub ladder:Option<LadderSettings>,
#[br(if(header&Self::SWIM!=0))]
pub swim:Option<PropulsionSettings>,
pub gravity:Planar64Vec3,
pub hitbox:Hitbox,
pub camera_offset:Planar64Vec3,
pub mass:Planar64,
}
impl StyleModifiers{
const STRAFE:u8=1<<0;
const ROCKET:u8=1<<1;
const JUMP:u8=1<<2;
const WALK:u8=1<<3;
const LADDER:u8=1<<4;
const SWIM:u8=1<<5;
}
impl Into<strafesnet_common::gameplay_style::StyleModifiers> for StyleModifiers{
fn into(self)->strafesnet_common::gameplay_style::StyleModifiers{
strafesnet_common::gameplay_style::StyleModifiers{
@@ -55,15 +39,7 @@ impl Into<strafesnet_common::gameplay_style::StyleModifiers> for StyleModifiers{
}
impl From<strafesnet_common::gameplay_style::StyleModifiers> for StyleModifiers{
fn from(value:strafesnet_common::gameplay_style::StyleModifiers)->Self{
let header=
flag(value.strafe.is_some(),StyleModifiers::STRAFE)
|flag(value.rocket.is_some(),StyleModifiers::ROCKET)
|flag(value.jump.is_some(),StyleModifiers::JUMP)
|flag(value.walk.is_some(),StyleModifiers::WALK)
|flag(value.ladder.is_some(),StyleModifiers::LADDER)
|flag(value.swim.is_some(),StyleModifiers::SWIM);
Self{
header,
controls_mask:value.controls_mask.bits(),
controls_mask_state:value.controls_mask_state.bits(),
strafe:value.strafe.map(Into::into),
@@ -106,7 +82,8 @@ impl From<strafesnet_common::gameplay_style::JumpCalculation> for JumpCalculatio
}
}
//TODO: test this
#[binrw::binrw]
#[brw(little)]
pub enum JumpImpulse{
FromTime(Time),
FromHeight(Planar64),
@@ -163,16 +140,11 @@ impl From<strafesnet_common::gameplay_style::ControlsActivation> for ControlsAct
#[binrw::binrw]
#[brw(little)]
pub struct StrafeSettings{
header:u8,
enable:ControlsActivation,
mv:Planar64,
#[br(if(header&Self::AIR_ACCEL_LIMIT!=0))]
air_accel_limit:Option<Planar64>,
tick_rate:Ratio64,
}
impl StrafeSettings{
const AIR_ACCEL_LIMIT:u8=1<<0;
}
impl Into<strafesnet_common::gameplay_style::StrafeSettings> for StrafeSettings{
fn into(self)->strafesnet_common::gameplay_style::StrafeSettings{
strafesnet_common::gameplay_style::StrafeSettings::new(
@@ -186,9 +158,7 @@ impl Into<strafesnet_common::gameplay_style::StrafeSettings> for StrafeSettings{
impl From<strafesnet_common::gameplay_style::StrafeSettings> for StrafeSettings{
fn from(value:strafesnet_common::gameplay_style::StrafeSettings)->Self{
let (enable,mv,air_accel_limit,tick_rate)=value.into_inner();
let header=flag(air_accel_limit.is_some(),StrafeSettings::AIR_ACCEL_LIMIT);
Self{
header,
enable:enable.into(),
mv:mv.get(),
air_accel_limit:air_accel_limit.map(|a|a.get()),
@@ -220,58 +190,23 @@ impl From<strafesnet_common::gameplay_style::PropulsionSettings> for PropulsionS
#[binrw::binrw]
#[brw(little)]
pub struct JumpSettings{
header:u8,
impulse:i64,
}
impl JumpSettings{
const IMPULSE:u8=0b0011;
const CALCULATION:u8=0b1100;
const fn impulse(&self)->Option<strafesnet_common::gameplay_style::JumpImpulse>{
match self.header&Self::IMPULSE{
0=>Some(strafesnet_common::gameplay_style::JumpImpulse::FromTime(strafesnet_common::integer::Time::raw(self.impulse))),
1=>Some(strafesnet_common::gameplay_style::JumpImpulse::FromHeight(strafesnet_common::integer::Planar64::raw(self.impulse))),
2=>Some(strafesnet_common::gameplay_style::JumpImpulse::FromDeltaV(strafesnet_common::integer::Planar64::raw(self.impulse))),
3=>Some(strafesnet_common::gameplay_style::JumpImpulse::FromEnergy(strafesnet_common::integer::Planar64::raw(self.impulse))),
_=>None,
}
}
const fn calculation(&self)->Option<strafesnet_common::gameplay_style::JumpCalculation>{
match (self.header&Self::CALCULATION)>>2{
0=>Some(strafesnet_common::gameplay_style::JumpCalculation::Capped),
1=>Some(strafesnet_common::gameplay_style::JumpCalculation::Energy),
2=>Some(strafesnet_common::gameplay_style::JumpCalculation::Linear),
_=>None,
}
}
impulse:JumpImpulse,
calculation:JumpCalculation,
}
impl Into<strafesnet_common::gameplay_style::JumpSettings> for JumpSettings{
fn into(self)->strafesnet_common::gameplay_style::JumpSettings{
strafesnet_common::gameplay_style::JumpSettings::new(
self.impulse().unwrap(),
self.calculation().unwrap(),
self.impulse.into(),
self.calculation.into(),
)
}
}
impl From<strafesnet_common::gameplay_style::JumpSettings> for JumpSettings{
fn from(value:strafesnet_common::gameplay_style::JumpSettings)->Self{
let (impulse_enum,calculation)=value.into_inner();
let (impulse,impulse_header)=match impulse_enum{
strafesnet_common::gameplay_style::JumpImpulse::FromTime(impulse)=>(impulse.get(),0),
strafesnet_common::gameplay_style::JumpImpulse::FromHeight(impulse)=>(impulse.get(),1),
strafesnet_common::gameplay_style::JumpImpulse::FromDeltaV(impulse)=>(impulse.get(),2),
strafesnet_common::gameplay_style::JumpImpulse::FromEnergy(impulse)=>(impulse.get(),3),
};
let calculation_header=match calculation{
strafesnet_common::gameplay_style::JumpCalculation::Capped=>0,
strafesnet_common::gameplay_style::JumpCalculation::Energy=>1,
strafesnet_common::gameplay_style::JumpCalculation::Linear=>2,
};
let header=
impulse_header
|(calculation_header<<2);
let (impulse,calculation)=value.into_inner();
Self{
header,
impulse,
impulse:impulse.into(),
calculation:calculation.into(),
}
}
}

View File

@@ -1,4 +1,3 @@
use super::common::flag;
use strafesnet_common::model::PolygonIter;
use super::integer::{Planar64Vec3,Planar64Affine3};
@@ -61,13 +60,8 @@ impl From<strafesnet_common::model::PolygonGroup> for PolygonGroup{
#[binrw::binrw]
#[brw(little)]
pub struct RenderConfig{
pub header:u8,
#[br(if(header&Self::TEXTURE!=0))]
pub texture:Option<u32>,
}
impl RenderConfig{
const TEXTURE:u8=1<<0;
}
impl Into<strafesnet_common::model::RenderConfig> for RenderConfig{
fn into(self)->strafesnet_common::model::RenderConfig{
strafesnet_common::model::RenderConfig{
@@ -77,9 +71,7 @@ impl Into<strafesnet_common::model::RenderConfig> for RenderConfig{
}
impl From<strafesnet_common::model::RenderConfig> for RenderConfig{
fn from(value:strafesnet_common::model::RenderConfig)->Self{
let header=flag(value.texture.is_some(),RenderConfig::TEXTURE);
Self{
header,
texture:value.texture.map(|texture_id|texture_id.get()),
}
}