14 Commits

Author SHA1 Message Date
4e1ed43161 read bot debug function 2024-08-05 18:42:52 -07:00
00ac7960e0 please don't fill my hard drive 2024-08-05 17:32:03 -07:00
f2e9f81fe4 special place for debug bots 2024-08-05 17:27:17 -07:00
bfcf973524 rethink physics instructions 2024-08-05 17:26:46 -07:00
97da935d9d drop droppable instructions 2024-08-05 13:34:30 -07:00
68ccee81b1 newtypes 2024-08-05 13:34:11 -07:00
2c000cca67 prototype 2024-08-02 13:44:47 -07:00
cd65db0008 newtypes 2024-08-02 13:44:41 -07:00
91b90675c4 prototype 2024-08-02 12:11:23 -07:00
8911968a7c rand dep 2024-08-02 12:11:17 -07:00
d036a33501 v0.1.1 no panic 2024-07-29 18:22:26 -07:00
05c8db4750 don't panic 2024-07-29 18:20:44 -07:00
e3130661f4 v0.1.0 2024-07-29 16:38:32 -07:00
a1ee34c7a3 binrw enums 2024-07-29 16:36:00 -07:00
14 changed files with 672 additions and 237 deletions

102
Cargo.lock generated
View File

@@ -44,12 +44,35 @@ version = "1.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b236fc92302c97ed75b38da1f4917b5cdda4984745740f153a5d3059e48d725e"
[[package]]
name = "byteorder"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "either"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
[[package]]
name = "getrandom"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "glam"
version = "0.28.0"
@@ -67,12 +90,27 @@ dependencies = [
"syn 2.0.72",
]
[[package]]
name = "libc"
version = "0.2.155"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
[[package]]
name = "owo-colors"
version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
[[package]]
name = "ppv-lite86"
version = "0.2.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dee4364d9f3b902ef14fab8a1ddffb783a1cb6b4bba3bfc1fa3922732c7de97f"
dependencies = [
"zerocopy",
]
[[package]]
name = "proc-macro2"
version = "1.0.86"
@@ -91,11 +129,41 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "strafesnet_common"
version = "0.1.3"
version = "0.2.0"
source = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/"
checksum = "10a7e3b69506893bbdde90ce8a9d75cd56d280c0424d2dfdf98f8520179d0c1b"
checksum = "74580c59a09194ce39db49cd814a5c2fc2d61513c88c6b811b5b40c0da6de057"
dependencies = [
"bitflags",
"glam",
@@ -104,10 +172,11 @@ dependencies = [
[[package]]
name = "strafesnet_snf"
version = "0.1.0"
version = "0.1.1"
dependencies = [
"binrw",
"id",
"rand",
"strafesnet_common",
]
@@ -138,3 +207,30 @@ name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "zerocopy"
version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "854e949ac82d619ee9a14c66a1b674ac730422372ccb759ce0c39cabcf2bf8e6"
dependencies = [
"byteorder",
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "125139de3f6b9d625c39e2efdd73d41bdac468ccd556556440e322be0e1bbd91"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.72",
]

View File

@@ -1,6 +1,6 @@
[package]
name = "strafesnet_snf"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -8,4 +8,5 @@ edition = "2021"
[dependencies]
binrw = "0.14.0"
id = { version = "0.1.0", registry = "strafesnet" }
strafesnet_common = { version = "0.1.3", registry = "strafesnet" }
rand = "0.8.5"
strafesnet_common = { version = "0.2.0", registry = "strafesnet" }

View File

@@ -1,4 +1,7 @@
use binrw::{BinReaderExt, binrw};
use std::io::Seek;
use binrw::{binrw,BinReaderExt,BinWriterExt};
use crate::newtypes::instruction::TimedPhysicsInstruction;
#[derive(Debug)]
pub enum Error{
@@ -8,6 +11,46 @@ pub enum Error{
File(crate::file::Error),
}
pub struct BotDebug{
name:String,
file:std::fs::File,
}
impl BotDebug{
pub fn new()->std::io::Result<Self>{
let rng:u128=rand::random();
let name=format!("debug_bots/{rng:x}");
Ok(Self{
file:std::fs::File::create(name.as_str())?,
name,
})
}
pub fn delete(self)->std::io::Result<()>{
std::mem::drop(self.file);
std::fs::remove_file(self.name)
}
pub fn push(&mut self,ins:strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>)->Result<(),binrw::Error>{
let ret=match TryInto::<TimedPhysicsInstruction>::try_into(ins){
Ok(ins)=>self.file.write_le(&ins),
Err(crate::newtypes::physics::PhysicsInputInstructionError::DropInstruction)=>Ok(()),
};
//check if too much data has written to be reasonable
//avoid filling my hard drive on an infinite loop basically
if self.file.stream_position().is_ok_and(|pos|50*1024*1024<pos){
panic!();
}
ret
}
}
pub fn read_bot_debug(mut reader:impl BinReaderExt)->Result<Vec<strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>>,binrw::Error>{
let mut instructions=Vec::new();
while let Ok(ins)=reader.read_le::<TimedPhysicsInstruction>(){
instructions.push(ins.try_into().unwrap());
}
Ok(instructions)
}
/* block types
BLOCK_BOT_HEADER:

View File

@@ -12,6 +12,7 @@ use strafesnet_common::gameplay_modes;
#[derive(Debug)]
pub enum Error{
InvalidHeader(binrw::Error),
InvalidMode(newtypes::gameplay_modes::ModeError),
InvalidBlockId(BlockId),
InvalidMeshId(model::MeshId),
InvalidModelId(model::ModelId),
@@ -214,7 +215,7 @@ impl<R:BinReaderExt> StreamableMap<R>{
pub(crate) fn new(mut file:crate::file::File<R>)->Result<Self,Error>{
//assume the file seek is in the right place to start reading a map header
let header:MapHeader=file.as_mut().read_le().map_err(Error::InvalidHeader)?;
let modes=header.modes.into_iter().map(Into::into).collect();
let modes=header.modes.into_iter().map(TryInto::try_into).collect::<Result<_,_>>().map_err(Error::InvalidMode)?;
let attributes=header.attributes.into_iter().map(Into::into).collect();
let render_configs=header.render_configs.into_iter().map(Into::into).collect();
let bvh=header.spacial_blocks.into_iter().map(|spacial_block|

View File

@@ -1,6 +1,10 @@
mod common;
pub mod aabb;
pub mod model;
pub mod mouse;
pub mod integer;
pub mod physics;
pub mod instruction;
pub mod gameplay_modes;
pub mod gameplay_style;
pub mod gameplay_attributes;

26
src/newtypes/common.rs Normal file
View File

@@ -0,0 +1,26 @@
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,28 +1,6 @@
use super::common::{flag,Boolio};
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{
@@ -316,50 +294,48 @@ 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 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>,
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(mut self)->strafesnet_common::gameplay_attributes::GeneralAttributes{
fn into(self)->strafesnet_common::gameplay_attributes::GeneralAttributes{
strafesnet_common::gameplay_attributes::GeneralAttributes{
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),
booster:self.booster.map(Into::into),
trajectory:self.trajectory.map(Into::into),
wormhole:self.wormhole.map(Into::into),
accelerator:self.accelerator.map(Into::into),
}
}
}
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: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)),
header,
booster:value.booster.map(Into::into),
trajectory:value.trajectory.map(Into::into),
wormhole:value.wormhole.map(Into::into),
accelerator:value.accelerator.map(Into::into),
}
}
}
@@ -367,22 +343,25 @@ impl From<strafesnet_common::gameplay_attributes::GeneralAttributes> for General
#[binrw::binrw]
#[brw(little)]
pub struct ContactingAttributes{
pub contact_behaviour_enabled:u8,
#[br(count=contact_behaviour_enabled)]
pub contact_behaviour:Vec<ContactingBehaviour>,
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(mut self)->strafesnet_common::gameplay_attributes::ContactingAttributes{
fn into(self)->strafesnet_common::gameplay_attributes::ContactingAttributes{
strafesnet_common::gameplay_attributes::ContactingAttributes{
contact_behaviour:self.contact_behaviour.pop().map(Into::into),
contact_behaviour:self.contact_behaviour.map(Into::into),
}
}
}
impl From<strafesnet_common::gameplay_attributes::ContactingAttributes> for ContactingAttributes{
fn from(value:strafesnet_common::gameplay_attributes::ContactingAttributes)->Self{
Self{
contact_behaviour_enabled:value.contact_behaviour.is_some() as u8,
contact_behaviour:super::gameplay_style::stupid(value.contact_behaviour.map(Into::into)),
header:flag(value.contact_behaviour.is_some(),ContactingAttributes::CONTACTING_BEHAVIOUR),
contact_behaviour:value.contact_behaviour.map(Into::into),
}
}
}
@@ -390,22 +369,25 @@ impl From<strafesnet_common::gameplay_attributes::ContactingAttributes> for Cont
#[binrw::binrw]
#[brw(little)]
pub struct IntersectingAttributes{
pub water_enabled:u8,
#[br(count=water_enabled)]
pub water:Vec<IntersectingWater>,
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(mut self)->strafesnet_common::gameplay_attributes::IntersectingAttributes{
fn into(self)->strafesnet_common::gameplay_attributes::IntersectingAttributes{
strafesnet_common::gameplay_attributes::IntersectingAttributes{
water:self.water.pop().map(Into::into),
water:self.water.map(Into::into),
}
}
}
impl From<strafesnet_common::gameplay_attributes::IntersectingAttributes> for IntersectingAttributes{
fn from(value:strafesnet_common::gameplay_attributes::IntersectingAttributes)->Self{
Self{
water_enabled:value.water.is_some() as u8,
water:super::gameplay_style::stupid(value.water.map(Into::into)),
header:flag(value.water.is_some(),IntersectingAttributes::INTERSECTING_WATER),
water:value.water.map(Into::into),
}
}
}

View File

@@ -1,68 +1,74 @@
#[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,
}
}
}
use super::common::flag;
pub type ModeId=u32;
pub type StageId=u32;
#[binrw::binrw]
#[brw(little)]
pub struct StageElement{
pub stage_id:u32,//which stage spawn to send to
pub behaviour:StageElementBehaviour,
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
pub header:u8,
pub stage_id:StageId,
#[br(if(header&Self::JUMP_LIMIT!=0))]
pub jump_limit:Option<u8>,
}
impl Into<strafesnet_common::gameplay_modes::StageElement> for StageElement{
fn into(mut self)->strafesnet_common::gameplay_modes::StageElement{
strafesnet_common::gameplay_modes::StageElement::new(
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
}
}
#[derive(Debug)]
pub enum StageElementError{
InvalidBehaviour,
}
impl std::fmt::Display for StageElementError{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"{self:?}")
}
}
impl std::error::Error for StageElementError{}
impl TryInto<strafesnet_common::gameplay_modes::StageElement> for StageElement{
type Error=StageElementError;
fn try_into(self)->Result<strafesnet_common::gameplay_modes::StageElement,Self::Error>{
Ok(strafesnet_common::gameplay_modes::StageElement::new(
strafesnet_common::gameplay_modes::StageId::new(self.stage_id),
self.force.into(),
self.behaviour.into(),
self.jump_limit.pop(),
)
self.force(),
self.behaviour().ok_or(StageElementError::InvalidBehaviour)?,
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_enabled:value.jump_limit().is_some() as u8,
jump_limit:super::gameplay_style::stupid(value.jump_limit()),
force:value.force().into(),
jump_limit:value.jump_limit(),
}
}
}
@@ -117,8 +123,7 @@ impl From<strafesnet_common::gameplay_modes::Stage> for Stage{
}
#[binrw::binrw]
#[brw(little,repr=u32)]
#[repr(u32)]
#[brw(little,repr=u8)]
pub enum Zone{
Start,
Finish,
@@ -145,7 +150,6 @@ impl From<strafesnet_common::gameplay_modes::Zone> for Zone{
#[binrw::binrw]
#[brw(little)]
#[derive(Debug)]
pub struct ModeHeader{
pub zones:u32,
pub stages:u32,
@@ -164,19 +168,31 @@ pub struct Mode{
#[br(count=header.elements)]
pub elements:Vec<(u32,StageElement)>,
}
impl Into<strafesnet_common::gameplay_modes::Mode> for Mode{
fn into(self)->strafesnet_common::gameplay_modes::Mode{
strafesnet_common::gameplay_modes::Mode::new(
self.style.into(),
#[derive(Debug)]
pub enum ModeError{
StyleModifier(super::gameplay_style::StyleModifierError),
StageElement(StageElementError),
}
impl std::fmt::Display for ModeError{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"{self:?}")
}
}
impl std::error::Error for ModeError{}
impl TryInto<strafesnet_common::gameplay_modes::Mode> for Mode{
type Error=ModeError;
fn try_into(self)->Result<strafesnet_common::gameplay_modes::Mode,Self::Error>{
Ok(strafesnet_common::gameplay_modes::Mode::new(
self.style.try_into().map_err(ModeError::StyleModifier)?,
strafesnet_common::model::ModelId::new(self.start),
self.zones.into_iter().map(|(model_id,zone)|
(strafesnet_common::model::ModelId::new(model_id),zone.into())
).collect(),
self.stages.into_iter().map(Into::into).collect(),
self.elements.into_iter().map(|(model_id,stage_element)|
(strafesnet_common::model::ModelId::new(model_id),stage_element.into())
).collect(),
)
Ok((strafesnet_common::model::ModelId::new(model_id),stage_element.try_into()?))
).collect::<Result<_,_>>().map_err(ModeError::StageElement)?,
))
}
}
impl From<strafesnet_common::gameplay_modes::Mode> for Mode{

View File

@@ -1,85 +1,99 @@
use super::common::flag;
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,
#[derive(Debug)]
pub enum ControlsError{
UnknownBits,
}
impl std::fmt::Display for ControlsError{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"{self:?}")
}
}
impl std::error::Error for ControlsError{}
#[binrw::binrw]
#[brw(little)]
pub struct StyleModifiers{
pub header:StyleModifiersHeader,
pub header:u8,
pub controls_mask:Controls,
pub controls_mask_state:Controls,
#[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>,
#[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 Into<strafesnet_common::gameplay_style::StyleModifiers> for 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.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),
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;
}
#[derive(Debug)]
pub enum StyleModifierError{
Controls(ControlsError),
JumpSettings(JumpSettingsError),
StrafeSettings(StrafeSettingsError),
}
impl std::fmt::Display for StyleModifierError{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"{self:?}")
}
}
impl std::error::Error for StyleModifierError{}
impl TryInto<strafesnet_common::gameplay_style::StyleModifiers> for StyleModifiers{
type Error=StyleModifierError;
fn try_into(self)->Result<strafesnet_common::gameplay_style::StyleModifiers,Self::Error>{
Ok(strafesnet_common::gameplay_style::StyleModifiers{
controls_mask:strafesnet_common::controls_bitflag::Controls::from_bits(self.controls_mask).ok_or(StyleModifierError::Controls(ControlsError::UnknownBits))?,
controls_mask_state:strafesnet_common::controls_bitflag::Controls::from_bits(self.controls_mask_state).ok_or(StyleModifierError::Controls(ControlsError::UnknownBits))?,
strafe:self.strafe.map(TryInto::try_into).transpose().map_err(StyleModifierError::StrafeSettings)?,
rocket:self.rocket.map(Into::into),
jump:self.jump.map(TryInto::try_into).transpose().map_err(StyleModifierError::JumpSettings)?,
walk:self.walk.map(Into::into),
ladder:self.ladder.map(Into::into),
swim:self.swim.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),
mass:strafesnet_common::integer::Planar64::raw(self.mass),
}
}
}
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{
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: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,
},
header,
controls_mask:value.controls_mask.bits(),
controls_mask_state:value.controls_mask_state.bits(),
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)),
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),
gravity:value.gravity.get().to_array(),
hitbox:value.hitbox.into(),
camera_offset:value.camera_offset.get().to_array(),
@@ -114,8 +128,6 @@ impl From<strafesnet_common::gameplay_style::JumpCalculation> for JumpCalculatio
}
}
#[binrw::binrw]
#[brw(little)]
pub enum JumpImpulse{
FromTime(Time),
FromHeight(Planar64),
@@ -150,13 +162,14 @@ pub struct ControlsActivation{
controls_intersects:Controls,
controls_contains:Controls,
}
impl Into<strafesnet_common::gameplay_style::ControlsActivation> for ControlsActivation{
fn into(self)->strafesnet_common::gameplay_style::ControlsActivation{
strafesnet_common::gameplay_style::ControlsActivation::new(
strafesnet_common::controls_bitflag::Controls::from_bits(self.controls_mask).unwrap(),
strafesnet_common::controls_bitflag::Controls::from_bits(self.controls_intersects).unwrap(),
strafesnet_common::controls_bitflag::Controls::from_bits(self.controls_contains).unwrap(),
)
impl TryInto<strafesnet_common::gameplay_style::ControlsActivation> for ControlsActivation{
type Error=ControlsError;
fn try_into(self)->Result<strafesnet_common::gameplay_style::ControlsActivation,Self::Error>{
Ok(strafesnet_common::gameplay_style::ControlsActivation::new(
strafesnet_common::controls_bitflag::Controls::from_bits(self.controls_mask).ok_or(ControlsError::UnknownBits)?,
strafesnet_common::controls_bitflag::Controls::from_bits(self.controls_intersects).ok_or(ControlsError::UnknownBits)?,
strafesnet_common::controls_bitflag::Controls::from_bits(self.controls_contains).ok_or(ControlsError::UnknownBits)?,
))
}
}
impl From<strafesnet_common::gameplay_style::ControlsActivation> for ControlsActivation{
@@ -172,31 +185,47 @@ impl From<strafesnet_common::gameplay_style::ControlsActivation> for ControlsAct
#[binrw::binrw]
#[brw(little)]
pub struct StrafeSettings{
header:u8,
enable:ControlsActivation,
mv:Planar64,
air_accel_limit_enabled:u8,
#[br(count=air_accel_limit_enabled)]
air_accel_limit:Vec<Planar64>,
#[br(if(header&Self::AIR_ACCEL_LIMIT!=0))]
air_accel_limit:Option<Planar64>,
tick_rate:Ratio64,
}
impl Into<strafesnet_common::gameplay_style::StrafeSettings> for StrafeSettings{
fn into(mut self)->strafesnet_common::gameplay_style::StrafeSettings{
strafesnet_common::gameplay_style::StrafeSettings::new(
self.enable.into(),
impl StrafeSettings{
const AIR_ACCEL_LIMIT:u8=1<<0;
}
#[derive(Debug)]
pub enum StrafeSettingsError{
Ratio(super::integer::RatioError),
Controls(ControlsError),
}
impl std::fmt::Display for StrafeSettingsError{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"{self:?}")
}
}
impl std::error::Error for StrafeSettingsError{}
impl TryInto<strafesnet_common::gameplay_style::StrafeSettings> for StrafeSettings{
type Error=StrafeSettingsError;
fn try_into(self)->Result<strafesnet_common::gameplay_style::StrafeSettings,Self::Error>{
Ok(strafesnet_common::gameplay_style::StrafeSettings::new(
self.enable.try_into().map_err(StrafeSettingsError::Controls)?,
strafesnet_common::integer::Planar64::raw(self.mv),
self.air_accel_limit.pop().map(strafesnet_common::integer::Planar64::raw),
self.tick_rate.into(),
)
self.air_accel_limit.map(strafesnet_common::integer::Planar64::raw),
self.tick_rate.try_into().map_err(StrafeSettingsError::Ratio)?,
))
}
}
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_enabled:air_accel_limit.is_some() as u8,
air_accel_limit:stupid(air_accel_limit.map(|a|a.get())),
air_accel_limit:air_accel_limit.map(|a|a.get()),
tick_rate:tick_rate.into(),
}
}
@@ -225,23 +254,64 @@ impl From<strafesnet_common::gameplay_style::PropulsionSettings> for PropulsionS
#[binrw::binrw]
#[brw(little)]
pub struct JumpSettings{
impulse:JumpImpulse,
calculation:JumpCalculation,
header:u8,
impulse:i64,
}
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.into(),
self.calculation.into(),
)
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,
}
}
}
#[derive(Debug)]
pub enum JumpSettingsError{
InvalidImpulseDiscriminant,
InvalidCalculationDiscriminant,
}
impl TryInto<strafesnet_common::gameplay_style::JumpSettings> for JumpSettings{
type Error=JumpSettingsError;
fn try_into(self)->Result<strafesnet_common::gameplay_style::JumpSettings,Self::Error>{
Ok(strafesnet_common::gameplay_style::JumpSettings::new(
self.impulse().ok_or(JumpSettingsError::InvalidImpulseDiscriminant)?,
self.calculation().ok_or(JumpSettingsError::InvalidCalculationDiscriminant)?,
))
}
}
impl From<strafesnet_common::gameplay_style::JumpSettings> for JumpSettings{
fn from(value:strafesnet_common::gameplay_style::JumpSettings)->Self{
let (impulse,calculation)=value.into_inner();
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);
Self{
impulse:impulse.into(),
calculation:calculation.into(),
header,
impulse,
}
}
}

View File

@@ -0,0 +1,27 @@
use super::integer::Time;
#[binrw::binrw]
#[brw(little)]
pub struct TimedPhysicsInstruction{
pub time:Time,
pub instruction:super::physics::PhysicsInputInstruction,
}
impl TryInto<strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>> for TimedPhysicsInstruction{
type Error=super::integer::RatioError;
fn try_into(self)->Result<strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>,Self::Error>{
Ok(strafesnet_common::instruction::TimedInstruction{
time:strafesnet_common::integer::Time::raw(self.time),
instruction:self.instruction.try_into()?,
})
}
}
impl TryFrom<strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>> for TimedPhysicsInstruction{
type Error=super::physics::PhysicsInputInstructionError;
fn try_from(value:strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>)->Result<Self,Self::Error>{
Ok(Self{
time:value.time.get(),
instruction:value.instruction.try_into()?,
})
}
}

View File

@@ -6,9 +6,21 @@ pub struct Ratio64{
num:i64,
den:u64,
}
impl Into<strafesnet_common::integer::Ratio64> for Ratio64{
fn into(self)->strafesnet_common::integer::Ratio64{
strafesnet_common::integer::Ratio64::new(self.num,self.den).unwrap()
#[derive(Debug)]
pub enum RatioError{
ZeroDenominator,
}
impl std::fmt::Display for RatioError{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"{self:?}")
}
}
impl std::error::Error for RatioError{}
impl TryInto<strafesnet_common::integer::Ratio64> for Ratio64{
type Error=RatioError;
fn try_into(self)->Result<strafesnet_common::integer::Ratio64,Self::Error>{
strafesnet_common::integer::Ratio64::new(self.num,self.den)
.ok_or(RatioError::ZeroDenominator)
}
}
impl From<strafesnet_common::integer::Ratio64> for Ratio64{
@@ -26,6 +38,23 @@ pub struct Ratio64Vec2{
pub x:Ratio64,
pub y:Ratio64,
}
impl TryInto<strafesnet_common::integer::Ratio64Vec2> for Ratio64Vec2{
type Error=RatioError;
fn try_into(self)->Result<strafesnet_common::integer::Ratio64Vec2,Self::Error>{
Ok(strafesnet_common::integer::Ratio64Vec2{
x:self.x.try_into()?,
y:self.y.try_into()?,
})
}
}
impl From<strafesnet_common::integer::Ratio64Vec2> for Ratio64Vec2{
fn from(value:strafesnet_common::integer::Ratio64Vec2)->Self{
Self{
x:value.x.into(),
y:value.y.into(),
}
}
}
pub type Angle32=i32;
pub type Planar64=i64;

View File

@@ -1,3 +1,4 @@
use super::common::flag;
use strafesnet_common::model::PolygonIter;
use super::integer::{Planar64Vec3,Planar64Affine3};
@@ -60,22 +61,26 @@ impl From<strafesnet_common::model::PolygonGroup> for PolygonGroup{
#[binrw::binrw]
#[brw(little)]
pub struct RenderConfig{
pub texture_enabled:u8,
#[br(count=texture_enabled)]
pub texture:Vec<u32>,
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(mut self)->strafesnet_common::model::RenderConfig{
fn into(self)->strafesnet_common::model::RenderConfig{
strafesnet_common::model::RenderConfig{
texture:self.texture.pop().map(strafesnet_common::model::TextureId::new),
texture:self.texture.map(strafesnet_common::model::TextureId::new),
}
}
}
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{
texture_enabled:value.texture.is_some() as u8,
texture:super::gameplay_style::stupid(value.texture.map(|texture_id|texture_id.get())),
header,
texture:value.texture.map(|texture_id|texture_id.get()),
}
}
}

37
src/newtypes/mouse.rs Normal file
View File

@@ -0,0 +1,37 @@
use super::integer::Time;
#[binrw::binrw]
#[brw(little)]
pub enum EncodedMouseDelta{
//X did not move Y has 1 byte, time has 2 bytes
X0Y1T2{
y:i8,
t:u16,
},
X1Y1T2
}
///TODO: delta delta encoding lol
#[binrw::binrw]
#[brw(little)]
pub struct MouseState{
pub pos:[i32;2],
pub time:Time,
}
impl Into<strafesnet_common::mouse::MouseState> for MouseState{
fn into(self)->strafesnet_common::mouse::MouseState{
strafesnet_common::mouse::MouseState{
pos:self.pos.into(),
time:strafesnet_common::integer::Time::raw(self.time),
}
}
}
impl From<strafesnet_common::mouse::MouseState> for MouseState{
fn from(value:strafesnet_common::mouse::MouseState)->Self{
Self{
pos:value.pos.to_array(),
time:value.time.get(),
}
}
}

98
src/newtypes/physics.rs Normal file
View File

@@ -0,0 +1,98 @@
use super::common::Boolio;
#[binrw::binrw]
#[brw(little)]
pub enum PhysicsInputInstruction{
#[brw(magic=0u8)]
ReplaceMouse(super::mouse::MouseState,super::mouse::MouseState),
#[brw(magic=1u8)]
SetNextMouse(super::mouse::MouseState),
#[brw(magic=2u8)]
SetMoveRight(Boolio),
#[brw(magic=3u8)]
SetMoveUp(Boolio),
#[brw(magic=4u8)]
SetMoveBack(Boolio),
#[brw(magic=5u8)]
SetMoveLeft(Boolio),
#[brw(magic=6u8)]
SetMoveDown(Boolio),
#[brw(magic=7u8)]
SetMoveForward(Boolio),
#[brw(magic=8u8)]
SetJump(Boolio),
#[brw(magic=9u8)]
SetZoom(Boolio),
#[brw(magic=10u8)]
Reset,
#[brw(magic=11u8)]
Restart,
#[brw(magic=12u8)]
Spawn(super::gameplay_modes::ModeId,super::gameplay_modes::StageId),
#[brw(magic=13u8)]
PracticeFly,
#[brw(magic=14u8)]
SetSensitivity(super::integer::Ratio64Vec2),
}
#[derive(Debug)]
pub enum PhysicsInputInstructionError{
/// This is an instruction that can be dropped when serializing
DropInstruction,
}
impl std::fmt::Display for PhysicsInputInstructionError{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"{self:?}")
}
}
impl std::error::Error for PhysicsInputInstructionError{}
impl TryInto<strafesnet_common::physics::Instruction> for PhysicsInputInstruction{
type Error=super::integer::RatioError;
fn try_into(self)->Result<strafesnet_common::physics::Instruction,Self::Error>{
Ok(match self{
PhysicsInputInstruction::ReplaceMouse(m0,m1)=>strafesnet_common::physics::Instruction::ReplaceMouse(m0.into(),m1.into()),
PhysicsInputInstruction::SetNextMouse(m)=>strafesnet_common::physics::Instruction::SetNextMouse(m.into()),
PhysicsInputInstruction::SetMoveRight(state)=>strafesnet_common::physics::Instruction::SetMoveRight(state.into()),
PhysicsInputInstruction::SetMoveUp(state)=>strafesnet_common::physics::Instruction::SetMoveUp(state.into()),
PhysicsInputInstruction::SetMoveBack(state)=>strafesnet_common::physics::Instruction::SetMoveBack(state.into()),
PhysicsInputInstruction::SetMoveLeft(state)=>strafesnet_common::physics::Instruction::SetMoveLeft(state.into()),
PhysicsInputInstruction::SetMoveDown(state)=>strafesnet_common::physics::Instruction::SetMoveDown(state.into()),
PhysicsInputInstruction::SetMoveForward(state)=>strafesnet_common::physics::Instruction::SetMoveForward(state.into()),
PhysicsInputInstruction::SetJump(state)=>strafesnet_common::physics::Instruction::SetJump(state.into()),
PhysicsInputInstruction::SetZoom(state)=>strafesnet_common::physics::Instruction::SetZoom(state.into()),
PhysicsInputInstruction::Reset=>strafesnet_common::physics::Instruction::Reset,
PhysicsInputInstruction::Restart=>strafesnet_common::physics::Instruction::Restart,
PhysicsInputInstruction::Spawn(mode_id,stage_id)=>strafesnet_common::physics::Instruction::Spawn(
strafesnet_common::gameplay_modes::ModeId::new(mode_id),
strafesnet_common::gameplay_modes::StageId::new(stage_id),
),
PhysicsInputInstruction::PracticeFly=>strafesnet_common::physics::Instruction::PracticeFly,
PhysicsInputInstruction::SetSensitivity(sensitivity)=>strafesnet_common::physics::Instruction::SetSensitivity(sensitivity.try_into()?),
})
}
}
impl TryFrom<strafesnet_common::physics::Instruction> for PhysicsInputInstruction{
type Error=PhysicsInputInstructionError;
fn try_from(value:strafesnet_common::physics::Instruction)->Result<Self,Self::Error>{
match value{
strafesnet_common::physics::Instruction::ReplaceMouse(m0,m1)=>Ok(PhysicsInputInstruction::ReplaceMouse(m0.into(),m1.into())),
strafesnet_common::physics::Instruction::SetNextMouse(m)=>Ok(PhysicsInputInstruction::SetNextMouse(m.into())),
strafesnet_common::physics::Instruction::SetMoveRight(state)=>Ok(PhysicsInputInstruction::SetMoveRight(state.into())),
strafesnet_common::physics::Instruction::SetMoveUp(state)=>Ok(PhysicsInputInstruction::SetMoveUp(state.into())),
strafesnet_common::physics::Instruction::SetMoveBack(state)=>Ok(PhysicsInputInstruction::SetMoveBack(state.into())),
strafesnet_common::physics::Instruction::SetMoveLeft(state)=>Ok(PhysicsInputInstruction::SetMoveLeft(state.into())),
strafesnet_common::physics::Instruction::SetMoveDown(state)=>Ok(PhysicsInputInstruction::SetMoveDown(state.into())),
strafesnet_common::physics::Instruction::SetMoveForward(state)=>Ok(PhysicsInputInstruction::SetMoveForward(state.into())),
strafesnet_common::physics::Instruction::SetJump(state)=>Ok(PhysicsInputInstruction::SetJump(state.into())),
strafesnet_common::physics::Instruction::SetZoom(state)=>Ok(PhysicsInputInstruction::SetZoom(state.into())),
strafesnet_common::physics::Instruction::Reset=>Ok(PhysicsInputInstruction::Reset),
strafesnet_common::physics::Instruction::Restart=>Ok(PhysicsInputInstruction::Restart),
strafesnet_common::physics::Instruction::Spawn(mode_id,stage_id)=>Ok(PhysicsInputInstruction::Spawn(
mode_id.get(),
stage_id.get(),
)),
strafesnet_common::physics::Instruction::PracticeFly=>Ok(PhysicsInputInstruction::PracticeFly),
strafesnet_common::physics::Instruction::SetSensitivity(sensitivity)=>Ok(PhysicsInputInstruction::SetSensitivity(sensitivity.into())),
strafesnet_common::physics::Instruction::Idle=>Err(PhysicsInputInstructionError::DropInstruction),
}
}
}