Working on letting debug interact with scene while being a seperate
module currently buggy and for some reason debug only returns modelpull/3/head
parent
aed0b606c2
commit
e5101f6c7d
126
src/debug.rs
126
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",
|
const MODELS: [&str; 3]= ["resources/models/TestCarModel/CarW4.obj", "resources/models/TestCarModel/CarW1.obj",
|
||||||
"resources/models/TestCarModel/CarW0.obj"];
|
"resources/models/TestCarModel/CarW0.obj"];
|
||||||
|
|
||||||
|
mod info;
|
||||||
|
|
||||||
|
|
||||||
pub enum dEvent
|
pub enum dEvent
|
||||||
{
|
{
|
||||||
loadModel(i32),
|
loadModel(i32),
|
||||||
|
setTest(f32, i32),
|
||||||
exit,
|
exit,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub enum Callback
|
||||||
|
{
|
||||||
|
ModelInfo(info::ModelI),
|
||||||
|
TestWind(info::testI),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub enum OpenWindows {
|
||||||
|
TestWind,
|
||||||
|
ModelInfo
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Debug {
|
pub struct Debug {
|
||||||
imgui: imgui::Context,
|
imgui: imgui::Context,
|
||||||
renderer: AutoRenderer,
|
renderer: AutoRenderer,
|
||||||
platform: SdlPlatform,
|
platform: SdlPlatform,
|
||||||
selectedModel: i32
|
pub windows: Vec<OpenWindows>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,7 +57,7 @@ impl Debug {
|
||||||
imgui,
|
imgui,
|
||||||
renderer,
|
renderer,
|
||||||
platform,
|
platform,
|
||||||
selectedModel: 0,
|
windows: vec![OpenWindows::TestWind, OpenWindows::ModelInfo],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,42 +65,28 @@ impl Debug {
|
||||||
{
|
{
|
||||||
self.platform.handle_event(&mut self.imgui, event);
|
self.platform.handle_event(&mut self.imgui, event);
|
||||||
}
|
}
|
||||||
|
pub fn windows(self) -> Vec<OpenWindows>
|
||||||
|
{
|
||||||
|
let ret = self.windows.clone();
|
||||||
|
ret
|
||||||
|
}
|
||||||
|
|
||||||
pub fn drawImgui(&mut self, events_loop: &sdl2::EventPump, window: &sdl2::video::Window,
|
pub fn drawImgui(&mut self, events_loop: &sdl2::EventPump, window: &sdl2::video::Window,
|
||||||
tempData: &mut crate::scene::tempData, Car: &crate::model::Model) -> Vec<dEvent>
|
callback: Vec<Callback>) -> Vec<dEvent>
|
||||||
{
|
{
|
||||||
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 ui = self.imgui.new_frame();
|
||||||
let mut ret = Vec::<dEvent>::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();
|
let draw_data = self.imgui.render();
|
||||||
|
@ -97,4 +96,65 @@ impl Debug {
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn displayTest(ui: &mut imgui::Ui, testI: &mut info::testI) -> Vec<dEvent>
|
||||||
|
{
|
||||||
|
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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
|
||||||
|
pub struct ModelI
|
||||||
|
{
|
||||||
|
pub meshesCount: usize,
|
||||||
|
pub vertCount: Vec<usize>
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct testI
|
||||||
|
{
|
||||||
|
pub spinSpeed: f32,
|
||||||
|
pub selectedModel: i32,
|
||||||
|
}
|
19
src/scene.rs
19
src/scene.rs
|
@ -8,7 +8,7 @@ use glow::*;
|
||||||
|
|
||||||
use imgui_glow_renderer::AutoRenderer;
|
use imgui_glow_renderer::AutoRenderer;
|
||||||
use imgui_sdl2_support::SdlPlatform;
|
use imgui_sdl2_support::SdlPlatform;
|
||||||
|
use crate::debug;
|
||||||
use cgmath::{Matrix4, vec3, Point3, Deg, perspective};
|
use cgmath::{Matrix4, vec3, Point3, Deg, perspective};
|
||||||
use cgmath::prelude::*;
|
use cgmath::prelude::*;
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ pub struct tempData {
|
||||||
pub deltaTime: f32,
|
pub deltaTime: f32,
|
||||||
pub lastFrame: f32,
|
pub lastFrame: f32,
|
||||||
DebugMode: bool,
|
DebugMode: bool,
|
||||||
|
selectedModel: i32
|
||||||
}
|
}
|
||||||
use crate::debug::Debug;
|
use crate::debug::Debug;
|
||||||
|
|
||||||
|
@ -74,6 +75,7 @@ impl Scene{
|
||||||
deltaTime: 0.0,
|
deltaTime: 0.0,
|
||||||
lastFrame: 0.0,
|
lastFrame: 0.0,
|
||||||
DebugMode: false,
|
DebugMode: false,
|
||||||
|
selectedModel: 0,
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -115,8 +117,21 @@ impl Scene{
|
||||||
}
|
}
|
||||||
self.Car.Draw(&self.shaders[0]);
|
self.Car.Draw(&self.shaders[0]);
|
||||||
|
|
||||||
|
|
||||||
if self.tempData.DebugMode{
|
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;
|
use crate::debug::dEvent;
|
||||||
match command
|
match command
|
||||||
|
|
Loading…
Reference in New Issue