From 4dca7fc369905aeda213127301a98e6ed860a002 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 6 Jan 2025 21:22:40 -0800 Subject: [PATCH] try_increment_jump_count monolithic function --- strafe-client/src/physics.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/strafe-client/src/physics.rs b/strafe-client/src/physics.rs index 1d09a62..0180477 100644 --- a/strafe-client/src/physics.rs +++ b/strafe-client/src/physics.rs @@ -326,6 +326,15 @@ impl std::default::Default for PhysicsCamera{ } mod gameplay{ use super::{gameplay_modes,HashSet,HashMap,ModelId}; + pub enum JumpIncrementResult{ + Allowed, + ExceededLimit, + } + impl JumpIncrementResult{ + pub const fn is_allowed(self)->bool{ + matches!(self,JumpIncrementResult::Allowed) + } + } #[derive(Clone,Debug)] pub struct ModeState{ mode_id:gameplay_modes::ModeId, @@ -344,8 +353,14 @@ mod gameplay{ pub const fn get_next_ordered_checkpoint_id(&self)->gameplay_modes::CheckpointId{ self.next_ordered_checkpoint_id } - pub fn get_jump_count(&self,model_id:ModelId)->Option{ - self.jump_counts.get(&model_id).copied() + fn increment_jump_count(&mut self,model_id:ModelId)->u32{ + *self.jump_counts.entry(model_id).and_modify(|c|*c+=1).or_insert(1) + } + pub fn try_increment_jump_count(&mut self,model_id:ModelId,jump_limit:Option)->JumpIncrementResult{ + match jump_limit{ + Some(jump_limit) if (jump_limit as u32)JumpIncrementResult::ExceededLimit, + _=>JumpIncrementResult::Allowed, + } } pub const fn ordered_checkpoint_count(&self)->u32{ self.next_ordered_checkpoint_id.get()