refactor JumpCalculation

This commit is contained in:
Quaternions 2024-08-07 18:11:24 -07:00
parent 617cae300f
commit 3255b687e5
2 changed files with 112 additions and 93 deletions

View File

@ -125,6 +125,11 @@ pub enum Booster{
Velocity(Planar64Vec3), Velocity(Planar64Vec3),
#[brw(magic=1u8)] #[brw(magic=1u8)]
Energy{direction:Planar64Vec3,energy:Planar64}, Energy{direction:Planar64Vec3,energy:Planar64},
#[brw(magic=2u8)]
AirTime(Time),
#[brw(magic=3u8)]
Height(Planar64),
} }
impl Into<strafesnet_common::gameplay_attributes::Booster> for Booster{ impl Into<strafesnet_common::gameplay_attributes::Booster> for Booster{
fn into(self)->strafesnet_common::gameplay_attributes::Booster{ fn into(self)->strafesnet_common::gameplay_attributes::Booster{
@ -138,6 +143,14 @@ impl Into<strafesnet_common::gameplay_attributes::Booster> for Booster{
direction:strafesnet_common::integer::Planar64Vec3::raw_array(direction), direction:strafesnet_common::integer::Planar64Vec3::raw_array(direction),
energy:strafesnet_common::integer::Planar64::raw(energy) 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)
),
} }
} }
} }
@ -151,6 +164,10 @@ impl From<strafesnet_common::gameplay_attributes::Booster> for Booster{
direction:direction.get().to_array(), direction:direction.get().to_array(),
energy:energy.get(), 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()),
} }
} }
} }

View File

