diff --git a/src/debug.rs b/src/debug.rs index ac29990..f7a4f53 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -106,6 +106,17 @@ impl Debug { } pub fn addWindow(&mut self, window: OpenWindows) { + let mut found = false; + for (hashId, windowType) in &self.windows + { + if *windowType == window + { + found = true; + break; + } + } + if (!found) + { if (self.free_ids.is_empty()) { self.windows.insert(self.next_id, window); @@ -114,6 +125,7 @@ impl Debug { else { self.windows.insert(self.free_ids.pop().unwrap(), window); } + } } pub fn removeWindow(&mut self, window: OpenWindows) { diff --git a/src/main.rs b/src/main.rs index 85a9ced..5f33f71 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,6 @@ use cgmath::prelude::*; use std::sync::Arc; const SCR_WIDTH: u32 = 1600; const SCR_HEIGHT: u32 = 900; -const TITLE: &str = "GLFWtest"; enum gameState { Paused, diff --git a/src/scene.rs b/src/scene.rs index 1313a5f..0138821 100644 --- a/src/scene.rs +++ b/src/scene.rs @@ -118,35 +118,8 @@ impl Scene{ self.Car.Draw(&self.shaders[0]); if self.tempData.DebugMode{ - let mut Callbacks = Vec::new(); - let windows = self.debug.windows.clone(); - for (id, window) in windows - { - 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), - - } - } - - - for command in self.debug.drawImgui(&events_loop, &window, Callbacks) - { - 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)), - 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), - } - } - } + self.handleDebug(events_loop, window, &mut ret) + } for event in events_loop.poll_iter() { if self.tempData.DebugMode { @@ -173,5 +146,38 @@ impl Scene{ ret } + fn handleDebug(&mut self, events_loop:&mut sdl2::EventPump, window: &sdl2::video::Window, ret: &mut SceneEnum) + { + let mut Callbacks = Vec::new(); + let windows = self.debug.windows.clone(); + for (id, window) in windows + { + 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), + + } + } + + + for command in self.debug.drawImgui(&events_loop, &window, Callbacks) + { + 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)), + 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), + } + } + + } + }