From f7b774c0509a2acd0aa372a0bf2c9d805e51eec5 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Sun, 4 Feb 2024 22:36:43 -0800 Subject: [PATCH] wip --- src/gameplay_modes.rs | 37 ++++++++++++++++++++++++++++--------- src/model.rs | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 59 insertions(+), 12 deletions(-) diff --git a/src/gameplay_modes.rs b/src/gameplay_modes.rs index 923407a..ecb1da6 100644 --- a/src/gameplay_modes.rs +++ b/src/gameplay_modes.rs @@ -5,14 +5,14 @@ use crate::updatable::Updatable; #[derive(Clone)] pub struct StageElement{ - pub stage:StageId,//which stage spawn to send to + pub stage_id:StageId,//which stage spawn to send to pub force:bool,//allow setting to lower spawn id i.e. 7->3 pub behaviour:StageElementBehaviour } impl StageElement{ pub fn new(stage_id:u32,force:bool,behaviour:StageElementBehaviour)->Self{ Self{ - stage:StageId(stage_id), + stage_id:StageId(stage_id), force, behaviour, } @@ -32,13 +32,26 @@ pub enum StageElementBehaviour{ } #[derive(Clone,Copy,Hash,Eq,PartialEq)] -pub struct CheckpointId(usize); -#[derive(Clone,Copy,Hash,Eq,PartialEq,Ord,PartialOrd)] -pub struct StageId(u32); -impl StageId{ +pub struct CheckpointId(u32); +impl CheckpointId{ + #[inline] pub const fn id(id:u32)->Self{ Self(id) } + #[inline] + pub const fn get(self)->u32{ + self.0 + } +} +#[derive(Clone,Copy,Hash,Eq,PartialEq,Ord,PartialOrd)] +pub struct StageId(u32); +impl StageId{ + pub const FIRST:Self=Self(0); + #[inline] + pub const fn id(id:u32)->Self{ + Self(id) + } + #[inline] pub const fn get(self)->u32{ self.0 } @@ -60,6 +73,10 @@ impl Stage{ unordered_checkpoints:HashSet::new(), } } + #[inline] + pub const fn spawn(&self)->ModelId{ + self.spawn + } } #[derive(Default)] pub struct StageUpdate{ @@ -85,9 +102,11 @@ pub struct ModeId(u32); impl ModeId{ pub const MAIN:Self=Self(0); pub const BONUS:Self=Self(1); + #[inline] pub const fn id(id:u32)->Self{ Self(id) } + #[inline] pub const fn get(&self)->u32{ self.0 } @@ -139,20 +158,20 @@ impl Mode{ self.zones.insert(self.start,Zone::Start); for (stage_id,stage) in self.stages.iter().enumerate(){ self.elements.insert(stage.spawn,StageElement{ - stage:StageId(stage_id as u32), + stage_id:StageId(stage_id as u32), force:false, behaviour:StageElementBehaviour::SpawnAt, }); for (_,&model) in &stage.ordered_checkpoints{ self.elements.insert(model,StageElement{ - stage:StageId(stage_id as u32), + stage_id:StageId(stage_id as u32), force:false, behaviour:StageElementBehaviour::Checkpoint, }); } for &model in &stage.unordered_checkpoints{ self.elements.insert(model,StageElement{ - stage:StageId(stage_id as u32), + stage_id:StageId(stage_id as u32), force:false, behaviour:StageElementBehaviour::Checkpoint, }); diff --git a/src/model.rs b/src/model.rs index 655aca5..0b7644d 100644 --- a/src/model.rs +++ b/src/model.rs @@ -8,30 +8,50 @@ pub type Color4=glam::Vec4; #[derive(Clone,Copy,Hash,PartialEq,Eq)] pub struct PositionId(u32); impl PositionId{ + #[inline] pub const fn id(id:u32)->Self{ Self(id) } + #[inline] + pub const fn get(self)->u32{ + self.0 + } } #[derive(Clone,Copy,Hash,PartialEq,Eq)] pub struct TextureCoordinateId(u32); impl TextureCoordinateId{ + #[inline] pub const fn id(id:u32)->Self{ Self(id) } + #[inline] + pub const fn get(self)->u32{ + self.0 + } } #[derive(Clone,Copy,Hash,PartialEq,Eq)] pub struct NormalId(u32); impl NormalId{ + #[inline] pub const fn id(id:u32)->Self{ Self(id) } + #[inline] + pub const fn get(self)->u32{ + self.0 + } } #[derive(Clone,Copy,Hash,PartialEq,Eq)] pub struct ColorId(u32); impl ColorId{ + #[inline] pub const fn id(id:u32)->Self{ Self(id) } + #[inline] + pub const fn get(self)->u32{ + self.0 + } } #[derive(Clone,Hash,PartialEq,Eq)] pub struct IndexedVertex{ @@ -43,9 +63,14 @@ pub struct IndexedVertex{ #[derive(Clone,Copy,Hash,PartialEq,Eq)] pub struct VertexId(u32); impl VertexId{ + #[inline] pub const fn id(id:u32)->Self{ Self(id) } + #[inline] + pub const fn get(self)->u32{ + self.0 + } } pub struct IndexedVertexList{ pub vertices:Vec, @@ -119,12 +144,15 @@ pub struct IndexedModel{ pub physics_groups:Vec, } -#[derive(Clone,Copy,Hash,Eq,PartialEq)] +#[derive(Debug,Clone,Copy,Hash,Eq,PartialEq)] pub struct ModelId(u32); impl ModelId{ pub const fn id(id:u32)->Self{ Self(id) } + pub const fn get(&self)->u32{ + self.0 + } } pub struct Model{ pub model:IndexedModelId, @@ -134,8 +162,8 @@ pub struct Model{ } pub struct Models{ - indexed_models:HashMap, - models:HashMap, + pub indexed_models:HashMap, + pub models:HashMap, } impl Models{ pub fn new(