From e9414f42b65dcc7bef25b1ad5cc83b80af58e8e5 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 29 Jul 2024 16:09:16 -0700 Subject: [PATCH] fix them --- src/newtypes/common.rs | 4 ++++ src/newtypes/gameplay_attributes.rs | 15 ++++++++------- src/newtypes/gameplay_modes.rs | 6 ++++-- src/newtypes/gameplay_style.rs | 15 ++++++++------- src/newtypes/model.rs | 3 ++- 5 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/newtypes/common.rs b/src/newtypes/common.rs index 88ffac7..0136b54 100644 --- a/src/newtypes/common.rs +++ b/src/newtypes/common.rs @@ -1,3 +1,7 @@ +pub const fn flag(b:bool,mask:u8)->u8{ + (-(b as i8) as u8)&mask +} + #[binrw::binrw] #[brw(little,repr=u8)] pub enum Boolio{ diff --git a/src/newtypes/gameplay_attributes.rs b/src/newtypes/gameplay_attributes.rs index f544ec5..0dd3501 100644 --- a/src/newtypes/gameplay_attributes.rs +++ b/src/newtypes/gameplay_attributes.rs @@ -1,9 +1,10 @@ +use super::common::{flag,Boolio}; use super::integer::{Time,Planar64,Planar64Vec3}; #[binrw::binrw] #[brw(little)] pub struct ContactingLadder{ - pub sticky:super::common::Boolio, + pub sticky:Boolio, } impl Into for ContactingLadder{ fn into(self)->strafesnet_common::gameplay_attributes::ContactingLadder{ @@ -325,10 +326,10 @@ impl Into for General impl From for GeneralAttributes{ fn from(value:strafesnet_common::gameplay_attributes::GeneralAttributes)->Self{ let header= - value.booster.is_some() as u8&GeneralAttributes::BOOSTER - |value.trajectory.is_some() as u8&GeneralAttributes::TRAJECTORY - |value.wormhole.is_some() as u8&GeneralAttributes::WORMHOLE - |value.accelerator.is_some() as u8&GeneralAttributes::ACCELERATOR; + flag(value.booster.is_some(),GeneralAttributes::BOOSTER) + |flag(value.trajectory.is_some(),GeneralAttributes::TRAJECTORY) + |flag(value.wormhole.is_some(),GeneralAttributes::WORMHOLE) + |flag(value.accelerator.is_some(),GeneralAttributes::ACCELERATOR); Self{ header, booster:value.booster.map(Into::into), @@ -359,7 +360,7 @@ impl Into for Cont impl From for ContactingAttributes{ fn from(value:strafesnet_common::gameplay_attributes::ContactingAttributes)->Self{ Self{ - header:value.contact_behaviour.is_some() as u8&ContactingAttributes::CONTACTING_BEHAVIOUR, + header:flag(value.contact_behaviour.is_some(),ContactingAttributes::CONTACTING_BEHAVIOUR), contact_behaviour:value.contact_behaviour.map(Into::into), } } @@ -385,7 +386,7 @@ impl Into for In impl From for IntersectingAttributes{ fn from(value:strafesnet_common::gameplay_attributes::IntersectingAttributes)->Self{ Self{ - header:value.water.is_some() as u8&IntersectingAttributes::INTERSECTING_WATER, + header:flag(value.water.is_some(),IntersectingAttributes::INTERSECTING_WATER), water:value.water.map(Into::into), } } diff --git a/src/newtypes/gameplay_modes.rs b/src/newtypes/gameplay_modes.rs index 12e1e8e..b789427 100644 --- a/src/newtypes/gameplay_modes.rs +++ b/src/newtypes/gameplay_modes.rs @@ -1,3 +1,5 @@ +use super::common::flag; + #[binrw::binrw] #[brw(little)] pub struct StageElement{ @@ -47,8 +49,8 @@ impl From for StageElement{ }; let header= behaviour - |value.jump_limit().is_some() as u8&StageElement::JUMP_LIMIT - |value.force() as u8&StageElement::FORCE; + |flag(value.jump_limit().is_some(),StageElement::JUMP_LIMIT) + |flag(value.force(),StageElement::FORCE); Self{ header, stage_id:value.stage_id().get(), diff --git a/src/newtypes/gameplay_style.rs b/src/newtypes/gameplay_style.rs index e68ad69..b39bf94 100644 --- a/src/newtypes/gameplay_style.rs +++ b/src/newtypes/gameplay_style.rs @@ -1,3 +1,4 @@ +use super::common::flag; use super::integer::{Time,Ratio64,Planar64,Planar64Vec3}; pub type Controls=u32; @@ -55,12 +56,12 @@ impl Into for StyleModifiers{ impl From for StyleModifiers{ fn from(value:strafesnet_common::gameplay_style::StyleModifiers)->Self{ let header= - value.strafe.is_some() as u8&StyleModifiers::STRAFE - |value.rocket.is_some() as u8&StyleModifiers::ROCKET - |value.jump.is_some() as u8&StyleModifiers::JUMP - |value.walk.is_some() as u8&StyleModifiers::WALK - |value.ladder.is_some() as u8&StyleModifiers::LADDER - |value.swim.is_some() as u8&StyleModifiers::SWIM; + flag(value.strafe.is_some(),StyleModifiers::STRAFE) + |flag(value.rocket.is_some(),StyleModifiers::ROCKET) + |flag(value.jump.is_some(),StyleModifiers::JUMP) + |flag(value.walk.is_some(),StyleModifiers::WALK) + |flag(value.ladder.is_some(),StyleModifiers::LADDER) + |flag(value.swim.is_some(),StyleModifiers::SWIM); Self{ header, controls_mask:value.controls_mask.bits(), @@ -185,7 +186,7 @@ impl Into for StrafeSettings{ impl From for StrafeSettings{ fn from(value:strafesnet_common::gameplay_style::StrafeSettings)->Self{ let (enable,mv,air_accel_limit,tick_rate)=value.into_inner(); - let header=air_accel_limit.is_some() as u8&StrafeSettings::AIR_ACCEL_LIMIT; + let header=flag(air_accel_limit.is_some(),StrafeSettings::AIR_ACCEL_LIMIT); Self{ header, enable:enable.into(), diff --git a/src/newtypes/model.rs b/src/newtypes/model.rs index e8eb657..6b874d0 100644 --- a/src/newtypes/model.rs +++ b/src/newtypes/model.rs @@ -1,3 +1,4 @@ +use super::common::flag; use strafesnet_common::model::PolygonIter; use super::integer::{Planar64Vec3,Planar64Affine3}; @@ -76,7 +77,7 @@ impl Into for RenderConfig{ } impl From for RenderConfig{ fn from(value:strafesnet_common::model::RenderConfig)->Self{ - let header=value.texture.is_some() as u8&RenderConfig::TEXTURE; + let header=flag(value.texture.is_some(),RenderConfig::TEXTURE); Self{ header, texture:value.texture.map(|texture_id|texture_id.get()),