From 9fc78842708cfe8eb1434dd0fe0721fba79c537c Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 25 Oct 2023 19:51:24 -0700 Subject: [PATCH] rename Model{Graphics|Physics} for consistency --- src/graphics.rs | 34 +++++++++++++++++----------------- src/graphics_worker.rs | 2 +- src/model_graphics.rs | 24 ++++++++++++------------ src/physics.rs | 24 ++++++++++++------------ 4 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/graphics.rs b/src/graphics.rs index 2d799e19..2c15a1c7 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -1,9 +1,9 @@ use std::borrow::Cow; use wgpu::{util::DeviceExt,AstcBlock,AstcChannel}; -use crate::model_graphics::{GraphicsVertex,ModelGraphicsColor4,ModelGraphicsInstance,ModelGraphicsSingleTexture,IndexedModelGraphicsSingleTexture,IndexedGroupFixedTexture}; +use crate::model_graphics::{GraphicsVertex,GraphicsModelColor4,GraphicsModelInstance,GraphicsModelSingleTexture,IndexedGraphicsModelSingleTexture,IndexedGroupFixedTexture}; #[derive(Clone)] -pub struct ModelUpdate{ +pub struct GraphicsModelUpdate{ transform:Option, color:Option, } @@ -26,13 +26,13 @@ fn create_entities(device:&wgpu::Device,entities:&Vec>)- }).collect() } -struct ModelGraphics{ +struct GraphicsModel{ entities:Vec, model_buf:wgpu::Buffer, vertex_buf:wgpu::Buffer, bind_group:wgpu::BindGroup, index_format:wgpu::IndexFormat, - instances:Vec, + instances:Vec, } pub struct GraphicsSamplers{ @@ -110,7 +110,7 @@ pub struct GraphicsState{ camera:GraphicsCamera, camera_buf: wgpu::Buffer, temp_squid_texture_view: wgpu::TextureView, - models: Vec, + models: Vec, depth_view: wgpu::TextureView, staging_belt: wgpu::util::StagingBelt, } @@ -214,15 +214,15 @@ impl GraphicsState{ let indexed_models_len=indexed_models.models.len(); let mut unique_texture_models=Vec::with_capacity(indexed_models_len); for model in indexed_models.models.into_iter(){ - //convert ModelInstance into ModelGraphicsInstance - let instances:Vec=model.instances.into_iter().filter_map(|instance|{ + //convert ModelInstance into GraphicsModelInstance + let instances:Vec=model.instances.into_iter().filter_map(|instance|{ if instance.color.w==0.0{ None }else{ - Some(ModelGraphicsInstance{ + Some(GraphicsModelInstance{ transform: instance.transform.into(), normal_transform: Into::::into(instance.transform.matrix3).inverse().transpose(), - color:ModelGraphicsColor4::from(instance.color), + color:GraphicsModelColor4::from(instance.color), }) } }).collect(); @@ -241,7 +241,7 @@ impl GraphicsState{ //create new texture_index let texture_index=unique_textures.len(); unique_textures.push(group.texture); - unique_texture_models.push(IndexedModelGraphicsSingleTexture{ + unique_texture_models.push(IndexedGraphicsModelSingleTexture{ unique_pos:model.unique_pos.iter().map(|&v|*Into::::into(v).as_ref()).collect(), unique_tex:model.unique_tex.iter().map(|v|*v.as_ref()).collect(), unique_normal:model.unique_normal.iter().map(|&v|*Into::::into(v).as_ref()).collect(), @@ -396,7 +396,7 @@ impl GraphicsState{ } } //push model into dedup - deduplicated_models.push(IndexedModelGraphicsSingleTexture{ + deduplicated_models.push(IndexedGraphicsModelSingleTexture{ unique_pos, unique_tex, unique_normal, @@ -406,7 +406,7 @@ impl GraphicsState{ groups:vec![IndexedGroupFixedTexture{ polys }], - instances:vec![ModelGraphicsInstance{ + instances:vec![GraphicsModelInstance{ transform:glam::Mat4::IDENTITY, normal_transform:glam::Mat3::IDENTITY, color @@ -424,7 +424,7 @@ impl GraphicsState{ //de-index models let deduplicated_models_len=deduplicated_models.len(); - let models:Vec=deduplicated_models.into_iter().map(|model|{ + let models:Vec=deduplicated_models.into_iter().map(|model|{ let mut vertices = Vec::new(); let mut index_from_vertex = std::collections::HashMap::new();//:: //this mut be combined in a more complex way if the models use different render patterns per group @@ -452,7 +452,7 @@ impl GraphicsState{ } } } - ModelGraphicsSingleTexture{ + GraphicsModelSingleTexture{ instances:model.instances, entities:if (u16::MAX as usize)(); const MODEL_BUFFER_SIZE_BYTES:usize=MODEL_BUFFER_SIZE*4; -fn get_instances_buffer_data(instances:&[ModelGraphicsInstance]) -> Vec { +fn get_instances_buffer_data(instances:&[GraphicsModelInstance]) -> Vec { let mut raw = Vec::with_capacity(MODEL_BUFFER_SIZE*instances.len()); for (i,mi) in instances.iter().enumerate(){ let mut v = raw.split_off(MODEL_BUFFER_SIZE*i); @@ -1000,4 +1000,4 @@ fn get_instances_buffer_data(instances:&[ModelGraphicsInstance]) -> Vec { raw.append(&mut v); } raw -} \ No newline at end of file +} diff --git a/src/graphics_worker.rs b/src/graphics_worker.rs index b7ff5739..bf3f1013 100644 --- a/src/graphics_worker.rs +++ b/src/graphics_worker.rs @@ -1,6 +1,6 @@ pub enum Instruction{ Render(crate::physics::PhysicsOutputState,crate::integer::Time,glam::IVec2), - //UpdateModel(crate::graphics::ModelUpdate), + //UpdateModel(crate::graphics::GraphicsModelUpdate), Resize(winit::dpi::PhysicalSize,crate::settings::UserSettings), GenerateModels(crate::model::IndexedModelInstances), ClearModels, diff --git a/src/model_graphics.rs b/src/model_graphics.rs index 384e7a19..8e871e7a 100644 --- a/src/model_graphics.rs +++ b/src/model_graphics.rs @@ -11,7 +11,7 @@ pub struct GraphicsVertex { pub struct IndexedGroupFixedTexture{ pub polys:Vec, } -pub struct IndexedModelGraphicsSingleTexture{ +pub struct IndexedGraphicsModelSingleTexture{ pub unique_pos:Vec<[f32; 3]>, pub unique_tex:Vec<[f32; 2]>, pub unique_normal:Vec<[f32; 3]>, @@ -19,41 +19,41 @@ pub struct IndexedModelGraphicsSingleTexture{ pub unique_vertices:Vec, pub texture:Option,//RenderPattern? material/texture/shader/flat color pub groups: Vec, - pub instances:Vec, + pub instances:Vec, } pub enum Entities{ U32(Vec>), U16(Vec>), } -pub struct ModelGraphicsSingleTexture{ - pub instances:Vec, +pub struct GraphicsModelSingleTexture{ + pub instances:Vec, pub vertices:Vec, pub entities:Entities, pub texture:Option, } #[derive(Clone,PartialEq)] -pub struct ModelGraphicsColor4(glam::Vec4); -impl ModelGraphicsColor4{ +pub struct GraphicsModelColor4(glam::Vec4); +impl GraphicsModelColor4{ pub const fn get(&self)->glam::Vec4{ self.0 } } -impl From for ModelGraphicsColor4{ +impl From for GraphicsModelColor4{ fn from(value:glam::Vec4)->Self{ Self(value) } } -impl std::hash::Hash for ModelGraphicsColor4{ +impl std::hash::Hash for GraphicsModelColor4{ fn hash(&self,state:&mut H) { for &f in self.0.as_ref(){ bytemuck::cast::(f).hash(state); } } } -impl Eq for ModelGraphicsColor4{} +impl Eq for GraphicsModelColor4{} #[derive(Clone)] -pub struct ModelGraphicsInstance{ +pub struct GraphicsModelInstance{ pub transform:glam::Mat4, pub normal_transform:glam::Mat3, - pub color:ModelGraphicsColor4, -} \ No newline at end of file + pub color:GraphicsModelColor4, +} diff --git a/src/physics.rs b/src/physics.rs index 97fd93b5..92b5151d 100644 --- a/src/physics.rs +++ b/src/physics.rs @@ -155,7 +155,7 @@ impl Default for Modes{ } struct PhysicsModels{ - models:Vec, + models:Vec, model_id_from_wormhole_id:std::collections::HashMap::, } impl PhysicsModels{ @@ -163,13 +163,13 @@ impl PhysicsModels{ self.models.clear(); self.model_id_from_wormhole_id.clear(); } - fn get(&self,i:usize)->Option<&ModelPhysics>{ + fn get(&self,i:usize)->Option<&PhysicsModel>{ self.models.get(i) } - fn get_wormhole_model(&self,wormhole_id:u32)->Option<&ModelPhysics>{ + fn get_wormhole_model(&self,wormhole_id:u32)->Option<&PhysicsModel>{ self.models.get(*self.model_id_from_wormhole_id.get(&wormhole_id)?) } - fn push(&mut self,model:ModelPhysics)->usize{ + fn push(&mut self,model:PhysicsModel)->usize{ let model_id=self.models.len(); self.models.push(model); model_id @@ -602,7 +602,7 @@ enum PhysicsCollisionAttributes{ }, } -pub struct ModelPhysics { +pub struct PhysicsModel { //A model is a thing that has a hitbox. can be represented by a list of TreyMesh-es //in this iteration, all it needs is extents. mesh: TreyMesh, @@ -610,7 +610,7 @@ pub struct ModelPhysics { attributes:PhysicsCollisionAttributes, } -impl ModelPhysics { +impl PhysicsModel { fn from_model_transform_attributes(model:&crate::model::IndexedModel,transform:&crate::integer::Planar64Affine3,attributes:PhysicsCollisionAttributes)->Self{ let mut aabb=TreyMesh::default(); for indexed_vertex in &model.unique_vertices { @@ -624,8 +624,8 @@ impl ModelPhysics { } pub fn from_model(model:&crate::model::IndexedModel,instance:&crate::model::ModelInstance) -> Option { match &instance.attributes{ - crate::model::CollisionAttributes::Contact{contacting,general}=>Some(ModelPhysics::from_model_transform_attributes(model,&instance.transform,PhysicsCollisionAttributes::Contact{contacting:contacting.clone(),general:general.clone()})), - crate::model::CollisionAttributes::Intersect{intersecting,general}=>Some(ModelPhysics::from_model_transform_attributes(model,&instance.transform,PhysicsCollisionAttributes::Intersect{intersecting:intersecting.clone(),general:general.clone()})), + crate::model::CollisionAttributes::Contact{contacting,general}=>Some(PhysicsModel::from_model_transform_attributes(model,&instance.transform,PhysicsCollisionAttributes::Contact{contacting:contacting.clone(),general:general.clone()})), + crate::model::CollisionAttributes::Intersect{intersecting,general}=>Some(PhysicsModel::from_model_transform_attributes(model,&instance.transform,PhysicsCollisionAttributes::Intersect{intersecting:intersecting.clone(),general:general.clone()})), crate::model::CollisionAttributes::Decoration=>None, } } @@ -652,10 +652,10 @@ pub struct RelativeCollision { } impl RelativeCollision { - fn model<'a>(&self,models:&'a PhysicsModels)->Option<&'a ModelPhysics>{ + fn model<'a>(&self,models:&'a PhysicsModels)->Option<&'a PhysicsModel>{ models.get(self.model) } - // pub fn mesh(&self,models:&Vec) -> TreyMesh { + // pub fn mesh(&self,models:&Vec) -> TreyMesh { // return self.model(models).unwrap().face_mesh(self.face).clone() // } fn normal(&self,models:&PhysicsModels) -> Planar64Vec3 { @@ -792,7 +792,7 @@ impl PhysicsState { for model in &indexed_models.models{ //make aabb and run vertices to get realistic bounds for model_instance in &model.instances{ - if let Some(model_physics)=ModelPhysics::from_model(model,model_instance){ + if let Some(model_physics)=PhysicsModel::from_model(model,model_instance){ let model_id=self.models.push(model_physics); for attr in &model_instance.temp_indexing{ match attr{ @@ -1263,7 +1263,7 @@ fn teleport_to_spawn(body:&mut Body,touching:&mut TouchingState,style:&StyleModi Some(teleport(body,touching,style,point)) } -fn run_teleport_behaviour(teleport_behaviour:&Option,game:&mut GameMechanicsState,models:&PhysicsModels,modes:&Modes,style:&StyleModifiers,touching:&mut TouchingState,body:&mut Body,model:&ModelPhysics)->Option{ +fn run_teleport_behaviour(teleport_behaviour:&Option,game:&mut GameMechanicsState,models:&PhysicsModels,modes:&Modes,style:&StyleModifiers,touching:&mut TouchingState,body:&mut Body,model:&PhysicsModel)->Option{ match teleport_behaviour{ Some(crate::model::TeleportBehaviour::StageElement(stage_element))=>{ if stage_element.force||game.stage_id