From e5101f6c7d36385a642d6c00681db8c87727cb05 Mon Sep 17 00:00:00 2001 From: Melik Houij Date: Thu, 23 Mar 2023 12:17:21 +0100 Subject: [PATCH] Working on letting debug interact with scene while being a seperate module currently buggy and for some reason debug only returns model --- src/debug.rs | 126 ++++++++++++++++++++++++++++++++++------------ src/debug/info.rs | 12 +++++ src/scene.rs | 19 ++++++- 3 files changed, 122 insertions(+), 35 deletions(-) create mode 100644 src/debug/info.rs diff --git a/src/debug.rs b/src/debug.rs index c7b3d75..0b45bdd 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -6,21 +6,34 @@ use sdl2::event::Event; const MODELS: [&str; 3]= ["resources/models/TestCarModel/CarW4.obj", "resources/models/TestCarModel/CarW1.obj", "resources/models/TestCarModel/CarW0.obj"]; - +mod info; pub enum dEvent { loadModel(i32), + setTest(f32, i32), exit, } +pub enum Callback + { + ModelInfo(info::ModelI), + TestWind(info::testI), + } + +#[derive(Clone)] +pub enum OpenWindows { + TestWind, + ModelInfo +} + pub struct Debug { imgui: imgui::Context, renderer: AutoRenderer, platform: SdlPlatform, - selectedModel: i32 + pub windows: Vec, } @@ -44,7 +57,7 @@ impl Debug { imgui, renderer, platform, - selectedModel: 0, + windows: vec![OpenWindows::TestWind, OpenWindows::ModelInfo], } } @@ -52,42 +65,28 @@ impl Debug { { self.platform.handle_event(&mut self.imgui, event); } + pub fn windows(self) -> Vec + { + let ret = self.windows.clone(); + ret + } pub fn drawImgui(&mut self, events_loop: &sdl2::EventPump, window: &sdl2::video::Window, - tempData: &mut crate::scene::tempData, Car: &crate::model::Model) -> Vec + callback: Vec) -> Vec { self.platform.prepare_frame(&mut self.imgui, &window, &events_loop ); let ui = self.imgui.new_frame(); - let mut ret = Vec::::new(); + let mut ret = Vec::new(); + for call in callback + { + match call { + Callback::ModelInfo(a) => + Debug::displayModel(ui, &a), + Callback::TestWind(mut a) => + ret = Debug::displayTest(ui, &mut a), + } + } - ui.window("POLY I WILL FUCKING") - .size([500.0, 100.0], imgui::Condition::FirstUseEver) - .build(|| { - ui.text("you serve no purpose in life"); - ui.text("Your Purpose in life is to suck my dick"); - ui.slider("The Spin Speed", 0.1, 10.0, &mut tempData.spinSpeed); - if ui - .button("Quit") { - ret.push(dEvent::exit); - } - if ui.list_box("Select Model to Load", &mut self.selectedModel, &MODELS, 5) { - ret.push(dEvent::loadModel(self.selectedModel)); - } - }); - - ui.window("Stats") - .size([300.0,500.0], imgui::Condition::Always) - .build(|| { - ui.text("Model Information"); - ui.separator(); - ui.text(format!("count meshes: {}", Car.meshes.len())); - for i in 0..Car.meshes.len() - { - ui.text(format!("Mesh Number: {}",i )); - ui.text(format!("count vertices: {}", Car.meshes[i].vertices.len())); - ui.separator(); - } - }); let draw_data = self.imgui.render(); @@ -97,4 +96,65 @@ impl Debug { ret } + fn displayTest(ui: &mut imgui::Ui, testI: &mut info::testI) -> Vec + { + let mut ret = Vec::new(); + ui.window("POLY I WILL FUCKING") + .size([500.0, 100.0], imgui::Condition::FirstUseEver) + .build(|| { + ui.text("you serve no purpose in life"); + ui.text("Your Purpose in life is to suck my dick"); + ui.slider("The Spin Speed", 0.1, 10.0, &mut testI.spinSpeed); + if ui + .button("Quit") { + ret.push(dEvent::exit); + } + if ui.list_box("Select Model to Load", &mut testI.selectedModel, &MODELS, 5) { + ret.push(dEvent::loadModel(testI.selectedModel)); + } + }); + ret + } + + fn displayModel(ui: &mut imgui::Ui ,model: &info::ModelI) + { + ui.window("Stats") + .size([300.0, 500.0], imgui::Condition::Always) + .build(|| { + ui.text("Model Information"); + ui.text(format!("count meshes: {}", model.meshesCount)); + ui.separator(); + for i in 0..model.meshesCount + { + ui.text(format!("Mesh Number {}", i)); + ui.text(format!("count Vertices: {}", model.vertCount[i])); + ui.separator(); + } + }); + } + } + + + +use crate::model; +pub fn ModelInfo(model: &model::Model) -> Callback + { + let mut vertCount = Vec::new(); + let meshesCount = model.meshes.len(); + for i in 0..model.meshes.len() { + vertCount.push(model.meshes[i].vertices.len()); + } + Callback::ModelInfo(info::ModelI { + meshesCount, + vertCount + }) + } + +pub fn TestWind(spinSpeed: f32, selectedModel: i32) -> Callback + { + Callback::TestWind(info::testI { + spinSpeed, + selectedModel, + }) + } diff --git a/src/debug/info.rs b/src/debug/info.rs new file mode 100644 index 0000000..b4386b1 --- /dev/null +++ b/src/debug/info.rs @@ -0,0 +1,12 @@ + +pub struct ModelI +{ + pub meshesCount: usize, + pub vertCount: Vec +} + +pub struct testI + { + pub spinSpeed: f32, + pub selectedModel: i32, + } diff --git a/src/scene.rs b/src/scene.rs index 6c1c2fb..d1bc121 100644 --- a/src/scene.rs +++ b/src/scene.rs @@ -8,7 +8,7 @@ use glow::*; use imgui_glow_renderer::AutoRenderer; use imgui_sdl2_support::SdlPlatform; - +use crate::debug; use cgmath::{Matrix4, vec3, Point3, Deg, perspective}; use cgmath::prelude::*; @@ -31,6 +31,7 @@ pub struct tempData { pub deltaTime: f32, pub lastFrame: f32, DebugMode: bool, + selectedModel: i32 } use crate::debug::Debug; @@ -74,6 +75,7 @@ impl Scene{ deltaTime: 0.0, lastFrame: 0.0, DebugMode: false, + selectedModel: 0, }; @@ -115,8 +117,21 @@ impl Scene{ } self.Car.Draw(&self.shaders[0]); + if self.tempData.DebugMode{ - for command in self.debug.drawImgui(&events_loop, &window, &mut self.tempData, &self.Car) + let mut Callbacks = Vec::new(); + let windows = self.debug.windows.clone(); + for i in 0..windows.len() + { + + match &windows[i] { + ModelInfo => Callbacks.push(debug::ModelInfo(&self.Car)), + TestWind => Callbacks.push(debug::TestWind(self.tempData.spinSpeed, self.tempData.selectedModel)), + + } + } + + for command in self.debug.drawImgui(&events_loop, &window, Callbacks) { use crate::debug::dEvent; match command