From 2229e3e7422af7c22e39398ca897b9d2e499524e Mon Sep 17 00:00:00 2001 From: Melik Houij Date: Thu, 16 Mar 2023 16:01:57 +0100 Subject: [PATCH 01/11] added SceneObj --- src/main.rs | 8 ++--- src/scene.rs | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 5 deletions(-) create mode 100644 src/scene.rs diff --git a/src/main.rs b/src/main.rs index aa00574..250a34f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,6 +34,9 @@ use std::ffi::{CString, CStr}; mod shader; mod model; mod camera; +mod scene; + + fn main() { let (gl, shader_version, window, mut events_loop, _context) = { @@ -96,11 +99,6 @@ fn main() { Pitch: -20.0, ..camera::Camera::default() }; - - let mut firstMouse = true; - let mut lastX: f32 = SCR_WIDTH as f32 / 2.0; - let mut lastY: f32 = SCR_HEIGHT as f32 / 2.0; - // timing let mut deltaTime: f32; // time between current frame and last frame let mut lastFrame: f32 = 0.0; diff --git a/src/scene.rs b/src/scene.rs new file mode 100644 index 0000000..12655fa --- /dev/null +++ b/src/scene.rs @@ -0,0 +1,97 @@ + +use crate::model::Model; +use crate::camera::Camera; +use crate::shader::shader; +use std::sync::Arc; +use std::rc::Rc; + + +use imgui_glow_renderer::AutoRenderer; +use imgui_sdl2_support::SdlPlatform; + +use cgmath::{Matrix4, vec3, Point3, Deg, perspective}; +use cgmath::prelude::*; + +const MODELS: [&str; 3]= ["resources/models/TestCarModel/CarW4.obj", "resources/models/TestCarModel/CarW1.obj", +"resources/models/TestCarModel/CarW0.obj"]; + +/// XXX this is temporary, thus the name +pub struct tempData { + pub projection: Matrix4, + pub spinSpeed: f32, + pub current_rad: f32, + pub currentFrame: f32, + pub deltaTime: f32, + pub lastFrame: f32, +} + + + +struct Scene { + gl: Arc, + pub Car: Model, + camera: Camera, + imgui: imgui::Context, + imgui_rend: AutoRenderer, + imgui_plat: SdlPlatform, + shaders: Vec>, + time: std::time::Instant, + tempData: tempData, +} + +impl Scene{ + fn new(gl: Arc) -> Scene + { + let Car = Model::new(MODELS[0], Arc::clone(&gl)); + + let shader = Rc::new(shader::new("model", Arc::clone(&gl))); + + let time = std::time::Instant::now(); + + let camera = Camera { + Position: Point3::new(0.0, 0.40, 1.0), + Pitch: -20.0, + ..Camera::default() + }; + + let tempData = tempData { + projection: perspective(Deg(45.0), 1600.0/ 900.0, 0.1, 100.0), + spinSpeed: 1.0, + current_rad: 1.0, + currentFrame: 0.0, + deltaTime: 0.0, + lastFrame: 0.0 + + }; + + let mut imgui = imgui::Context::create(); + + imgui + .fonts() + .add_font(&[imgui::FontSource::DefaultFontData {config: None}]); + + let mut platform = SdlPlatform::init(&mut imgui); + let mut renderer = match AutoRenderer::initialize(gl.clone(), &mut imgui) + { + Ok(ret) => ret, + Err(s) => panic!("Failed to initialize Imgui Platform Renderer: {}", s), + }; + + Scene{ + gl, + Car, + camera, + imgui, + imgui_rend: renderer, + imgui_plat: platform, + shaders: vec![shader], + time, + tempData, + } + + + + + + } +} From 60eba9cd4ee6669d655c3282734606bb2d4af60f Mon Sep 17 00:00:00 2001 From: Melik Houij Date: Mon, 20 Mar 2023 16:31:42 +0100 Subject: [PATCH 02/11] Using Scene instead of main loop, there is a bug Cannot Exit the Program --- src/main.rs | 68 +++----------------------------------------- src/scene.rs | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 80 insertions(+), 67 deletions(-) diff --git a/src/main.rs b/src/main.rs index 250a34f..8da0da7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,6 +36,7 @@ mod model; mod camera; mod scene; +use scene::Scene; fn main() { @@ -79,19 +80,6 @@ fn main() { - let mut imgui = imgui::Context::create(); - - imgui - .fonts() - .add_font(&[imgui::FontSource::DefaultFontData {config: None}]); - - - let mut platform = SdlPlatform::init(&mut imgui); - let mut renderer = match AutoRenderer::initialize(gl.clone(), &mut imgui) - { - Ok(ret) => ret, - Err(s) => panic!("Failed to initialize Imgui Platform Renderer: {}", s), - }; // NOTE intiialize Camera let mut camera = camera::Camera { @@ -118,15 +106,14 @@ fn main() { let mut State = gameState::Playing; + let mut scene = Scene::new(gl.clone()); - let time = std::time::Instant::now(); - let mut spinSpeed = 1.0; - let mut current_rad = 1.0; let projection: Matrix4 = perspective(Deg(45.0), SCR_WIDTH as f32/ SCR_HEIGHT as f32, 0.1, 100.0); + println!("entering main loop"); @@ -138,57 +125,11 @@ fn main() { 'main: loop { match &State { gameState::Playing => { - let currentFrame = time.elapsed().as_secs_f32(); - deltaTime = currentFrame - lastFrame; - lastFrame = currentFrame; - current_rad += spinSpeed/15.0; - - unsafe{ - gl.enable(glow::DEPTH_TEST); - gl.clear(glow::COLOR_BUFFER_BIT | glow::DEPTH_BUFFER_BIT); - - ourshader.Use(); - let Projection: Matrix4 = perspective(Deg(camera.Zoom), SCR_WIDTH as f32 / SCR_HEIGHT as f32, 0.1, 100.0); - - let view = camera.GetViewMatrix(); - ourshader.setMat4("projection", &projection); - ourshader.setMat4("view", &view); - - - - let mut model: Matrix4 = Matrix4::from_axis_angle(vec3(0.0, -1.0, 0.0).normalize(), - cgmath::Rad(current_rad)); - model = model * Matrix4::from_scale(0.2); - ourshader.setMat4("model", &model); - - - - - } - ourModel.Draw(&ourshader); - - platform.prepare_frame(&mut imgui, &window, &events_loop); - let ui = imgui.new_frame(); - - 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 spinSpeed); - }); - - drawDebugUI(ui, &ourModel); - let draw_data = imgui.render(); - - - renderer.render(draw_data).unwrap(); - + scene.update(&mut events_loop, &window); window.gl_swap_window(); for event in events_loop.poll_iter() { - platform.handle_event(&mut imgui, &event); match event { Event::Quit {..} | @@ -206,7 +147,6 @@ fn main() { gameState::Paused => { for event in events_loop.poll_iter() { - platform.handle_event(&mut imgui, &event); match event { Event::KeyDown {keycode: Some(Keycode::P), ..} => { diff --git a/src/scene.rs b/src/scene.rs index 12655fa..f9a2e5d 100644 --- a/src/scene.rs +++ b/src/scene.rs @@ -4,7 +4,7 @@ use crate::camera::Camera; use crate::shader::shader; use std::sync::Arc; use std::rc::Rc; - +use glow::*; use imgui_glow_renderer::AutoRenderer; use imgui_sdl2_support::SdlPlatform; @@ -12,9 +12,17 @@ use imgui_sdl2_support::SdlPlatform; use cgmath::{Matrix4, vec3, Point3, Deg, perspective}; use cgmath::prelude::*; +use sdl2::keyboard::Keycode; +use sdl2::event::Event; + +const SCR_WIDTH: u32 = 1600; +const SCR_HEIGHT: u32 = 900; + const MODELS: [&str; 3]= ["resources/models/TestCarModel/CarW4.obj", "resources/models/TestCarModel/CarW1.obj", "resources/models/TestCarModel/CarW0.obj"]; + + /// XXX this is temporary, thus the name pub struct tempData { pub projection: Matrix4, @@ -27,7 +35,7 @@ pub struct tempData { -struct Scene { +pub struct Scene { gl: Arc, pub Car: Model, camera: Camera, @@ -40,7 +48,7 @@ struct Scene { } impl Scene{ - fn new(gl: Arc) -> Scene + pub fn new(gl: Arc) -> Scene { let Car = Model::new(MODELS[0], Arc::clone(&gl)); @@ -88,10 +96,75 @@ impl Scene{ time, tempData, } + } + + pub fn update(&mut self ,events_loop: &mut sdl2::EventPump, window: &sdl2::video::Window) + { + self.tempData.currentFrame = self.time.elapsed().as_secs_f32(); + self.tempData.deltaTime = self.tempData.currentFrame - self.tempData.lastFrame; + self.tempData.lastFrame = self.tempData.currentFrame; + self.tempData.current_rad += self.tempData.spinSpeed/15.0; + + unsafe { + self.gl.enable(glow::DEPTH_TEST); + self.gl.clear(glow::COLOR_BUFFER_BIT | glow::DEPTH_BUFFER_BIT); + + self.shaders[0].Use(); + self.tempData.projection = perspective(Deg(self.camera.Zoom), SCR_WIDTH as f32 /SCR_HEIGHT as f32, 0.1, 100.0); + let view = self.camera.GetViewMatrix(); + self.shaders[0].setMat4("projection", &self.tempData.projection); + self.shaders[0].setMat4("view", &view); + + let mut model: Matrix4 = Matrix4::from_axis_angle(vec3(0.0, -1.0, 0.0).normalize(), + cgmath::Rad(self.tempData.current_rad)); + + model = model * Matrix4::from_scale(0.2); + self.shaders[0].setMat4("model", &model); + } + self.Car.Draw(&self.shaders[0]); + + self.drawImgui(&events_loop, &window); + + let quit = false; + for event in events_loop.poll_iter() { + self.imgui_plat.handle_event(&mut self.imgui, &event); + + } + } + fn drawImgui(&mut self, events_loop: &sdl2::EventPump, window: &sdl2::video::Window) + { + self.imgui_plat.prepare_frame(&mut self.imgui, &window, &events_loop ); + let ui = self.imgui.new_frame(); + + 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 self.tempData.spinSpeed); + }); + + ui.window("Stats") + .size([300.0,500.0], imgui::Condition::Always) + .build(|| { + ui.text("Model Information"); + ui.separator(); + ui.text(format!("count meshes: {}", self.Car.meshes.len())); + for i in 0..self.Car.meshes.len() + { + ui.text(format!("Mesh Number: {}",i )); + ui.text(format!("count vertices: {}", self.Car.meshes[i].vertices.len())); + ui.separator(); + } + }); + let draw_data = self.imgui.render(); + + self.imgui_rend.render(draw_data).unwrap(); } + } From a3eb4017cfd8ae5fce9bd38a33c46f729ed550cf Mon Sep 17 00:00:00 2001 From: Melik Houij Date: Mon, 20 Mar 2023 19:09:35 +0100 Subject: [PATCH 03/11] made some changes kinda forgor what they were tbh --- src/main.rs | 66 +++++++++++----------------------------------------- src/scene.rs | 33 ++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 56 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8da0da7..0c047fa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,10 @@ enum gameState { Playing } +enum SceneEnum { + Exit, + Resume +} use imgui_glow_renderer::AutoRenderer; use imgui_sdl2_support::SdlPlatform; @@ -40,6 +44,7 @@ use scene::Scene; fn main() { + // initialize SDL and gl let (gl, shader_version, window, mut events_loop, _context) = { let sdl = match sdl2::init() { @@ -82,37 +87,10 @@ fn main() { // NOTE intiialize Camera - let mut camera = camera::Camera { - Position: Point3::new(0.0, 0.40, 1.0), - Pitch: -20.0, - ..camera::Camera::default() - }; - // timing - let mut deltaTime: f32; // time between current frame and last frame - let mut lastFrame: f32 = 0.0; - - //gl::load_with(|ptr| window.get_proc_address(ptr) as *const _); - let (ourshader, ourModel) = unsafe { - gl.enable(glow::DEPTH_TEST); - - let ourShader = shader::shader::new("model", Arc::clone(&gl)); - - let ourModel = model::Model::new("resources/models/TestCarModel/CarW4.obj", Arc::clone(&gl)); - - (ourShader, ourModel) - }; - - let mut State = gameState::Playing; - let mut scene = Scene::new(gl.clone()); - - - let projection: Matrix4 = perspective(Deg(45.0), SCR_WIDTH as f32/ SCR_HEIGHT as f32, 0.1, 100.0); - - - + let mut scene = Scene::new(gl); println!("entering main loop"); @@ -126,35 +104,19 @@ fn main() { match &State { gameState::Playing => { - scene.update(&mut events_loop, &window); + match scene.update(&mut events_loop, &window) + { + scene::SceneEnum::Exit => { + break 'main; + }, + _ => (), + + } window.gl_swap_window(); - for event in events_loop.poll_iter() { - - match event { - Event::Quit {..} | - Event::KeyDown { keycode: Some(Keycode::Escape), .. } => { - break 'main - }, - Event::KeyDown {keycode: Some(Keycode::P), ..} => { - State = gameState::Paused; - } - _ => {} - } - } } gameState::Paused => { - - for event in events_loop.poll_iter() { - - match event { - Event::KeyDown {keycode: Some(Keycode::P), ..} => { - State = gameState::Playing; - } - _ => {} - } - } } } } diff --git a/src/scene.rs b/src/scene.rs index f9a2e5d..937413d 100644 --- a/src/scene.rs +++ b/src/scene.rs @@ -31,8 +31,14 @@ pub struct tempData { pub currentFrame: f32, pub deltaTime: f32, pub lastFrame: f32, + DebugMode: bool, } +pub enum SceneEnum { + Exit, + Pause, + Resume, +} pub struct Scene { @@ -68,7 +74,8 @@ impl Scene{ current_rad: 1.0, currentFrame: 0.0, deltaTime: 0.0, - lastFrame: 0.0 + lastFrame: 0.0, + DebugMode: false, }; @@ -98,7 +105,7 @@ impl Scene{ } } - pub fn update(&mut self ,events_loop: &mut sdl2::EventPump, window: &sdl2::video::Window) + pub fn update(&mut self ,events_loop: &mut sdl2::EventPump, window: &sdl2::video::Window) -> SceneEnum { self.tempData.currentFrame = self.time.elapsed().as_secs_f32(); self.tempData.deltaTime = self.tempData.currentFrame - self.tempData.lastFrame; @@ -123,13 +130,31 @@ impl Scene{ } self.Car.Draw(&self.shaders[0]); - self.drawImgui(&events_loop, &window); + if self.tempData.DebugMode{ + self.drawImgui(&events_loop, &window); + } - let quit = false; + let mut ret = SceneEnum::Resume; for event in events_loop.poll_iter() { + if self.tempData.DebugMode { self.imgui_plat.handle_event(&mut self.imgui, &event); + } + match event { + Event::Quit {..} | + Event::KeyDown { keycode: Some(Keycode::Escape), .. } => { + ret = SceneEnum::Exit; + }, + Event::KeyDown {keycode: Some(Keycode::P), ..} => { + }, + Event::KeyDown {keycode: Some(Keycode::D), ..} => { + self.tempData.DebugMode = !self.tempData.DebugMode + } + _ => {} + } } + + ret } From f4b4295df15d2ff9a320f445ab58f41012a46fc7 Mon Sep 17 00:00:00 2001 From: Melik Houij Date: Tue, 21 Mar 2023 14:14:15 +0100 Subject: [PATCH 04/11] added debug.rs and moved some code there --- src/debug.rs | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 1 + src/scene.rs | 62 ++++---------------------------------- 3 files changed, 92 insertions(+), 56 deletions(-) create mode 100644 src/debug.rs diff --git a/src/debug.rs b/src/debug.rs new file mode 100644 index 0000000..768e803 --- /dev/null +++ b/src/debug.rs @@ -0,0 +1,85 @@ + +use imgui_glow_renderer::AutoRenderer; +use imgui_sdl2_support::SdlPlatform; + +use sdl2::event::Event; +const MODELS: [&str; 3]= ["resources/models/TestCarModel/CarW4.obj", "resources/models/TestCarModel/CarW1.obj", +"resources/models/TestCarModel/CarW0.obj"]; + + +pub struct Debug { + imgui: imgui::Context, + renderer: AutoRenderer, + platform: SdlPlatform, +} + +impl Debug { + pub fn new(gl: std::sync::Arc) -> Debug + { + let mut imgui = imgui::Context::create(); + + imgui + .fonts() + .add_font(&[imgui::FontSource::DefaultFontData {config: None}]); + + let mut platform = SdlPlatform::init(&mut imgui); + let mut renderer = match AutoRenderer::initialize(gl.clone(), &mut imgui) + { + Ok(ret) => ret, + Err(s) => panic!("Failed to initialize Imgui Platform Renderer: {}", s), + }; + Debug { + imgui, + renderer, + platform + } + } + + pub fn handle(&mut self, event: &sdl2::event::Event) + { + self.platform.handle_event(&mut self.imgui, event); + } + + pub fn drawImgui(&mut self, events_loop: &sdl2::EventPump, window: &sdl2::video::Window, + tempData: &mut crate::scene::tempData, Car: &crate::model::Model) + { + self.platform.prepare_frame(&mut self.imgui, &window, &events_loop ); + let ui = self.imgui.new_frame(); + let mut hello = String::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 tempData.spinSpeed); + if ui + .button("Quit") { + hello = String::from("cannot quit from here"); + + } + ui.text(hello); + }); + + 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(); + + self.renderer.render(draw_data).unwrap(); + + } + +} diff --git a/src/main.rs b/src/main.rs index 0c047fa..2b51156 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,6 +39,7 @@ mod shader; mod model; mod camera; mod scene; +mod debug; use scene::Scene; diff --git a/src/scene.rs b/src/scene.rs index 937413d..fa1372f 100644 --- a/src/scene.rs +++ b/src/scene.rs @@ -22,7 +22,6 @@ const MODELS: [&str; 3]= ["resources/models/TestCarModel/CarW4.obj", "resources/ "resources/models/TestCarModel/CarW0.obj"]; - /// XXX this is temporary, thus the name pub struct tempData { pub projection: Matrix4, @@ -33,6 +32,7 @@ pub struct tempData { pub lastFrame: f32, DebugMode: bool, } +use crate::debug::Debug; pub enum SceneEnum { Exit, @@ -45,9 +45,7 @@ pub struct Scene { gl: Arc, pub Car: Model, camera: Camera, - imgui: imgui::Context, - imgui_rend: AutoRenderer, - imgui_plat: SdlPlatform, + debug: Debug, shaders: Vec>, time: std::time::Instant, tempData: tempData, @@ -79,26 +77,12 @@ impl Scene{ }; - let mut imgui = imgui::Context::create(); - - imgui - .fonts() - .add_font(&[imgui::FontSource::DefaultFontData {config: None}]); - - let mut platform = SdlPlatform::init(&mut imgui); - let mut renderer = match AutoRenderer::initialize(gl.clone(), &mut imgui) - { - Ok(ret) => ret, - Err(s) => panic!("Failed to initialize Imgui Platform Renderer: {}", s), - }; - + let debug = Debug::new(gl.clone()); Scene{ gl, Car, camera, - imgui, - imgui_rend: renderer, - imgui_plat: platform, + debug, shaders: vec![shader], time, tempData, @@ -131,13 +115,13 @@ impl Scene{ self.Car.Draw(&self.shaders[0]); if self.tempData.DebugMode{ - self.drawImgui(&events_loop, &window); + self.debug.drawImgui(&events_loop, &window, &mut self.tempData, &self.Car); } let mut ret = SceneEnum::Resume; for event in events_loop.poll_iter() { if self.tempData.DebugMode { - self.imgui_plat.handle_event(&mut self.imgui, &event); + self.debug.handle(&event); } match event { Event::Quit {..} | @@ -158,38 +142,4 @@ impl Scene{ } - fn drawImgui(&mut self, events_loop: &sdl2::EventPump, window: &sdl2::video::Window) - { - self.imgui_plat.prepare_frame(&mut self.imgui, &window, &events_loop ); - let ui = self.imgui.new_frame(); - - 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 self.tempData.spinSpeed); - }); - - ui.window("Stats") - .size([300.0,500.0], imgui::Condition::Always) - .build(|| { - ui.text("Model Information"); - ui.separator(); - ui.text(format!("count meshes: {}", self.Car.meshes.len())); - for i in 0..self.Car.meshes.len() - { - ui.text(format!("Mesh Number: {}",i )); - ui.text(format!("count vertices: {}", self.Car.meshes[i].vertices.len())); - ui.separator(); - } - }); - - - let draw_data = self.imgui.render(); - - self.imgui_rend.render(draw_data).unwrap(); - - } - } From aed0b606c2788087f1574b6c7007bd7283826bf7 Mon Sep 17 00:00:00 2001 From: Melik Houij Date: Tue, 21 Mar 2023 15:14:10 +0100 Subject: [PATCH 05/11] can change models now --- src/debug.rs | 27 +++++++++++++++++++++------ src/scene.rs | 15 +++++++++++++-- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/debug.rs b/src/debug.rs index 768e803..c7b3d75 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -7,12 +7,24 @@ const MODELS: [&str; 3]= ["resources/models/TestCarModel/CarW4.obj", "resources/ "resources/models/TestCarModel/CarW0.obj"]; + + +pub enum dEvent + { + loadModel(i32), + exit, + } + + pub struct Debug { imgui: imgui::Context, renderer: AutoRenderer, platform: SdlPlatform, + selectedModel: i32 } + + impl Debug { pub fn new(gl: std::sync::Arc) -> Debug { @@ -31,7 +43,8 @@ impl Debug { Debug { imgui, renderer, - platform + platform, + selectedModel: 0, } } @@ -41,11 +54,11 @@ impl Debug { } pub fn drawImgui(&mut self, events_loop: &sdl2::EventPump, window: &sdl2::video::Window, - tempData: &mut crate::scene::tempData, Car: &crate::model::Model) + tempData: &mut crate::scene::tempData, Car: &crate::model::Model) -> Vec { self.platform.prepare_frame(&mut self.imgui, &window, &events_loop ); let ui = self.imgui.new_frame(); - let mut hello = String::new(); + let mut ret = Vec::::new(); ui.window("POLY I WILL FUCKING") .size([500.0, 100.0], imgui::Condition::FirstUseEver) @@ -55,10 +68,11 @@ impl Debug { ui.slider("The Spin Speed", 0.1, 10.0, &mut tempData.spinSpeed); if ui .button("Quit") { - hello = String::from("cannot quit from here"); - + ret.push(dEvent::exit); } - ui.text(hello); + if ui.list_box("Select Model to Load", &mut self.selectedModel, &MODELS, 5) { + ret.push(dEvent::loadModel(self.selectedModel)); + } }); ui.window("Stats") @@ -80,6 +94,7 @@ impl Debug { self.renderer.render(draw_data).unwrap(); + ret } } diff --git a/src/scene.rs b/src/scene.rs index fa1372f..6c1c2fb 100644 --- a/src/scene.rs +++ b/src/scene.rs @@ -95,6 +95,7 @@ impl Scene{ self.tempData.deltaTime = self.tempData.currentFrame - self.tempData.lastFrame; self.tempData.lastFrame = self.tempData.currentFrame; self.tempData.current_rad += self.tempData.spinSpeed/15.0; + let mut ret = SceneEnum::Resume; unsafe { self.gl.enable(glow::DEPTH_TEST); @@ -115,10 +116,20 @@ impl Scene{ self.Car.Draw(&self.shaders[0]); if self.tempData.DebugMode{ - self.debug.drawImgui(&events_loop, &window, &mut self.tempData, &self.Car); + for command in self.debug.drawImgui(&events_loop, &window, &mut self.tempData, &self.Car) + { + use crate::debug::dEvent; + match command + { + dEvent::exit => ret = SceneEnum::Exit, + dEvent::loadModel(i) => { + self.Car = Model::new(MODELS[i as usize], Arc::clone(&self.gl)); + } + _ => (), + } + } } - let mut ret = SceneEnum::Resume; for event in events_loop.poll_iter() { if self.tempData.DebugMode { self.debug.handle(&event); From e5101f6c7d36385a642d6c00681db8c87727cb05 Mon Sep 17 00:00:00 2001 From: Melik Houij Date: Thu, 23 Mar 2023 12:17:21 +0100 Subject: [PATCH 06/11] 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 From ecdcf00b0f9b45b2a08a8d55792121ecd190de70 Mon Sep 17 00:00:00 2001 From: Melik Houij Date: Thu, 23 Mar 2023 12:37:29 +0100 Subject: [PATCH 07/11] i learned my lesson, i will be less lazy from now on --- src/debug.rs | 6 ++++-- src/scene.rs | 13 ++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/debug.rs b/src/debug.rs index 0b45bdd..38afaf0 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -25,8 +25,8 @@ pub enum Callback #[derive(Clone)] pub enum OpenWindows { + ModelInfo, TestWind, - ModelInfo } pub struct Debug { @@ -81,7 +81,9 @@ impl Debug { { match call { Callback::ModelInfo(a) => - Debug::displayModel(ui, &a), + { + Debug::displayModel(ui, &a) + }, Callback::TestWind(mut a) => ret = Debug::displayTest(ui, &mut a), } diff --git a/src/scene.rs b/src/scene.rs index d1bc121..2629b03 100644 --- a/src/scene.rs +++ b/src/scene.rs @@ -74,7 +74,7 @@ impl Scene{ currentFrame: 0.0, deltaTime: 0.0, lastFrame: 0.0, - DebugMode: false, + DebugMode: true, selectedModel: 0, }; @@ -117,20 +117,19 @@ impl Scene{ } self.Car.Draw(&self.shaders[0]); - if self.tempData.DebugMode{ let mut Callbacks = Vec::new(); let windows = self.debug.windows.clone(); - for i in 0..windows.len() + for window in windows { - - match &windows[i] { - ModelInfo => Callbacks.push(debug::ModelInfo(&self.Car)), - TestWind => Callbacks.push(debug::TestWind(self.tempData.spinSpeed, self.tempData.selectedModel)), + match window { + debug::OpenWindows::ModelInfo => Callbacks.push(debug::ModelInfo(&self.Car)), + debug::OpenWindows::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; From 0c39d1b1e480b846d4a5421af6baf582fb684c84 Mon Sep 17 00:00:00 2001 From: Melik Houij Date: Thu, 23 Mar 2023 13:50:51 +0100 Subject: [PATCH 08/11] as working as it was a few commits ago --- src/debug.rs | 10 +++++++--- src/scene.rs | 10 ++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/debug.rs b/src/debug.rs index 38afaf0..c46dcd9 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -101,20 +101,24 @@ impl Debug { fn displayTest(ui: &mut imgui::Ui, testI: &mut info::testI) -> Vec { let mut ret = Vec::new(); + let mut selectedModel = testI.selectedModel; + let mut spinSpeed = testI.spinSpeed; 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); + ui.slider("The Spin Speed", 0.1, 10.0, &mut 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)); + if ui.list_box("Select Model to Load", &mut selectedModel, &MODELS, 5) { + ret.push(dEvent::loadModel(selectedModel)); } }); + ret.push(dEvent::setTest(spinSpeed, selectedModel + )); ret } diff --git a/src/scene.rs b/src/scene.rs index 2629b03..6e72dd2 100644 --- a/src/scene.rs +++ b/src/scene.rs @@ -74,7 +74,7 @@ impl Scene{ currentFrame: 0.0, deltaTime: 0.0, lastFrame: 0.0, - DebugMode: true, + DebugMode: false, selectedModel: 0, }; @@ -136,10 +136,12 @@ impl Scene{ match command { dEvent::exit => ret = SceneEnum::Exit, - dEvent::loadModel(i) => { - self.Car = Model::new(MODELS[i as usize], Arc::clone(&self.gl)); + dEvent::loadModel(i) => self.Car = Model::new(MODELS[i as usize], Arc::clone(&self.gl)), + dEvent::setTest(a, b) => { + self.tempData.spinSpeed = a; + self.tempData.selectedModel = b; } - _ => (), + } } } From 542223ddd91ef5cf1dce875d7e5c546d4cdcec83 Mon Sep 17 00:00:00 2001 From: Melik Houij Date: Thu, 23 Mar 2023 16:21:05 +0100 Subject: [PATCH 09/11] can now add and remove windows --- src/debug.rs | 127 ++++++++++++++++++++++++++++++++------------------- src/scene.rs | 10 ++-- 2 files changed, 86 insertions(+), 51 deletions(-) diff --git a/src/debug.rs b/src/debug.rs index c46dcd9..8705e48 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -1,7 +1,7 @@ use imgui_glow_renderer::AutoRenderer; use imgui_sdl2_support::SdlPlatform; - +use std::collections::HashMap; use sdl2::event::Event; const MODELS: [&str; 3]= ["resources/models/TestCarModel/CarW4.obj", "resources/models/TestCarModel/CarW1.obj", "resources/models/TestCarModel/CarW0.obj"]; @@ -13,6 +13,8 @@ pub enum dEvent { loadModel(i32), setTest(f32, i32), + addWindow(OpenWindows), + removeWindow(OpenWindows), exit, } @@ -33,7 +35,9 @@ pub struct Debug { imgui: imgui::Context, renderer: AutoRenderer, platform: SdlPlatform, - pub windows: Vec, + pub windows: HashMap, + next_id: i16, + free_ids:Vec } @@ -53,11 +57,16 @@ impl Debug { Ok(ret) => ret, Err(s) => panic!("Failed to initialize Imgui Platform Renderer: {}", s), }; + + let mut windows = HashMap::new(); + windows.insert(0,OpenWindows::TestWind,); Debug { imgui, renderer, platform, - windows: vec![OpenWindows::TestWind, OpenWindows::ModelInfo], + windows, + next_id: 2, + free_ids: Vec::new(), } } @@ -65,16 +74,11 @@ 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, callback: Vec) -> Vec { - self.platform.prepare_frame(&mut self.imgui, &window, &events_loop ); + self.platform.prepare_frame(&mut self.imgui, &window, &events_loop); let ui = self.imgui.new_frame(); let mut ret = Vec::new(); for call in callback @@ -82,10 +86,10 @@ impl Debug { match call { Callback::ModelInfo(a) => { - Debug::displayModel(ui, &a) + ret.append(&mut Debug::displayModel(ui, &a)) }, Callback::TestWind(mut a) => - ret = Debug::displayTest(ui, &mut a), + ret.append(&mut Debug::displayTest(ui, &mut a)), } } @@ -97,47 +101,74 @@ impl Debug { ret } + pub fn addWindow(&mut self, window: OpenWindows) + { + if (self.free_ids.is_empty()) + { + self.windows.insert(self.next_id, window); + } + else { + self.windows.insert(self.free_ids.pop().unwrap(), window); + } + } + pub fn removeWindow(&mut self, window: OpenWindows) + { + println!("searching for a match..."); + let mut id = 0; + for (hashId, windowType) in &self.windows + { + if let _window = windowType {id = *hashId; println!("found a match!")}; + + } + self.windows.remove(&id); + self.free_ids.push(id); + } fn displayTest(ui: &mut imgui::Ui, testI: &mut info::testI) -> Vec - { - let mut ret = Vec::new(); - let mut selectedModel = testI.selectedModel; - let mut spinSpeed = testI.spinSpeed; - 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 spinSpeed); - if ui - .button("Quit") { - ret.push(dEvent::exit); - } - if ui.list_box("Select Model to Load", &mut selectedModel, &MODELS, 5) { - ret.push(dEvent::loadModel(selectedModel)); + { + let mut ret = Vec::new(); + let mut selectedModel = testI.selectedModel; + let mut spinSpeed = testI.spinSpeed; + 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 spinSpeed); + if ui + .button("Quit") { + ret.push(dEvent::exit); } - }); - ret.push(dEvent::setTest(spinSpeed, selectedModel - )); - ret - } + if ui.list_box("Select Model to Load", &mut selectedModel, &MODELS, 5) { + ret.push(dEvent::loadModel(selectedModel)); + } + }); + ret.push(dEvent::setTest(spinSpeed, 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(); - } - }); - } + fn displayModel(ui: &mut imgui::Ui ,model: &info::ModelI) -> Vec + { + let mut ret = Vec::new(); + 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(); + } + if ui.button("close") { + ret.push(dEvent::removeWindow(OpenWindows::ModelInfo)) + } + }); + ret + } } diff --git a/src/scene.rs b/src/scene.rs index 6e72dd2..4e9a55f 100644 --- a/src/scene.rs +++ b/src/scene.rs @@ -120,7 +120,7 @@ impl Scene{ if self.tempData.DebugMode{ let mut Callbacks = Vec::new(); let windows = self.debug.windows.clone(); - for window in windows + for (id, window) in windows { match window { debug::OpenWindows::ModelInfo => Callbacks.push(debug::ModelInfo(&self.Car)), @@ -140,8 +140,9 @@ impl Scene{ dEvent::setTest(a, b) => { self.tempData.spinSpeed = a; self.tempData.selectedModel = b; - } - + }, + dEvent::addWindow(a) => self.debug.addWindow(a), + dEvent::removeWindow(a) => self.debug.removeWindow(a), } } } @@ -159,6 +160,9 @@ impl Scene{ }, Event::KeyDown {keycode: Some(Keycode::D), ..} => { self.tempData.DebugMode = !self.tempData.DebugMode + } + Event::KeyDown {keycode: Some(Keycode::M), ..} => { + self.debug.addWindow(debug::OpenWindows::ModelInfo) } _ => {} } From 81be82d0c6dab3f64a4ae32a91e5d0060f0d3009 Mon Sep 17 00:00:00 2001 From: Melik Houij Date: Thu, 23 Mar 2023 20:37:32 +0100 Subject: [PATCH 10/11] more work --- src/debug.rs | 59 ++++++++++++++++++++++++++++++++++++++++------------ src/scene.rs | 1 + 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/src/debug.rs b/src/debug.rs index 8705e48..ef1d5db 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -23,21 +23,23 @@ pub enum Callback { ModelInfo(info::ModelI), TestWind(info::testI), + MainMenu, } #[derive(Clone)] pub enum OpenWindows { - ModelInfo, - TestWind, + ModelInfo, + TestWind, + MainMenu, } pub struct Debug { imgui: imgui::Context, renderer: AutoRenderer, platform: SdlPlatform, - pub windows: HashMap, - next_id: i16, - free_ids:Vec + pub windows: HashMap, + next_id: u16, + free_ids:Vec } @@ -59,13 +61,13 @@ impl Debug { }; let mut windows = HashMap::new(); - windows.insert(0,OpenWindows::TestWind,); + windows.insert(0,OpenWindows::MainMenu,); Debug { imgui, renderer, platform, windows, - next_id: 2, + next_id: 1, free_ids: Vec::new(), } } @@ -85,12 +87,13 @@ impl Debug { { match call { Callback::ModelInfo(a) => - { - ret.append(&mut Debug::displayModel(ui, &a)) - }, + ret.append(&mut Debug::displayModel(ui, &a)), Callback::TestWind(mut a) => ret.append(&mut Debug::displayTest(ui, &mut a)), + Callback::MainMenu => + ret.append(&mut Debug::displayMain(ui)), } + } @@ -106,6 +109,7 @@ impl Debug { if (self.free_ids.is_empty()) { self.windows.insert(self.next_id, window); + self.next_id += 1; } else { self.windows.insert(self.free_ids.pop().unwrap(), window); @@ -118,6 +122,11 @@ impl Debug { for (hashId, windowType) in &self.windows { if let _window = windowType {id = *hashId; println!("found a match!")}; + match windowType + { + window => id = *hashId, + _ => () + } } self.windows.remove(&id); @@ -136,8 +145,8 @@ impl Debug { ui.text("Your Purpose in life is to suck my dick"); ui.slider("The Spin Speed", 0.1, 10.0, &mut spinSpeed); if ui - .button("Quit") { - ret.push(dEvent::exit); + .button("Close") { + ret.push(dEvent::removeWindow(OpenWindows::TestWind)); } if ui.list_box("Select Model to Load", &mut selectedModel, &MODELS, 5) { ret.push(dEvent::loadModel(selectedModel)); @@ -170,7 +179,31 @@ impl Debug { ret } -} + fn displayMain(ui: &mut imgui::Ui) -> Vec + { + let mut ret = Vec::new(); + ui.window("Welcome to the main Menu") + .size([500.0, 500.0], imgui::Condition::Always) + .build(|| { + ui.text("this is the main Debugger Menu, it's used to Debug the game"); + ui.text("although it isn't done yet"); + ui.separator(); + if ui.button("Open the Model Info") { + ret.push(dEvent::addWindow(OpenWindows::ModelInfo)) + } + if ui.button("Open the Test Modifier"){ + ret.push(dEvent::addWindow(OpenWindows::TestWind)) + } + if ui.button("Quit") { + ret.push(dEvent::exit) + } + + }); + ret + } + + + } diff --git a/src/scene.rs b/src/scene.rs index 4e9a55f..1313a5f 100644 --- a/src/scene.rs +++ b/src/scene.rs @@ -125,6 +125,7 @@ impl Scene{ match window { debug::OpenWindows::ModelInfo => Callbacks.push(debug::ModelInfo(&self.Car)), debug::OpenWindows::TestWind => Callbacks.push(debug::TestWind(self.tempData.spinSpeed, self.tempData.selectedModel)), + debug::OpenWindows::MainMenu => Callbacks.push(debug::Callback::MainMenu), } } From bd90426dc6430df92c3e697d9e6226d9d5f57e8d Mon Sep 17 00:00:00 2001 From: Melik Houij Date: Fri, 24 Mar 2023 08:47:49 +0100 Subject: [PATCH 11/11] fixed --- src/debug.rs | 21 +++++++++++---------- src/main.rs | 2 -- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/debug.rs b/src/debug.rs index ef1d5db..ac29990 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -26,7 +26,7 @@ pub enum Callback MainMenu, } -#[derive(Clone)] +#[derive(Clone, PartialEq)] pub enum OpenWindows { ModelInfo, TestWind, @@ -121,16 +121,17 @@ impl Debug { let mut id = 0; for (hashId, windowType) in &self.windows { - if let _window = windowType {id = *hashId; println!("found a match!")}; - match windowType - { - window => id = *hashId, - _ => () - } - + if *windowType == window { + id = *hashId; + break; } - self.windows.remove(&id); - self.free_ids.push(id); + + } + if id !=0 + { + self.windows.remove(&id); + self.free_ids.push(id); + } } fn displayTest(ui: &mut imgui::Ui, testI: &mut info::testI) -> Vec diff --git a/src/main.rs b/src/main.rs index 2b51156..85a9ced 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,8 +28,6 @@ use sdl2::pixels::Color; use sdl2::keyboard::Keycode; use sdl2::event::Event; -use std::sync::mpsc::Receiver; -use std::ptr; use std::mem; use std::os::raw::c_void; use std::path::Path;