|
|
@ -22,7 +22,7 @@ use crate::components::{Collider, ImguiWindow, LoopState, Mesh, Physics, Positio
|
|
|
|
use crate::geometry::RawMesh;
|
|
|
|
use crate::geometry::RawMesh;
|
|
|
|
use crate::physics::state::PhysicsState;
|
|
|
|
use crate::physics::state::PhysicsState;
|
|
|
|
use crate::render::state::RenderState;
|
|
|
|
use crate::render::state::RenderState;
|
|
|
|
use crate::render::system::ImguiPerformanceProfilerLine;
|
|
|
|
use crate::render::system::{ImguiGenericOutputLine, ImguiPerformanceProfilerLine};
|
|
|
|
use crate::runtime::state::RuntimeState;
|
|
|
|
use crate::runtime::state::RuntimeState;
|
|
|
|
|
|
|
|
|
|
|
|
pub fn quad_color(color: [f32; 4]) -> [[f32; 4]; 4] {
|
|
|
|
pub fn quad_color(color: [f32; 4]) -> [[f32; 4]; 4] {
|
|
|
@ -38,35 +38,38 @@ pub fn runtime_load(
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
runtime_state.preload_meshes(PathBuf::from("./resources"));
|
|
|
|
runtime_state.preload_meshes(PathBuf::from("./resources"));
|
|
|
|
|
|
|
|
|
|
|
|
let entity: Entity = cmd.push((
|
|
|
|
let entity: Entity = cmd.push((ImguiWindow {
|
|
|
|
ImguiWindow {
|
|
|
|
// a window that does everything for the performance profiler
|
|
|
|
// a window that does everything for the performance profiler
|
|
|
|
window: || {
|
|
|
|
window: || {
|
|
|
|
imgui::Window::new(im_str!("Performance Profiler"))
|
|
|
|
imgui::Window::new(im_str!("Performance Profiler"))
|
|
|
|
.size([400.0, 200.0], Condition::FirstUseEver)
|
|
|
|
.size([400.0, 500.0], Condition::FirstUseEver)
|
|
|
|
.position([10.0, 10.0], Condition::FirstUseEver)
|
|
|
|
.position([50.0, 50.0], Condition::FirstUseEver)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
func: |ui: &Ui, a: Vec<&ImguiPerformanceProfilerLine>| {
|
|
|
|
func: |ui: &Ui, a: &ImguiPerformanceProfilerLine| {
|
|
|
|
// ui.text(im_str!("Performance Graph"));
|
|
|
|
ui.text(im_str!("Performance Graph"));
|
|
|
|
|
|
|
|
|
|
|
|
let draw_list = ui.get_window_draw_list();
|
|
|
|
let draw_list = ui.get_window_draw_list();
|
|
|
|
let top_left = ui.cursor_screen_pos();
|
|
|
|
let top_left = ui.cursor_screen_pos();
|
|
|
|
let region_size = ui.content_region_avail();
|
|
|
|
let region_size = ui.content_region_avail();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Fill rect
|
|
|
|
|
|
|
|
let qcolor = quad_color([0.5, 0.5, 1.0, 0.1]);
|
|
|
|
|
|
|
|
draw_list.add_rect_filled_multicolor(
|
|
|
|
|
|
|
|
top_left,
|
|
|
|
|
|
|
|
[top_left[0] + (region_size[0] - region_size[0]/5.0), top_left[1] + region_size[1]],
|
|
|
|
|
|
|
|
qcolor[0],
|
|
|
|
|
|
|
|
qcolor[1],
|
|
|
|
|
|
|
|
qcolor[2],
|
|
|
|
|
|
|
|
qcolor[3],
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let x_scale = (region_size[0] - region_size[0]/5.0) / 400.0;
|
|
|
|
let region_size = [region_size[0] * 0.80, region_size[1]];
|
|
|
|
let y_scale = region_size[1] / a.scale_max;
|
|
|
|
|
|
|
|
a.iter_data_from_head()
|
|
|
|
// Fill rect
|
|
|
|
|
|
|
|
let qcolor = quad_color([0.5, 0.5, 1.0, 0.1]);
|
|
|
|
|
|
|
|
draw_list.add_rect_filled_multicolor(
|
|
|
|
|
|
|
|
top_left,
|
|
|
|
|
|
|
|
[top_left[0] + (region_size[0]), top_left[1] + region_size[1]],
|
|
|
|
|
|
|
|
qcolor[0],
|
|
|
|
|
|
|
|
qcolor[1],
|
|
|
|
|
|
|
|
qcolor[2],
|
|
|
|
|
|
|
|
qcolor[3],
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for profiler_line in a {
|
|
|
|
|
|
|
|
let x_scale = (region_size[0]) / 400.0;
|
|
|
|
|
|
|
|
let y_scale = region_size[1] / profiler_line.scale_max;
|
|
|
|
|
|
|
|
profiler_line
|
|
|
|
|
|
|
|
.iter_data_from_head()
|
|
|
|
.fold((0, 0.0f32), |accum, &fps_val| {
|
|
|
|
.fold((0, 0.0f32), |accum, &fps_val| {
|
|
|
|
let x1 = accum.0 as f32 * x_scale + top_left[0];
|
|
|
|
let x1 = accum.0 as f32 * x_scale + top_left[0];
|
|
|
|
let y1 = top_left[1] + region_size[1] - accum.1 * y_scale;
|
|
|
|
let y1 = top_left[1] + region_size[1] - accum.1 * y_scale;
|
|
|
@ -75,19 +78,42 @@ pub fn runtime_load(
|
|
|
|
let p1 = [x1, y1];
|
|
|
|
let p1 = [x1, y1];
|
|
|
|
let p2 = [x2, y2];
|
|
|
|
let p2 = [x2, y2];
|
|
|
|
draw_list
|
|
|
|
draw_list
|
|
|
|
.add_line(p1, p2, [1.0, 1.0, 0.0])
|
|
|
|
.add_line(p1, p2, [1.0, 1.0, 0.0, 0.8])
|
|
|
|
.thickness(1.0)
|
|
|
|
.thickness(1.0)
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
(accum.0 + 1, fps_val)
|
|
|
|
(accum.0 + 1, fps_val)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
let text_x = (region_size[0] - region_size[0]/5.0 + 75.0);
|
|
|
|
let text_x = (region_size[0] + top_left[0]);
|
|
|
|
let text_y = top_left[1] + region_size[1] - a.current_average_label().0 * y_scale;
|
|
|
|
let text_y = top_left[1] + region_size[1]
|
|
|
|
draw_list.add_text([text_x, text_y], [1.0,1.0,0.0,1.0], format!("{} {:.0}",a.current_average_label().1, 1.0/a.current_average_label().0));
|
|
|
|
- profiler_line.current_average_label().0 * y_scale;
|
|
|
|
},
|
|
|
|
draw_list.add_text(
|
|
|
|
|
|
|
|
[text_x, text_y],
|
|
|
|
|
|
|
|
[1.0, 1.0, 0.0, 1.0],
|
|
|
|
|
|
|
|
format!(
|
|
|
|
|
|
|
|
"{} {:.0}",
|
|
|
|
|
|
|
|
profiler_line.current_average_label().1,
|
|
|
|
|
|
|
|
1.0 / profiler_line.current_average_label().0
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},));
|
|
|
|
|
|
|
|
let entity: Entity = cmd.push((ImguiPerformanceProfilerLine::new("RenderFPS".to_string()),));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let entity: Entity = cmd.push((ImguiWindow {
|
|
|
|
|
|
|
|
// a window that does everything for the performance profiler
|
|
|
|
|
|
|
|
window: || {
|
|
|
|
|
|
|
|
imgui::Window::new(im_str!("Generic Output"))
|
|
|
|
|
|
|
|
.size([400.0, 500.0], Condition::FirstUseEver)
|
|
|
|
|
|
|
|
.position([50.0, 250.0], Condition::FirstUseEver)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
func: |ui: &Ui, a: Vec<&ImguiGenericOutputLine>| {
|
|
|
|
|
|
|
|
for label in a {
|
|
|
|
|
|
|
|
ui.text(im_str!("{}", label.label));
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ImguiPerformanceProfilerLine::new("RenderFFS".to_string()),
|
|
|
|
},));
|
|
|
|
));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[system]
|
|
|
|
#[system]
|
|
|
@ -149,6 +175,7 @@ pub fn runtime_spawn(
|
|
|
|
collider: collider,
|
|
|
|
collider: collider,
|
|
|
|
collider_handle: None,
|
|
|
|
collider_handle: None,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
ImguiGenericOutputLine::new("wahoo! from a physics entity".to_string()),
|
|
|
|
));
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"Terrain" => {
|
|
|
|
"Terrain" => {
|
|
|
@ -214,6 +241,7 @@ pub fn runtime_spawn(
|
|
|
|
pitch: Rad(PI / 2.0 + 25.0),
|
|
|
|
pitch: Rad(PI / 2.0 + 25.0),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
CameraController::new(5.0, 1.0),
|
|
|
|
CameraController::new(5.0, 1.0),
|
|
|
|
|
|
|
|
ImguiGenericOutputLine::new("wahoo! from a camera".to_string()),
|
|
|
|
));
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"Light" => {
|
|
|
|
"Light" => {
|
|
|
|