From 64948b487687d72758a42b458ddc37813e1a91f9 Mon Sep 17 00:00:00 2001 From: kokosha Date: Sat, 14 Dec 2024 15:50:45 -0300 Subject: [PATCH] Rename entity debug to rectangle --- korangar/src/graphics/engine.rs | 38 +++++++++---------- korangar/src/graphics/instruction.rs | 6 +-- korangar/src/graphics/passes/forward/mod.rs | 8 ++-- .../forward/{entity_debug.rs => rectangle.rs} | 16 ++++---- .../{entity_debug.wgsl => rectangle.wgsl} | 0 korangar/src/main.rs | 22 +++++------ korangar/src/world/animation/mod.rs | 12 +++--- korangar/src/world/entity/mod.rs | 6 +-- korangar/src/world/map/mod.rs | 4 +- 9 files changed, 55 insertions(+), 57 deletions(-) rename korangar/src/graphics/passes/forward/{entity_debug.rs => rectangle.rs} (92%) rename korangar/src/graphics/passes/forward/shader/{entity_debug.wgsl => rectangle.wgsl} (100%) diff --git a/korangar/src/graphics/engine.rs b/korangar/src/graphics/engine.rs index 8a2d52db..7b73513c 100644 --- a/korangar/src/graphics/engine.rs +++ b/korangar/src/graphics/engine.rs @@ -91,8 +91,6 @@ struct EngineContext { point_shadow_indicator_drawer: PointShadowIndicatorDrawer, light_culling_dispatcher: LightCullingDispatcher, forward_entity_drawer: ForwardEntityDrawer, - #[cfg(feature = "debug")] - forward_entity_debug_drawer: ForwardEntityDebugDrawer, forward_indicator_drawer: ForwardIndicatorDrawer, forward_model_drawer: ForwardModelDrawer, water_wave_drawer: WaterWaveDrawer, @@ -106,6 +104,8 @@ struct EngineContext { #[cfg(feature = "debug")] forward_circle_drawer: ForwardCircleDrawer, #[cfg(feature = "debug")] + forward_rectangle_drawer: ForwardRectangleDrawer, + #[cfg(feature = "debug")] post_processing_buffer_drawer: PostProcessingBufferDrawer, #[cfg(feature = "debug")] picker_marker_drawer: PickerMarkerDrawer, @@ -285,16 +285,15 @@ impl GraphicsEngine { ); let ForwardResources { forward_entity_drawer, - #[cfg(feature = "debug")] - forward_entity_debug_drawer, forward_indicator_drawer, forward_model_drawer, #[cfg(feature = "debug")] forward_aabb_drawer, - #[cfg(feature = "debug")] forward_circle_drawer, + #[cfg(feature = "debug")] + forward_rectangle_drawer, } = ForwardResources::create( &self.capabilities, &self.device, @@ -362,8 +361,6 @@ impl GraphicsEngine { point_shadow_entity_drawer, light_culling_dispatcher, forward_entity_drawer, - #[cfg(feature = "debug")] - forward_entity_debug_drawer, forward_indicator_drawer, forward_model_drawer, water_wave_drawer, @@ -377,6 +374,8 @@ impl GraphicsEngine { #[cfg(feature = "debug")] forward_circle_drawer, #[cfg(feature = "debug")] + forward_rectangle_drawer, + #[cfg(feature = "debug")] post_processing_buffer_drawer, #[cfg(feature = "debug")] picker_marker_drawer, @@ -488,14 +487,14 @@ impl GraphicsEngine { let ForwardResources { forward_entity_drawer, - #[cfg(feature = "debug")] - forward_entity_debug_drawer, forward_indicator_drawer, forward_model_drawer, #[cfg(feature = "debug")] forward_aabb_drawer, #[cfg(feature = "debug")] forward_circle_drawer, + #[cfg(feature = "debug")] + forward_rectangle_drawer, } = ForwardResources::create( &self.capabilities, &self.device, @@ -539,8 +538,8 @@ impl GraphicsEngine { { engine_context.forward_aabb_drawer = forward_aabb_drawer; engine_context.forward_circle_drawer = forward_circle_drawer; + engine_context.forward_rectangle_drawer = forward_rectangle_drawer; engine_context.post_processing_buffer_drawer = post_processing_buffer_drawer; - engine_context.forward_entity_debug_drawer = forward_entity_debug_drawer; } } } @@ -780,13 +779,12 @@ impl GraphicsEngine { scope.spawn(|_| { context.picker_marker_drawer.prepare(&self.device, instruction); context.forward_aabb_drawer.prepare(&self.device, instruction); - #[cfg(feature = "debug")] - context.forward_entity_debug_drawer.prepare(&self.device, instruction); }); #[cfg(feature = "debug")] scope.spawn(|_| { context.post_processing_buffer_drawer.prepare(&self.device, instruction); context.forward_circle_drawer.prepare(&self.device, instruction); + context.forward_rectangle_drawer.prepare(&self.device, instruction); }); context.global_context.prepare(&self.device, instruction); @@ -820,10 +818,10 @@ impl GraphicsEngine { #[cfg(feature = "debug")] { - visitor.upload(&mut context.forward_entity_debug_drawer); visitor.upload(&mut context.forward_aabb_drawer); visitor.upload(&mut context.post_processing_buffer_drawer); visitor.upload(&mut context.forward_circle_drawer); + visitor.upload(&mut context.forward_rectangle_drawer); visitor.upload(&mut context.picker_marker_drawer); } @@ -1012,7 +1010,7 @@ impl GraphicsEngine { { engine_context.forward_aabb_drawer.draw(&mut render_pass, None); engine_context.forward_circle_drawer.draw(&mut render_pass, None); - engine_context.forward_entity_debug_drawer.draw(&mut render_pass, None); + engine_context.forward_rectangle_drawer.draw(&mut render_pass, None); } if instruction.water.is_some() { @@ -1183,8 +1181,6 @@ impl<'a> UploadVisitor<'a> { struct ForwardResources { forward_entity_drawer: ForwardEntityDrawer, - #[cfg(feature = "debug")] - forward_entity_debug_drawer: ForwardEntityDebugDrawer, forward_indicator_drawer: ForwardIndicatorDrawer, forward_model_drawer: ForwardModelDrawer, @@ -1192,6 +1188,8 @@ struct ForwardResources { forward_aabb_drawer: ForwardAabbDrawer, #[cfg(feature = "debug")] forward_circle_drawer: ForwardCircleDrawer, + #[cfg(feature = "debug")] + forward_rectangle_drawer: ForwardRectangleDrawer, } impl ForwardResources { @@ -1203,25 +1201,25 @@ impl ForwardResources { forward_pass_context: &ForwardRenderPassContext, ) -> Self { let forward_entity_drawer = ForwardEntityDrawer::new(capabilities, device, queue, global_context, forward_pass_context); - #[cfg(feature = "debug")] - let forward_entity_debug_drawer = ForwardEntityDebugDrawer::new(capabilities, device, queue, global_context, forward_pass_context); let forward_indicator_drawer = ForwardIndicatorDrawer::new(capabilities, device, queue, global_context, forward_pass_context); let forward_model_drawer = ForwardModelDrawer::new(capabilities, device, queue, global_context, forward_pass_context); #[cfg(feature = "debug")] let forward_aabb_drawer = ForwardAabbDrawer::new(capabilities, device, queue, global_context, forward_pass_context); #[cfg(feature = "debug")] let forward_circle_drawer = ForwardCircleDrawer::new(capabilities, device, queue, global_context, forward_pass_context); + #[cfg(feature = "debug")] + let forward_rectangle_drawer = ForwardRectangleDrawer::new(capabilities, device, queue, global_context, forward_pass_context); Self { forward_entity_drawer, - #[cfg(feature = "debug")] - forward_entity_debug_drawer, forward_indicator_drawer, forward_model_drawer, #[cfg(feature = "debug")] forward_aabb_drawer, #[cfg(feature = "debug")] forward_circle_drawer, + #[cfg(feature = "debug")] + forward_rectangle_drawer, } } } diff --git a/korangar/src/graphics/instruction.rs b/korangar/src/graphics/instruction.rs index 27ef8879..a048a649 100644 --- a/korangar/src/graphics/instruction.rs +++ b/korangar/src/graphics/instruction.rs @@ -32,8 +32,6 @@ pub struct RenderInstruction<'a> { pub model_batches: &'a [ModelBatch], pub models: &'a mut [ModelInstruction], pub entities: &'a mut [EntityInstruction], - #[cfg(feature = "debug")] - pub entities_debug: &'a [DebugEntityInstruction], pub directional_model_batches: &'a [ModelBatch], pub directional_shadow_models: &'a [ModelInstruction], pub directional_shadow_entities: &'a [EntityInstruction], @@ -50,6 +48,8 @@ pub struct RenderInstruction<'a> { #[cfg(feature = "debug")] pub circles: &'a [DebugCircleInstruction], #[cfg(feature = "debug")] + pub rectangles: &'a [DebugRectangleInstruction], + #[cfg(feature = "debug")] pub marker: &'a [MarkerInstruction], } @@ -241,7 +241,7 @@ pub struct DebugCircleInstruction { #[cfg(feature = "debug")] #[derive(Copy, Clone, Debug)] -pub struct DebugEntityInstruction { +pub struct DebugRectangleInstruction { pub world: Matrix4, pub color: Color, } diff --git a/korangar/src/graphics/passes/forward/mod.rs b/korangar/src/graphics/passes/forward/mod.rs index 920bc1a5..3ff78a0b 100644 --- a/korangar/src/graphics/passes/forward/mod.rs +++ b/korangar/src/graphics/passes/forward/mod.rs @@ -3,20 +3,20 @@ mod aabb; #[cfg(feature = "debug")] mod circle; mod entity; -#[cfg(feature = "debug")] -mod entity_debug; mod indicator; mod model; +#[cfg(feature = "debug")] +mod rectangle; #[cfg(feature = "debug")] pub(crate) use aabb::ForwardAabbDrawer; #[cfg(feature = "debug")] pub(crate) use circle::ForwardCircleDrawer; pub(crate) use entity::ForwardEntityDrawer; -#[cfg(feature = "debug")] -pub(crate) use entity_debug::ForwardEntityDebugDrawer; pub(crate) use indicator::ForwardIndicatorDrawer; pub(crate) use model::ForwardModelDrawer; +#[cfg(feature = "debug")] +pub(crate) use rectangle::ForwardRectangleDrawer; use wgpu::{ BindGroupLayout, Color, CommandEncoder, Device, LoadOp, Operations, Queue, RenderPass, RenderPassColorAttachment, RenderPassDepthStencilAttachment, RenderPassDescriptor, StoreOp, TextureFormat, diff --git a/korangar/src/graphics/passes/forward/entity_debug.rs b/korangar/src/graphics/passes/forward/rectangle.rs similarity index 92% rename from korangar/src/graphics/passes/forward/entity_debug.rs rename to korangar/src/graphics/passes/forward/rectangle.rs index 5b252175..23d8f2ba 100644 --- a/korangar/src/graphics/passes/forward/entity_debug.rs +++ b/korangar/src/graphics/passes/forward/rectangle.rs @@ -17,8 +17,8 @@ use crate::graphics::passes::{ use crate::graphics::{Capabilities, GlobalContext, Prepare, RenderInstruction, SimpleVertex}; use crate::Buffer; -const SHADER: ShaderModuleDescriptor = include_wgsl!("shader/entity_debug.wgsl"); -const DRAWER_NAME: &str = "forward entity debug"; +const SHADER: ShaderModuleDescriptor = include_wgsl!("shader/rectangle.wgsl"); +const DRAWER_NAME: &str = "screen rectangle"; const INITIAL_INSTRUCTION_SIZE: usize = 256; const INDEX_COUNT: usize = 8; @@ -29,7 +29,7 @@ struct InstanceData { color: [f32; 4], } -pub(crate) struct ForwardEntityDebugDrawer { +pub(crate) struct ForwardRectangleDrawer { vertex_buffer: Buffer, index_buffer: Buffer, instance_data_buffer: Buffer, @@ -40,7 +40,7 @@ pub(crate) struct ForwardEntityDebugDrawer { instance_data: Vec, } -impl Drawer<{ BindGroupCount::Two }, { ColorAttachmentCount::One }, { DepthAttachmentCount::One }> for ForwardEntityDebugDrawer { +impl Drawer<{ BindGroupCount::Two }, { ColorAttachmentCount::One }, { DepthAttachmentCount::One }> for ForwardRectangleDrawer { type Context = ForwardRenderPassContext; type DrawData<'data> = Option<()>; @@ -173,9 +173,9 @@ impl Drawer<{ BindGroupCount::Two }, { ColorAttachmentCount::One }, { DepthAttac } } -impl Prepare for ForwardEntityDebugDrawer { +impl Prepare for ForwardRectangleDrawer { fn prepare(&mut self, _device: &Device, instructions: &RenderInstruction) { - self.draw_count = instructions.entities_debug.len(); + self.draw_count = instructions.rectangles.len(); if self.draw_count == 0 { return; @@ -183,7 +183,7 @@ impl Prepare for ForwardEntityDebugDrawer { self.instance_data.clear(); - for instruction in instructions.entities_debug.iter() { + for instruction in instructions.rectangles.iter() { self.instance_data.push(InstanceData { world: instruction.world.into(), color: instruction.color.into(), @@ -202,7 +202,7 @@ impl Prepare for ForwardEntityDebugDrawer { } } -impl ForwardEntityDebugDrawer { +impl ForwardRectangleDrawer { fn create_bind_group(device: &Device, bind_group_layout: &BindGroupLayout, instance_data_buffer: &Buffer) -> BindGroup { device.create_bind_group(&BindGroupDescriptor { label: Some(DRAWER_NAME), diff --git a/korangar/src/graphics/passes/forward/shader/entity_debug.wgsl b/korangar/src/graphics/passes/forward/shader/rectangle.wgsl similarity index 100% rename from korangar/src/graphics/passes/forward/shader/entity_debug.wgsl rename to korangar/src/graphics/passes/forward/shader/rectangle.wgsl diff --git a/korangar/src/main.rs b/korangar/src/main.rs index 6e6e04de..a46a6712 100644 --- a/korangar/src/main.rs +++ b/korangar/src/main.rs @@ -177,11 +177,11 @@ struct Client { aabb_instructions: Vec, #[cfg(feature = "debug")] circle_instructions: Vec, + #[cfg(feature = "debug")] + rectangle_instructions: Vec, model_batches: Vec, model_instructions: Vec, entity_instructions: Vec, - #[cfg(feature = "debug")] - entity_debug_instructions: Vec, directional_shadow_model_batches: Vec, directional_shadow_model_instructions: Vec, directional_shadow_entity_instructions: Vec, @@ -417,11 +417,11 @@ impl Client { let aabb_instructions = Vec::default(); #[cfg(feature = "debug")] let circle_instructions = Vec::default(); + #[cfg(feature = "debug")] + let rectangle_instructions = Vec::default(); let model_batches = Vec::default(); let model_instructions = Vec::default(); let entity_instructions = Vec::default(); - #[cfg(feature = "debug")] - let entity_debug_instructions = Vec::default(); let directional_shadow_model_batches = Vec::default(); let directional_shadow_model_instructions = Vec::default(); let directional_shadow_entity_instructions = Vec::default(); @@ -588,11 +588,11 @@ impl Client { aabb_instructions, #[cfg(feature = "debug")] circle_instructions, + #[cfg(feature = "debug")] + rectangle_instructions, model_batches, model_instructions, entity_instructions, - #[cfg(feature = "debug")] - entity_debug_instructions, directional_shadow_model_batches, directional_shadow_model_instructions, directional_shadow_entity_instructions, @@ -690,11 +690,11 @@ impl Client { self.aabb_instructions.clear(); #[cfg(feature = "debug")] self.circle_instructions.clear(); + #[cfg(feature = "debug")] + self.rectangle_instructions.clear(); self.model_batches.clear(); self.model_instructions.clear(); self.entity_instructions.clear(); - #[cfg(feature = "debug")] - self.entity_debug_instructions.clear(); self.directional_shadow_model_batches.clear(); self.directional_shadow_model_instructions.clear(); self.directional_shadow_entity_instructions.clear(); @@ -2105,7 +2105,7 @@ impl Client { #[cfg(feature = "debug")] if render_settings.show_entities_debug { self.map - .render_entities_debug(&mut self.entity_debug_instructions, entities, entity_camera); + .render_entities_debug(&mut self.rectangle_instructions, entities, entity_camera); } #[cfg_attr(feature = "debug", korangar_debug::debug_condition(render_settings.show_water))] @@ -2280,8 +2280,6 @@ impl Client { model_batches: &self.model_batches, models: &mut self.model_instructions, entities: &mut self.entity_instructions, - #[cfg(feature = "debug")] - entities_debug: &self.entity_debug_instructions, directional_model_batches: &self.directional_shadow_model_batches, directional_shadow_models: &self.directional_shadow_model_instructions, directional_shadow_entities: &self.directional_shadow_entity_instructions, @@ -2298,6 +2296,8 @@ impl Client { #[cfg(feature = "debug")] circles: &self.circle_instructions, #[cfg(feature = "debug")] + rectangles: &self.rectangle_instructions, + #[cfg(feature = "debug")] marker: self.debug_marker_renderer.get_instructions(), }; diff --git a/korangar/src/world/animation/mod.rs b/korangar/src/world/animation/mod.rs index e56d2924..00d2f6fa 100644 --- a/korangar/src/world/animation/mod.rs +++ b/korangar/src/world/animation/mod.rs @@ -6,7 +6,7 @@ use korangar_util::container::Cacheable; use ragnarok_packets::EntityId; #[cfg(feature = "debug")] -use crate::graphics::DebugEntityInstruction; +use crate::graphics::DebugRectangleInstruction; use crate::graphics::{Color, EntityInstruction}; use crate::loaders::{Actions, AnimationState, Sprite}; use crate::world::{Camera, EntityType}; @@ -186,7 +186,7 @@ impl AnimationData { #[cfg(feature = "debug")] pub fn render_debug( &self, - instructions: &mut Vec, + instructions: &mut Vec, camera: &dyn Camera, entity_position: Point3, animation_state: &AnimationState, @@ -200,20 +200,20 @@ impl AnimationData { let frame = self.get_frame(animation_state, camera, head_direction); let world_matrix = self.calculate_world_matrix(camera, frame, entity_position, SPRITE_SCALE, TILE_SIZE); let world_shift_offset = world_matrix * frame.offset_matrix; - instructions.push(DebugEntityInstruction { + instructions.push(DebugRectangleInstruction { world: world_shift_offset, color: color_external, }); - instructions.push(DebugEntityInstruction { + instructions.push(DebugRectangleInstruction { world: world_shift_offset * frame.horizontal_matrix, color: color_external, }); - instructions.push(DebugEntityInstruction { + instructions.push(DebugRectangleInstruction { world: world_shift_offset * frame.vertical_matrix, color: color_external, }); for frame_part in frame.frame_parts.iter() { - instructions.push(DebugEntityInstruction { + instructions.push(DebugRectangleInstruction { world: world_matrix * frame_part.affine_matrix, color: color_internal, }); diff --git a/korangar/src/world/entity/mod.rs b/korangar/src/world/entity/mod.rs index 651ecd2b..4a019d52 100644 --- a/korangar/src/world/entity/mod.rs +++ b/korangar/src/world/entity/mod.rs @@ -14,7 +14,7 @@ use ragnarok_packets::{AccountId, CharacterInformation, ClientTick, EntityId, Se use wgpu::{BufferUsages, Device, Queue}; #[cfg(feature = "debug")] -use crate::graphics::DebugEntityInstruction; +use crate::graphics::DebugRectangleInstruction; use crate::graphics::EntityInstruction; use crate::interface::application::InterfaceSettings; use crate::interface::layout::{ScreenPosition, ScreenSize}; @@ -779,7 +779,7 @@ impl Common { } #[cfg(feature = "debug")] - pub fn render_debug(&self, instructions: &mut Vec, camera: &dyn Camera) { + pub fn render_debug(&self, instructions: &mut Vec, camera: &dyn Camera) { self.animation_data.render_debug( instructions, camera, @@ -1153,7 +1153,7 @@ impl Entity { } #[cfg(feature = "debug")] - pub fn render_debug(&self, instructions: &mut Vec, camera: &dyn Camera) { + pub fn render_debug(&self, instructions: &mut Vec, camera: &dyn Camera) { self.get_common().render_debug(instructions, camera); } diff --git a/korangar/src/world/map/mod.rs b/korangar/src/world/map/mod.rs index 37cdda79..80535c97 100644 --- a/korangar/src/world/map/mod.rs +++ b/korangar/src/world/map/mod.rs @@ -29,7 +29,7 @@ use crate::graphics::ModelBatch; #[cfg(feature = "debug")] use crate::graphics::RenderSettings; #[cfg(feature = "debug")] -use crate::graphics::{DebugAabbInstruction, DebugCircleInstruction, DebugEntityInstruction}; +use crate::graphics::{DebugAabbInstruction, DebugCircleInstruction, DebugRectangleInstruction}; use crate::graphics::{EntityInstruction, IndicatorInstruction, ModelInstruction, Texture, WaterInstruction}; #[cfg(feature = "debug")] use crate::interface::application::InterfaceSettings; @@ -315,7 +315,7 @@ impl Map { #[cfg(feature = "debug")] #[cfg_attr(feature = "debug", korangar_debug::profile)] - pub fn render_entities_debug(&self, instructions: &mut Vec, entities: &[Entity], camera: &dyn Camera) { + pub fn render_entities_debug(&self, instructions: &mut Vec, entities: &[Entity], camera: &dyn Camera) { entities.iter().for_each(|entity| { entity.render_debug(instructions, camera); });