@ -105,52 +105,52 @@ impl From<strafesnet_common::gameplay_style::StyleModifiers> for StyleModifiers{
#[binrw::binrw] #[binrw::binrw]
#[brw(little,repr=u8)] #[brw(little,repr=u8)]
pub enum JumpCalculation{ pub enum JumpCalculation{
Capped, Max,
Energy, BoostThenJump,
Linear, JumpThenBoost,
} }
impl Into<strafesnet_common::gameplay_style::JumpCalculation> for JumpCalculation{ impl Into<strafesnet_common::gameplay_style::JumpCalculation> for JumpCalculation{
fn into(self)->strafesnet_common::gameplay_style::JumpCalculation{ fn into(self)->strafesnet_common::gameplay_style::JumpCalculation{
match self{ match self{
JumpCalculation::Capped=>strafesnet_common::gameplay_style::JumpCalculation::Capped, JumpCalculation::Max=>strafesnet_common::gameplay_style::JumpCalculation::Max,
JumpCalculation::Energy=>strafesnet_common::gameplay_style::JumpCalculation::Energy, JumpCalculation::BoostThenJump=>strafesnet_common::gameplay_style::JumpCalculation::BoostThenJump,
JumpCalculation::Linear=>strafesnet_common::gameplay_style::JumpCalculation::Linear, JumpCalculation::JumpThenBoost=>strafesnet_common::gameplay_style::JumpCalculation::JumpThenBoost,
} }
} }
} }
impl From<strafesnet_common::gameplay_style::JumpCalculation> for JumpCalculation{ impl From<strafesnet_common::gameplay_style::JumpCalculation> for JumpCalculation{
fn from(value:strafesnet_common::gameplay_style::JumpCalculation)->Self{ fn from(value:strafesnet_common::gameplay_style::JumpCalculation)->Self{
match value{ match value{
strafesnet_common::gameplay_style::JumpCalculation::Capped=>JumpCalculation::Capped, strafesnet_common::gameplay_style::JumpCalculation::Max=>JumpCalculation::Max,
strafesnet_common::gameplay_style::JumpCalculation::Energy=>JumpCalculation::Energy, strafesnet_common::gameplay_style::JumpCalculation::BoostThenJump=>JumpCalculation::BoostThenJump,
strafesnet_common::gameplay_style::JumpCalculation::Linear=>JumpCalculation::Linear, strafesnet_common::gameplay_style::JumpCalculation::JumpThenBoost=>JumpCalculation::JumpThenBoost,
} }
} }
} }
pub enum JumpImpulse{ pub enum JumpImpulse{
FromTime(Time), Time(Time),
FromHeight(Planar64), Height(Planar64),
FromDeltaV(Planar64), Linear(Planar64),
FromEnergy(Planar64), Energy(Planar64),
} }
impl Into<strafesnet_common::gameplay_style::JumpImpulse> for JumpImpulse{ impl Into<strafesnet_common::gameplay_style::JumpImpulse> for JumpImpulse{
fn into(self)->strafesnet_common::gameplay_style::JumpImpulse{ fn into(self)->strafesnet_common::gameplay_style::JumpImpulse{
match self{ match self{
JumpImpulse::FromTime(time)=>strafesnet_common::gameplay_style::JumpImpulse::FromTime(strafesnet_common::integer::Time::raw(time)), JumpImpulse::Time(time)=>strafesnet_common::gameplay_style::JumpImpulse::Time(strafesnet_common::integer::Time::raw(time)),
JumpImpulse::FromHeight(height)=>strafesnet_common::gameplay_style::JumpImpulse::FromHeight(strafesnet_common::integer::Planar64::raw(height)), JumpImpulse::Height(height)=>strafesnet_common::gameplay_style::JumpImpulse::Height(strafesnet_common::integer::Planar64::raw(height)),
JumpImpulse::FromDeltaV(deltav)=>strafesnet_common::gameplay_style::JumpImpulse::FromDeltaV(strafesnet_common::integer::Planar64::raw(deltav)), JumpImpulse::Linear(deltav)=>strafesnet_common::gameplay_style::JumpImpulse::Linear(strafesnet_common::integer::Planar64::raw(deltav)),
JumpImpulse::FromEnergy(energy)=>strafesnet_common::gameplay_style::JumpImpulse::FromEnergy(strafesnet_common::integer::Planar64::raw(energy)), JumpImpulse::Energy(energy)=>strafesnet_common::gameplay_style::JumpImpulse::Energy(strafesnet_common::integer::Planar64::raw(energy)),
} }
} }
} }
impl From<strafesnet_common::gameplay_style::JumpImpulse> for JumpImpulse{ impl From<strafesnet_common::gameplay_style::JumpImpulse> for JumpImpulse{
fn from(value:strafesnet_common::gameplay_style::JumpImpulse)->Self{ fn from(value:strafesnet_common::gameplay_style::JumpImpulse)->Self{
match value{ match value{
strafesnet_common::gameplay_style::JumpImpulse::FromTime(time)=>JumpImpulse::FromTime(time.get()), strafesnet_common::gameplay_style::JumpImpulse::Time(time)=>JumpImpulse::Time(time.get()),
strafesnet_common::gameplay_style::JumpImpulse::FromHeight(height)=>JumpImpulse::FromHeight(height.get()), strafesnet_common::gameplay_style::JumpImpulse::Height(height)=>JumpImpulse::Height(height.get()),
strafesnet_common::gameplay_style::JumpImpulse::FromDeltaV(deltav)=>JumpImpulse::FromDeltaV(deltav.get()), strafesnet_common::gameplay_style::JumpImpulse::Linear(deltav)=>JumpImpulse::Linear(deltav.get()),
strafesnet_common::gameplay_style::JumpImpulse::FromEnergy(energy)=>JumpImpulse::FromEnergy(energy.get()), strafesnet_common::gameplay_style::JumpImpulse::Energy(energy)=>JumpImpulse::Energy(energy.get()),
} }
} }
} }
@ -165,19 +165,19 @@ pub struct ControlsActivation{
impl TryInto<strafesnet_common::gameplay_style::ControlsActivation> for ControlsActivation{ impl TryInto<strafesnet_common::gameplay_style::ControlsActivation> for ControlsActivation{
type Error=ControlsError; type Error=ControlsError;
fn try_into(self)->Result<strafesnet_common::gameplay_style::ControlsActivation,Self::Error>{ fn try_into(self)->Result<strafesnet_common::gameplay_style::ControlsActivation,Self::Error>{
Ok(strafesnet_common::gameplay_style::ControlsActivation::new( Ok(strafesnet_common::gameplay_style::ControlsActivation{
strafesnet_common::controls_bitflag::Controls::from_bits(self.controls_mask).ok_or(ControlsError::UnknownBits)?, controls_mask: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)?, controls_intersects: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)?, controls_contains:strafesnet_common::controls_bitflag::Controls::from_bits(self.controls_contains).ok_or(ControlsError::UnknownBits)?,
)) })
} }
} }
impl From<strafesnet_common::gameplay_style::ControlsActivation> for ControlsActivation{ impl From<strafesnet_common::gameplay_style::ControlsActivation> for ControlsActivation{
fn from(value:strafesnet_common::gameplay_style::ControlsActivation)->Self{ fn from(value:strafesnet_common::gameplay_style::ControlsActivation)->Self{
Self{ Self{
controls_mask:value.controls_mask().bits(), controls_mask:value.controls_mask.bits(),
controls_intersects:value.controls_intersects().bits(), controls_intersects:value.controls_intersects.bits(),
controls_contains:value.controls_contains().bits(), controls_contains:value.controls_contains.bits(),
} }
} }
} }
@ -209,24 +209,23 @@ impl std::error::Error for StrafeSettingsError{}
impl TryInto<strafesnet_common::gameplay_style::StrafeSettings> for StrafeSettings{ impl TryInto<strafesnet_common::gameplay_style::StrafeSettings> for StrafeSettings{
type Error=StrafeSettingsError; type Error=StrafeSettingsError;
fn try_into(self)->Result<strafesnet_common::gameplay_style::StrafeSettings,Self::Error>{ fn try_into(self)->Result<strafesnet_common::gameplay_style::StrafeSettings,Self::Error>{
Ok(strafesnet_common::gameplay_style::StrafeSettings::new( Ok(strafesnet_common::gameplay_style::StrafeSettings{
self.enable.try_into().map_err(StrafeSettingsError::Controls)?, enable:self.enable.try_into().map_err(StrafeSettingsError::Controls)?,
strafesnet_common::integer::Planar64::raw(self.mv), mv:strafesnet_common::integer::Planar64::raw(self.mv),
self.air_accel_limit.map(strafesnet_common::integer::Planar64::raw), air_accel_limit:self.air_accel_limit.map(strafesnet_common::integer::Planar64::raw),
self.tick_rate.try_into().map_err(StrafeSettingsError::Ratio)?, tick_rate:self.tick_rate.try_into().map_err(StrafeSettingsError::Ratio)?,
)) })
} }
} }
impl From<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{ fn from(value:strafesnet_common::gameplay_style::StrafeSettings)->Self{
let (enable,mv,air_accel_limit,tick_rate)=value.into_inner(); let header=flag(value.air_accel_limit.is_some(),StrafeSettings::AIR_ACCEL_LIMIT);
let header=flag(air_accel_limit.is_some(),StrafeSettings::AIR_ACCEL_LIMIT);
Self{ Self{
header, header,
enable:enable.into(), enable:value.enable.into(),
mv:mv.get(), mv:value.mv.get(),
air_accel_limit:air_accel_limit.map(|a|a.get()), air_accel_limit:value.air_accel_limit.map(|a|a.get()),
tick_rate:tick_rate.into(), tick_rate:value.tick_rate.into(),
} }
} }
} }
@ -238,15 +237,15 @@ pub struct PropulsionSettings{
} }
impl Into<strafesnet_common::gameplay_style::PropulsionSettings> for PropulsionSettings{ impl Into<strafesnet_common::gameplay_style::PropulsionSettings> for PropulsionSettings{
fn into(self)->strafesnet_common::gameplay_style::PropulsionSettings{ fn into(self)->strafesnet_common::gameplay_style::PropulsionSettings{
strafesnet_common::gameplay_style::PropulsionSettings::new( strafesnet_common::gameplay_style::PropulsionSettings{
strafesnet_common::integer::Planar64::raw(self.magnitude) magnitude:strafesnet_common::integer::Planar64::raw(self.magnitude)
) }
} }
} }
impl From<strafesnet_common::gameplay_style::PropulsionSettings> for PropulsionSettings{ impl From<strafesnet_common::gameplay_style::PropulsionSettings> for PropulsionSettings{
fn from(value:strafesnet_common::gameplay_style::PropulsionSettings)->Self{ fn from(value:strafesnet_common::gameplay_style::PropulsionSettings)->Self{
Self{ Self{
magnitude:value.magnitude().get(), magnitude:value.magnitude.get(),
} }
} }
} }
@ -258,25 +257,29 @@ pub struct JumpSettings{
impulse:i64, impulse:i64,
} }
impl JumpSettings{ impl JumpSettings{
const IMPULSE:u8=0b0011; const IMPULSE:u8=0b00011;
const CALCULATION:u8=0b1100; const CALCULATION:u8=0b01100;
const LIMIT_MINIMUM:u8=0b10000;
const fn impulse(&self)->Option<strafesnet_common::gameplay_style::JumpImpulse>{ const fn impulse(&self)->Option<strafesnet_common::gameplay_style::JumpImpulse>{
match self.header&Self::IMPULSE{ match self.header&Self::IMPULSE{
0=>Some(strafesnet_common::gameplay_style::JumpImpulse::FromTime(strafesnet_common::integer::Time::raw(self.impulse))), 0=>Some(strafesnet_common::gameplay_style::JumpImpulse::Time(strafesnet_common::integer::Time::raw(self.impulse))),
1=>Some(strafesnet_common::gameplay_style::JumpImpulse::FromHeight(strafesnet_common::integer::Planar64::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::FromDeltaV(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::FromEnergy(strafesnet_common::integer::Planar64::raw(self.impulse))), 3=>Some(strafesnet_common::gameplay_style::JumpImpulse::Energy(strafesnet_common::integer::Planar64::raw(self.impulse))),
_=>None, _=>None,
} }
} }
const fn calculation(&self)->Option<strafesnet_common::gameplay_style::JumpCalculation>{ const fn calculation(&self)->Option<strafesnet_common::gameplay_style::JumpCalculation>{
match (self.header&Self::CALCULATION)>>2{ match (self.header&Self::CALCULATION)>>2{
0=>Some(strafesnet_common::gameplay_style::JumpCalculation::Capped), 0=>Some(strafesnet_common::gameplay_style::JumpCalculation::Max),
1=>Some(strafesnet_common::gameplay_style::JumpCalculation::Energy), 1=>Some(strafesnet_common::gameplay_style::JumpCalculation::JumpThenBoost),
2=>Some(strafesnet_common::gameplay_style::JumpCalculation::Linear), 2=>Some(strafesnet_common::gameplay_style::JumpCalculation::BoostThenJump),
_=>None, _=>None,
} }
} }
const fn limit_minimum(&self)->bool{
self.header&Self::LIMIT_MINIMUM!=0
}
} }
#[derive(Debug)] #[derive(Debug)]
pub enum JumpSettingsError{ pub enum JumpSettingsError{
@ -286,29 +289,30 @@ pub enum JumpSettingsError{
impl TryInto<strafesnet_common::gameplay_style::JumpSettings> for JumpSettings{ impl TryInto<strafesnet_common::gameplay_style::JumpSettings> for JumpSettings{
type Error=JumpSettingsError; type Error=JumpSettingsError;
fn try_into(self)->Result<strafesnet_common::gameplay_style::JumpSettings,Self::Error>{ fn try_into(self)->Result<strafesnet_common::gameplay_style::JumpSettings,Self::Error>{
Ok(strafesnet_common::gameplay_style::JumpSettings::new( Ok(strafesnet_common::gameplay_style::JumpSettings{
self.impulse().ok_or(JumpSettingsError::InvalidImpulseDiscriminant)?, impulse:self.impulse().ok_or(JumpSettingsError::InvalidImpulseDiscriminant)?,
self.calculation().ok_or(JumpSettingsError::InvalidCalculationDiscriminant)?, calculation:self.calculation().ok_or(JumpSettingsError::InvalidCalculationDiscriminant)?,
)) limit_minimum:self.limit_minimum(),
})
} }
} }
impl From<strafesnet_common::gameplay_style::JumpSettings> for JumpSettings{ impl From<strafesnet_common::gameplay_style::JumpSettings> for JumpSettings{
fn from(value:strafesnet_common::gameplay_style::JumpSettings)->Self{ fn from(value:strafesnet_common::gameplay_style::JumpSettings)->Self{
let (impulse_enum,calculation)=value.into_inner(); let (impulse,impulse_header)=match value.impulse{
let (impulse,impulse_header)=match impulse_enum{ strafesnet_common::gameplay_style::JumpImpulse::Time(impulse)=>(impulse.get(),0),
strafesnet_common::gameplay_style::JumpImpulse::FromTime(impulse)=>(impulse.get(),0), strafesnet_common::gameplay_style::JumpImpulse::Height(impulse)=>(impulse.get(),1),
strafesnet_common::gameplay_style::JumpImpulse::FromHeight(impulse)=>(impulse.get(),1), strafesnet_common::gameplay_style::JumpImpulse::Linear(impulse)=>(impulse.get(),2),
strafesnet_common::gameplay_style::JumpImpulse::FromDeltaV(impulse)=>(impulse.get(),2), strafesnet_common::gameplay_style::JumpImpulse::Energy(impulse)=>(impulse.get(),3),
strafesnet_common::gameplay_style::JumpImpulse::FromEnergy(impulse)=>(impulse.get(),3),
}; };
let calculation_header=match calculation{ let calculation_header=match value.calculation{
strafesnet_common::gameplay_style::JumpCalculation::Capped=>0, strafesnet_common::gameplay_style::JumpCalculation::Max=>0,
strafesnet_common::gameplay_style::JumpCalculation::Energy=>1, strafesnet_common::gameplay_style::JumpCalculation::JumpThenBoost=>1,
strafesnet_common::gameplay_style::JumpCalculation::Linear=>2, strafesnet_common::gameplay_style::JumpCalculation::BoostThenJump=>2,
}; };
let header= let header=
impulse_header impulse_header
|(calculation_header<<2); |(calculation_header<<2)
|((value.limit_minimum as u8)<<4);
Self{ Self{
header, header,
impulse, impulse,
@ -324,17 +328,17 @@ pub struct AccelerateSettings{
} }
impl Into<strafesnet_common::gameplay_style::AccelerateSettings> for AccelerateSettings{ impl Into<strafesnet_common::gameplay_style::AccelerateSettings> for AccelerateSettings{
fn into(self)->strafesnet_common::gameplay_style::AccelerateSettings{ fn into(self)->strafesnet_common::gameplay_style::AccelerateSettings{
strafesnet_common::gameplay_style::AccelerateSettings::new( strafesnet_common::gameplay_style::AccelerateSettings{
strafesnet_common::integer::Planar64::raw(self.accel), accel:strafesnet_common::integer::Planar64::raw(self.accel),
strafesnet_common::integer::Planar64::raw(self.topspeed), topspeed:strafesnet_common::integer::Planar64::raw(self.topspeed),
) }
} }
} }
impl From<strafesnet_common::gameplay_style::AccelerateSettings> for AccelerateSettings{ impl From<strafesnet_common::gameplay_style::AccelerateSettings> for AccelerateSettings{
fn from(value:strafesnet_common::gameplay_style::AccelerateSettings)->Self{ fn from(value:strafesnet_common::gameplay_style::AccelerateSettings)->Self{
Self{ Self{
accel:value.accel().get(), accel:value.accel.get(),
topspeed:value.topspeed().get(), topspeed:value.topspeed.get(),
} }
} }
} }
@ -349,22 +353,21 @@ pub struct WalkSettings{
} }
impl Into<strafesnet_common::gameplay_style::WalkSettings> for WalkSettings{ impl Into<strafesnet_common::gameplay_style::WalkSettings> for WalkSettings{
fn into(self)->strafesnet_common::gameplay_style::WalkSettings{ fn into(self)->strafesnet_common::gameplay_style::WalkSettings{
strafesnet_common::gameplay_style::WalkSettings::new( strafesnet_common::gameplay_style::WalkSettings{
self.accelerate.into(), accelerate:self.accelerate.into(),
strafesnet_common::integer::Planar64::raw(self.static_friction), static_friction:strafesnet_common::integer::Planar64::raw(self.static_friction),
strafesnet_common::integer::Planar64::raw(self.kinetic_friction), kinetic_friction:strafesnet_common::integer::Planar64::raw(self.kinetic_friction),
strafesnet_common::integer::Planar64::raw(self.surf_dot), surf_dot:strafesnet_common::integer::Planar64::raw(self.surf_dot),
) }
} }
} }
impl From<strafesnet_common::gameplay_style::WalkSettings> for WalkSettings{ impl From<strafesnet_common::gameplay_style::WalkSettings> for WalkSettings{
fn from(value:strafesnet_common::gameplay_style::WalkSettings)->Self{ fn from(value:strafesnet_common::gameplay_style::WalkSettings)->Self{
let (accelerate,static_friction,kinetic_friction,surf_dot)=value.into_inner();
Self{ Self{
accelerate:accelerate.into(), accelerate:value.accelerate.into(),
static_friction:static_friction.get(), static_friction:value.static_friction.get(),
kinetic_friction:kinetic_friction.get(), kinetic_friction:value.kinetic_friction.get(),
surf_dot:surf_dot.get(), surf_dot:value.surf_dot.get(),
} }
} }
} }
@ -377,18 +380,17 @@ pub struct LadderSettings{
} }
impl Into<strafesnet_common::gameplay_style::LadderSettings> for LadderSettings{ impl Into<strafesnet_common::gameplay_style::LadderSettings> for LadderSettings{
fn into(self)->strafesnet_common::gameplay_style::LadderSettings{ fn into(self)->strafesnet_common::gameplay_style::LadderSettings{
strafesnet_common::gameplay_style::LadderSettings::new( strafesnet_common::gameplay_style::LadderSettings{
self.accelerate.into(), accelerate:self.accelerate.into(),
strafesnet_common::integer::Planar64::raw(self.dot), dot:strafesnet_common::integer::Planar64::raw(self.dot),
) }
} }
} }
impl From<strafesnet_common::gameplay_style::LadderSettings> for LadderSettings{ impl From<strafesnet_common::gameplay_style::LadderSettings> for LadderSettings{
fn from(value:strafesnet_common::gameplay_style::LadderSettings)->Self{ fn from(value:strafesnet_common::gameplay_style::LadderSettings)->Self{
let (accelerate,dot)=value.into_inner();
Self{ Self{
accelerate:accelerate.into(), accelerate:value.accelerate.into(),
dot:dot.get(), dot:value.dot.get(),
} }
} }
} }