Compare commits
5 Commits
bot2
...
workaround
| Author | SHA1 | Date | |
|---|---|---|---|
| e9414f42b6 | |||
| ef992feb63 | |||
| 17a7e7b738 | |||
| 7a03b079d8 | |||
| 6a3c097741 |
17
Cargo.lock
generated
17
Cargo.lock
generated
@@ -8,12 +8,6 @@ version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3d62b7694a562cdf5a74227903507c56ab2cc8bdd1f781ed5cb4cf9c9f810bfc"
|
||||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711"
|
||||
|
||||
[[package]]
|
||||
name = "binrw"
|
||||
version = "0.14.0"
|
||||
@@ -46,9 +40,9 @@ checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
|
||||
|
||||
[[package]]
|
||||
name = "bytemuck"
|
||||
version = "1.16.3"
|
||||
version = "1.16.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "102087e286b4677862ea56cf8fc58bb2cdfa8725c40ffb80fe3a008eb7f2fc83"
|
||||
checksum = "b236fc92302c97ed75b38da1f4917b5cdda4984745740f153a5d3059e48d725e"
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
@@ -99,11 +93,10 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "strafesnet_common"
|
||||
version = "0.3.0"
|
||||
version = "0.1.3"
|
||||
source = "sparse+https://git.itzana.me/api/packages/strafesnet/cargo/"
|
||||
checksum = "1077d45a0b064964906a57de765a5a2bfe47b41f2f807d13b18c70765e76d3dd"
|
||||
checksum = "10a7e3b69506893bbdde90ce8a9d75cd56d280c0424d2dfdf98f8520179d0c1b"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"bitflags",
|
||||
"glam",
|
||||
"id",
|
||||
@@ -111,7 +104,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "strafesnet_snf"
|
||||
version = "0.1.3-bot"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"binrw",
|
||||
"id",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "strafesnet_snf"
|
||||
version = "0.1.3-bot"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
@@ -8,4 +8,4 @@ edition = "2021"
|
||||
[dependencies]
|
||||
binrw = "0.14.0"
|
||||
id = { version = "0.1.0", registry = "strafesnet" }
|
||||
strafesnet_common = { version = "0.3.0", registry = "strafesnet" }
|
||||
strafesnet_common = { version = "0.1.3", registry = "strafesnet" }
|
||||
|
||||
37
src/bot.rs
37
src/bot.rs
@@ -1,7 +1,4 @@
|
||||
use std::io::Seek;
|
||||
|
||||
use binrw::{binrw,BinReaderExt,BinWriterExt};
|
||||
use crate::newtypes::instruction::TimedPhysicsInstruction;
|
||||
use binrw::{BinReaderExt, binrw};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error{
|
||||
@@ -11,38 +8,6 @@ pub enum Error{
|
||||
File(crate::file::Error),
|
||||
}
|
||||
|
||||
pub struct BotDebug{
|
||||
file:std::fs::File,
|
||||
}
|
||||
|
||||
impl BotDebug{
|
||||
pub fn new(name:impl AsRef<std::path::Path>)->std::io::Result<Self>{
|
||||
Ok(Self{
|
||||
file:std::fs::File::create(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:
|
||||
|
||||
@@ -12,7 +12,6 @@ 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),
|
||||
@@ -215,7 +214,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(TryInto::try_into).collect::<Result<_,_>>().map_err(Error::InvalidMode)?;
|
||||
let modes=header.modes.into_iter().map(Into::into).collect();
|
||||
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|
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
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;
|
||||
|
||||
@@ -125,11 +125,6 @@ pub enum Booster{
|
||||
Velocity(Planar64Vec3),
|
||||
#[brw(magic=1u8)]
|
||||
Energy{direction:Planar64Vec3,energy:Planar64},
|
||||
#[brw(magic=2u8)]
|
||||
AirTime(Time),
|
||||
#[brw(magic=3u8)]
|
||||
Height(Planar64),
|
||||
|
||||
}
|
||||
impl Into<strafesnet_common::gameplay_attributes::Booster> for Booster{
|
||||
fn into(self)->strafesnet_common::gameplay_attributes::Booster{
|
||||
@@ -143,14 +138,6 @@ impl Into<strafesnet_common::gameplay_attributes::Booster> for Booster{
|
||||
direction:strafesnet_common::integer::Planar64Vec3::raw_array(direction),
|
||||
energy:strafesnet_common::integer::Planar64::raw(energy)
|
||||
},
|
||||
Booster::AirTime(time)=>
|
||||
strafesnet_common::gameplay_attributes::Booster::AirTime(
|
||||
strafesnet_common::integer::Time::raw(time)
|
||||
),
|
||||
Booster::Height(height)=>
|
||||
strafesnet_common::gameplay_attributes::Booster::Height(
|
||||
strafesnet_common::integer::Planar64::raw(height)
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -164,10 +151,6 @@ impl From<strafesnet_common::gameplay_attributes::Booster> for Booster{
|
||||
direction:direction.get().to_array(),
|
||||
energy:energy.get(),
|
||||
},
|
||||
strafesnet_common::gameplay_attributes::Booster::AirTime(time)=>
|
||||
Booster::AirTime(time.get()),
|
||||
strafesnet_common::gameplay_attributes::Booster::Height(height)=>
|
||||
Booster::Height(height.get()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
use super::common::flag;
|
||||
|
||||
pub type ModeId=u32;
|
||||
pub type StageId=u32;
|
||||
|
||||
#[binrw::binrw]
|
||||
#[brw(little)]
|
||||
pub struct StageElement{
|
||||
pub header:u8,
|
||||
pub stage_id:StageId,
|
||||
pub stage_id:u32,
|
||||
#[br(if(header&Self::JUMP_LIMIT!=0))]
|
||||
pub jump_limit:Option<u8>,
|
||||
}
|
||||
@@ -30,25 +27,14 @@ impl StageElement{
|
||||
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(
|
||||
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().ok_or(StageElementError::InvalidBehaviour)?,
|
||||
self.behaviour().unwrap(),
|
||||
self.jump_limit,
|
||||
))
|
||||
)
|
||||
}
|
||||
}
|
||||
impl From<strafesnet_common::gameplay_modes::StageElement> for StageElement{
|
||||
@@ -168,31 +154,19 @@ pub struct Mode{
|
||||
#[br(count=header.elements)]
|
||||
pub elements:Vec<(u32,StageElement)>,
|
||||
}
|
||||
#[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)?,
|
||||
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(),
|
||||
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)|
|
||||
Ok((strafesnet_common::model::ModelId::new(model_id),stage_element.try_into()?))
|
||||
).collect::<Result<_,_>>().map_err(ModeError::StageElement)?,
|
||||
))
|
||||
(strafesnet_common::model::ModelId::new(model_id),stage_element.into())
|
||||
).collect(),
|
||||
)
|
||||
}
|
||||
}
|
||||
impl From<strafesnet_common::gameplay_modes::Mode> for Mode{
|
||||
|
||||
@@ -2,16 +2,6 @@ use super::common::flag;
|
||||
use super::integer::{Time,Ratio64,Planar64,Planar64Vec3};
|
||||
|
||||
pub type Controls=u32;
|
||||
#[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)]
|
||||
@@ -44,27 +34,15 @@ impl StyleModifiers{
|
||||
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)?,
|
||||
impl Into<strafesnet_common::gameplay_style::StyleModifiers> for StyleModifiers{
|
||||
fn into(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(TryInto::try_into).transpose().map_err(StyleModifierError::JumpSettings)?,
|
||||
jump:self.jump.map(Into::into),
|
||||
walk:self.walk.map(Into::into),
|
||||
ladder:self.ladder.map(Into::into),
|
||||
swim:self.swim.map(Into::into),
|
||||
@@ -72,7 +50,7 @@ impl TryInto<strafesnet_common::gameplay_style::StyleModifiers> for StyleModifie
|
||||
hitbox:self.hitbox.into(),
|
||||
camera_offset:strafesnet_common::integer::Planar64Vec3::raw_array(self.camera_offset),
|
||||
mass:strafesnet_common::integer::Planar64::raw(self.mass),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<strafesnet_common::gameplay_style::StyleModifiers> for StyleModifiers{
|
||||
@@ -105,52 +83,53 @@ impl From<strafesnet_common::gameplay_style::StyleModifiers> for StyleModifiers{
|
||||
#[binrw::binrw]
|
||||
#[brw(little,repr=u8)]
|
||||
pub enum JumpCalculation{
|
||||
Max,
|
||||
BoostThenJump,
|
||||
JumpThenBoost,
|
||||
Capped,
|
||||
Energy,
|
||||
Linear,
|
||||
}
|
||||
impl Into<strafesnet_common::gameplay_style::JumpCalculation> for JumpCalculation{
|
||||
fn into(self)->strafesnet_common::gameplay_style::JumpCalculation{
|
||||
match self{
|
||||
JumpCalculation::Max=>strafesnet_common::gameplay_style::JumpCalculation::Max,
|
||||
JumpCalculation::BoostThenJump=>strafesnet_common::gameplay_style::JumpCalculation::BoostThenJump,
|
||||
JumpCalculation::JumpThenBoost=>strafesnet_common::gameplay_style::JumpCalculation::JumpThenBoost,
|
||||
JumpCalculation::Capped=>strafesnet_common::gameplay_style::JumpCalculation::Capped,
|
||||
JumpCalculation::Energy=>strafesnet_common::gameplay_style::JumpCalculation::Energy,
|
||||
JumpCalculation::Linear=>strafesnet_common::gameplay_style::JumpCalculation::Linear,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<strafesnet_common::gameplay_style::JumpCalculation> for JumpCalculation{
|
||||
fn from(value:strafesnet_common::gameplay_style::JumpCalculation)->Self{
|
||||
match value{
|
||||
strafesnet_common::gameplay_style::JumpCalculation::Max=>JumpCalculation::Max,
|
||||
strafesnet_common::gameplay_style::JumpCalculation::BoostThenJump=>JumpCalculation::BoostThenJump,
|
||||
strafesnet_common::gameplay_style::JumpCalculation::JumpThenBoost=>JumpCalculation::JumpThenBoost,
|
||||
strafesnet_common::gameplay_style::JumpCalculation::Capped=>JumpCalculation::Capped,
|
||||
strafesnet_common::gameplay_style::JumpCalculation::Energy=>JumpCalculation::Energy,
|
||||
strafesnet_common::gameplay_style::JumpCalculation::Linear=>JumpCalculation::Linear,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: test this
|
||||
pub enum JumpImpulse{
|
||||
Time(Time),
|
||||
Height(Planar64),
|
||||
Linear(Planar64),
|
||||
Energy(Planar64),
|
||||
FromTime(Time),
|
||||
FromHeight(Planar64),
|
||||
FromDeltaV(Planar64),
|
||||
FromEnergy(Planar64),
|
||||
}
|
||||
impl Into<strafesnet_common::gameplay_style::JumpImpulse> for JumpImpulse{
|
||||
fn into(self)->strafesnet_common::gameplay_style::JumpImpulse{
|
||||
match self{
|
||||
JumpImpulse::Time(time)=>strafesnet_common::gameplay_style::JumpImpulse::Time(strafesnet_common::integer::Time::raw(time)),
|
||||
JumpImpulse::Height(height)=>strafesnet_common::gameplay_style::JumpImpulse::Height(strafesnet_common::integer::Planar64::raw(height)),
|
||||
JumpImpulse::Linear(deltav)=>strafesnet_common::gameplay_style::JumpImpulse::Linear(strafesnet_common::integer::Planar64::raw(deltav)),
|
||||
JumpImpulse::Energy(energy)=>strafesnet_common::gameplay_style::JumpImpulse::Energy(strafesnet_common::integer::Planar64::raw(energy)),
|
||||
JumpImpulse::FromTime(time)=>strafesnet_common::gameplay_style::JumpImpulse::FromTime(strafesnet_common::integer::Time::raw(time)),
|
||||
JumpImpulse::FromHeight(height)=>strafesnet_common::gameplay_style::JumpImpulse::FromHeight(strafesnet_common::integer::Planar64::raw(height)),
|
||||
JumpImpulse::FromDeltaV(deltav)=>strafesnet_common::gameplay_style::JumpImpulse::FromDeltaV(strafesnet_common::integer::Planar64::raw(deltav)),
|
||||
JumpImpulse::FromEnergy(energy)=>strafesnet_common::gameplay_style::JumpImpulse::FromEnergy(strafesnet_common::integer::Planar64::raw(energy)),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<strafesnet_common::gameplay_style::JumpImpulse> for JumpImpulse{
|
||||
fn from(value:strafesnet_common::gameplay_style::JumpImpulse)->Self{
|
||||
match value{
|
||||
strafesnet_common::gameplay_style::JumpImpulse::Time(time)=>JumpImpulse::Time(time.get()),
|
||||
strafesnet_common::gameplay_style::JumpImpulse::Height(height)=>JumpImpulse::Height(height.get()),
|
||||
strafesnet_common::gameplay_style::JumpImpulse::Linear(deltav)=>JumpImpulse::Linear(deltav.get()),
|
||||
strafesnet_common::gameplay_style::JumpImpulse::Energy(energy)=>JumpImpulse::Energy(energy.get()),
|
||||
strafesnet_common::gameplay_style::JumpImpulse::FromTime(time)=>JumpImpulse::FromTime(time.get()),
|
||||
strafesnet_common::gameplay_style::JumpImpulse::FromHeight(height)=>JumpImpulse::FromHeight(height.get()),
|
||||
strafesnet_common::gameplay_style::JumpImpulse::FromDeltaV(deltav)=>JumpImpulse::FromDeltaV(deltav.get()),
|
||||
strafesnet_common::gameplay_style::JumpImpulse::FromEnergy(energy)=>JumpImpulse::FromEnergy(energy.get()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -162,22 +141,21 @@ pub struct ControlsActivation{
|
||||
controls_intersects:Controls,
|
||||
controls_contains:Controls,
|
||||
}
|
||||
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{
|
||||
controls_mask:strafesnet_common::controls_bitflag::Controls::from_bits(self.controls_mask).ok_or(ControlsError::UnknownBits)?,
|
||||
controls_intersects:strafesnet_common::controls_bitflag::Controls::from_bits(self.controls_intersects).ok_or(ControlsError::UnknownBits)?,
|
||||
controls_contains:strafesnet_common::controls_bitflag::Controls::from_bits(self.controls_contains).ok_or(ControlsError::UnknownBits)?,
|
||||
})
|
||||
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 From<strafesnet_common::gameplay_style::ControlsActivation> for ControlsActivation{
|
||||
fn from(value:strafesnet_common::gameplay_style::ControlsActivation)->Self{
|
||||
Self{
|
||||
controls_mask:value.controls_mask.bits(),
|
||||
controls_intersects:value.controls_intersects.bits(),
|
||||
controls_contains:value.controls_contains.bits(),
|
||||
controls_mask:value.controls_mask().bits(),
|
||||
controls_intersects:value.controls_intersects().bits(),
|
||||
controls_contains:value.controls_contains().bits(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -195,37 +173,26 @@ pub struct StrafeSettings{
|
||||
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{
|
||||
enable:self.enable.try_into().map_err(StrafeSettingsError::Controls)?,
|
||||
mv:strafesnet_common::integer::Planar64::raw(self.mv),
|
||||
air_accel_limit:self.air_accel_limit.map(strafesnet_common::integer::Planar64::raw),
|
||||
tick_rate:self.tick_rate.try_into().map_err(StrafeSettingsError::Ratio)?,
|
||||
})
|
||||
impl Into<strafesnet_common::gameplay_style::StrafeSettings> for StrafeSettings{
|
||||
fn into(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.tick_rate.into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
impl From<strafesnet_common::gameplay_style::StrafeSettings> for StrafeSettings{
|
||||
fn from(value:strafesnet_common::gameplay_style::StrafeSettings)->Self{
|
||||
let header=flag(value.air_accel_limit.is_some(),StrafeSettings::AIR_ACCEL_LIMIT);
|
||||
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:value.enable.into(),
|
||||
mv:value.mv.get(),
|
||||
air_accel_limit:value.air_accel_limit.map(|a|a.get()),
|
||||
tick_rate:value.tick_rate.into(),
|
||||
enable:enable.into(),
|
||||
mv:mv.get(),
|
||||
air_accel_limit:air_accel_limit.map(|a|a.get()),
|
||||
tick_rate:tick_rate.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -237,15 +204,15 @@ pub struct PropulsionSettings{
|
||||
}
|
||||
impl Into<strafesnet_common::gameplay_style::PropulsionSettings> for PropulsionSettings{
|
||||
fn into(self)->strafesnet_common::gameplay_style::PropulsionSettings{
|
||||
strafesnet_common::gameplay_style::PropulsionSettings{
|
||||
magnitude:strafesnet_common::integer::Planar64::raw(self.magnitude)
|
||||
}
|
||||
strafesnet_common::gameplay_style::PropulsionSettings::new(
|
||||
strafesnet_common::integer::Planar64::raw(self.magnitude)
|
||||
)
|
||||
}
|
||||
}
|
||||
impl From<strafesnet_common::gameplay_style::PropulsionSettings> for PropulsionSettings{
|
||||
fn from(value:strafesnet_common::gameplay_style::PropulsionSettings)->Self{
|
||||
Self{
|
||||
magnitude:value.magnitude.get(),
|
||||
magnitude:value.magnitude().get(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -257,62 +224,51 @@ pub struct JumpSettings{
|
||||
impulse:i64,
|
||||
}
|
||||
impl JumpSettings{
|
||||
const IMPULSE:u8=0b00011;
|
||||
const CALCULATION:u8=0b01100;
|
||||
const LIMIT_MINIMUM:u8=0b10000;
|
||||
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::Time(strafesnet_common::integer::Time::raw(self.impulse))),
|
||||
1=>Some(strafesnet_common::gameplay_style::JumpImpulse::Height(strafesnet_common::integer::Planar64::raw(self.impulse))),
|
||||
2=>Some(strafesnet_common::gameplay_style::JumpImpulse::Linear(strafesnet_common::integer::Planar64::raw(self.impulse))),
|
||||
3=>Some(strafesnet_common::gameplay_style::JumpImpulse::Energy(strafesnet_common::integer::Planar64::raw(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::Max),
|
||||
1=>Some(strafesnet_common::gameplay_style::JumpCalculation::JumpThenBoost),
|
||||
2=>Some(strafesnet_common::gameplay_style::JumpCalculation::BoostThenJump),
|
||||
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,
|
||||
}
|
||||
}
|
||||
const fn limit_minimum(&self)->bool{
|
||||
self.header&Self::LIMIT_MINIMUM!=0
|
||||
}
|
||||
}
|
||||
#[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{
|
||||
impulse:self.impulse().ok_or(JumpSettingsError::InvalidImpulseDiscriminant)?,
|
||||
calculation:self.calculation().ok_or(JumpSettingsError::InvalidCalculationDiscriminant)?,
|
||||
limit_minimum:self.limit_minimum(),
|
||||
})
|
||||
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(),
|
||||
)
|
||||
}
|
||||
}
|
||||
impl From<strafesnet_common::gameplay_style::JumpSettings> for JumpSettings{
|
||||
fn from(value:strafesnet_common::gameplay_style::JumpSettings)->Self{
|
||||
let (impulse,impulse_header)=match value.impulse{
|
||||
strafesnet_common::gameplay_style::JumpImpulse::Time(impulse)=>(impulse.get(),0),
|
||||
strafesnet_common::gameplay_style::JumpImpulse::Height(impulse)=>(impulse.get(),1),
|
||||
strafesnet_common::gameplay_style::JumpImpulse::Linear(impulse)=>(impulse.get(),2),
|
||||
strafesnet_common::gameplay_style::JumpImpulse::Energy(impulse)=>(impulse.get(),3),
|
||||
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 value.calculation{
|
||||
strafesnet_common::gameplay_style::JumpCalculation::Max=>0,
|
||||
strafesnet_common::gameplay_style::JumpCalculation::JumpThenBoost=>1,
|
||||
strafesnet_common::gameplay_style::JumpCalculation::BoostThenJump=>2,
|
||||
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)
|
||||
|((value.limit_minimum as u8)<<4);
|
||||
|(calculation_header<<2);
|
||||
Self{
|
||||
header,
|
||||
impulse,
|
||||
@@ -328,17 +284,17 @@ pub struct AccelerateSettings{
|
||||
}
|
||||
impl Into<strafesnet_common::gameplay_style::AccelerateSettings> for AccelerateSettings{
|
||||
fn into(self)->strafesnet_common::gameplay_style::AccelerateSettings{
|
||||
strafesnet_common::gameplay_style::AccelerateSettings{
|
||||
accel:strafesnet_common::integer::Planar64::raw(self.accel),
|
||||
topspeed:strafesnet_common::integer::Planar64::raw(self.topspeed),
|
||||
}
|
||||
strafesnet_common::gameplay_style::AccelerateSettings::new(
|
||||
strafesnet_common::integer::Planar64::raw(self.accel),
|
||||
strafesnet_common::integer::Planar64::raw(self.topspeed),
|
||||
)
|
||||
}
|
||||
}
|
||||
impl From<strafesnet_common::gameplay_style::AccelerateSettings> for AccelerateSettings{
|
||||
fn from(value:strafesnet_common::gameplay_style::AccelerateSettings)->Self{
|
||||
Self{
|
||||
accel:value.accel.get(),
|
||||
topspeed:value.topspeed.get(),
|
||||
accel:value.accel().get(),
|
||||
topspeed:value.topspeed().get(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -353,21 +309,22 @@ pub struct WalkSettings{
|
||||
}
|
||||
impl Into<strafesnet_common::gameplay_style::WalkSettings> for WalkSettings{
|
||||
fn into(self)->strafesnet_common::gameplay_style::WalkSettings{
|
||||
strafesnet_common::gameplay_style::WalkSettings{
|
||||
accelerate:self.accelerate.into(),
|
||||
static_friction:strafesnet_common::integer::Planar64::raw(self.static_friction),
|
||||
kinetic_friction:strafesnet_common::integer::Planar64::raw(self.kinetic_friction),
|
||||
surf_dot:strafesnet_common::integer::Planar64::raw(self.surf_dot),
|
||||
}
|
||||
strafesnet_common::gameplay_style::WalkSettings::new(
|
||||
self.accelerate.into(),
|
||||
strafesnet_common::integer::Planar64::raw(self.static_friction),
|
||||
strafesnet_common::integer::Planar64::raw(self.kinetic_friction),
|
||||
strafesnet_common::integer::Planar64::raw(self.surf_dot),
|
||||
)
|
||||
}
|
||||
}
|
||||
impl From<strafesnet_common::gameplay_style::WalkSettings> for WalkSettings{
|
||||
fn from(value:strafesnet_common::gameplay_style::WalkSettings)->Self{
|
||||
let (accelerate,static_friction,kinetic_friction,surf_dot)=value.into_inner();
|
||||
Self{
|
||||
accelerate:value.accelerate.into(),
|
||||
static_friction:value.static_friction.get(),
|
||||
kinetic_friction:value.kinetic_friction.get(),
|
||||
surf_dot:value.surf_dot.get(),
|
||||
accelerate:accelerate.into(),
|
||||
static_friction:static_friction.get(),
|
||||
kinetic_friction:kinetic_friction.get(),
|
||||
surf_dot:surf_dot.get(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -380,17 +337,18 @@ pub struct LadderSettings{
|
||||
}
|
||||
impl Into<strafesnet_common::gameplay_style::LadderSettings> for LadderSettings{
|
||||
fn into(self)->strafesnet_common::gameplay_style::LadderSettings{
|
||||
strafesnet_common::gameplay_style::LadderSettings{
|
||||
accelerate:self.accelerate.into(),
|
||||
dot:strafesnet_common::integer::Planar64::raw(self.dot),
|
||||
}
|
||||
strafesnet_common::gameplay_style::LadderSettings::new(
|
||||
self.accelerate.into(),
|
||||
strafesnet_common::integer::Planar64::raw(self.dot),
|
||||
)
|
||||
}
|
||||
}
|
||||
impl From<strafesnet_common::gameplay_style::LadderSettings> for LadderSettings{
|
||||
fn from(value:strafesnet_common::gameplay_style::LadderSettings)->Self{
|
||||
let (accelerate,dot)=value.into_inner();
|
||||
Self{
|
||||
accelerate:value.accelerate.into(),
|
||||
dot:value.dot.get(),
|
||||
accelerate:accelerate.into(),
|
||||
dot:dot.get(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
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()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -6,21 +6,9 @@ pub struct Ratio64{
|
||||
num:i64,
|
||||
den:u64,
|
||||
}
|
||||
#[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 Into<strafesnet_common::integer::Ratio64> for Ratio64{
|
||||
fn into(self)->strafesnet_common::integer::Ratio64{
|
||||
strafesnet_common::integer::Ratio64::new(self.num,self.den).unwrap()
|
||||
}
|
||||
}
|
||||
impl From<strafesnet_common::integer::Ratio64> for Ratio64{
|
||||
@@ -38,23 +26,6 @@ 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;
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
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),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user