|
|
@ -31,6 +31,8 @@ use crate::imgui_supp::imgui_support::{ImguiContext, ImguiPlatform};
|
|
|
|
use crate::light::{DirectionalLight, LightRaw};
|
|
|
|
use crate::light::{DirectionalLight, LightRaw};
|
|
|
|
use crate::render::state::{RenderState};
|
|
|
|
use crate::render::state::{RenderState};
|
|
|
|
use crate::render::{push_debug_group_checked, insert_debug_marker_checked, pop_debug_group_checked, EntityUniforms};
|
|
|
|
use crate::render::{push_debug_group_checked, insert_debug_marker_checked, pop_debug_group_checked, EntityUniforms};
|
|
|
|
|
|
|
|
use std::iter::Chain;
|
|
|
|
|
|
|
|
use std::slice::Iter;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[system]
|
|
|
|
#[system]
|
|
|
@ -55,13 +57,13 @@ pub fn imgui_prepare(
|
|
|
|
|
|
|
|
|
|
|
|
/// Go through each "global" window-data component and render it's data
|
|
|
|
/// Go through each "global" window-data component and render it's data
|
|
|
|
#[system]
|
|
|
|
#[system]
|
|
|
|
#[write_component(ImguiWindow<ImguiPerformanceProfiler>)]
|
|
|
|
#[write_component(ImguiWindow<ImguiPerformanceProfilerLine>)]
|
|
|
|
#[write_component(ImguiPerformanceProfiler)]
|
|
|
|
#[write_component(ImguiPerformanceProfilerLine)]
|
|
|
|
pub fn render_imgui(world: &mut SubWorld, #[resource] loop_state: &mut LoopState) {
|
|
|
|
pub fn render_imgui(world: &mut SubWorld, #[resource] loop_state: &mut LoopState) {
|
|
|
|
|
|
|
|
|
|
|
|
let ui = unsafe { crate::current_ui().unwrap() };
|
|
|
|
let ui = unsafe { crate::current_ui().unwrap() };
|
|
|
|
|
|
|
|
|
|
|
|
let mut query = <(&ImguiPerformanceProfiler, &mut ImguiWindow<ImguiPerformanceProfiler>)>::query();
|
|
|
|
let mut query = <(&ImguiPerformanceProfilerLine, &mut ImguiWindow<ImguiPerformanceProfilerLine>)>::query();
|
|
|
|
for (state, mut window) in query.iter_mut(world) {
|
|
|
|
for (state, mut window) in query.iter_mut(world) {
|
|
|
|
let new_window = (window.window)();
|
|
|
|
let new_window = (window.window)();
|
|
|
|
new_window.build(&ui, || { (window.func)(ui, state) });
|
|
|
|
new_window.build(&ui, || { (window.func)(ui, state) });
|
|
|
@ -71,17 +73,56 @@ pub fn render_imgui(world: &mut SubWorld, #[resource] loop_state: &mut LoopState
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// This would be the shared state for all imgui performance window things
|
|
|
|
// This would be the shared state for all imgui performance window things
|
|
|
|
pub struct ImguiPerformanceProfiler {
|
|
|
|
pub struct ImguiPerformanceProfilerLine {
|
|
|
|
pub top_text: String,
|
|
|
|
pub label: String,
|
|
|
|
pub list_of_fps: [f32; 400],
|
|
|
|
list_of_fps: [f32; 400],
|
|
|
|
pub index: usize
|
|
|
|
index: usize,
|
|
|
|
|
|
|
|
scale_min: f32,
|
|
|
|
|
|
|
|
pub scale_max: f32,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl ImguiPerformanceProfilerLine {
|
|
|
|
|
|
|
|
fn add_sample(&mut self, sample: f32) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.list_of_fps[self.index] = sample;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.index >= 399 {
|
|
|
|
|
|
|
|
self.scale_max = self.list_of_fps.iter().cloned().fold(0./0., f32::max);
|
|
|
|
|
|
|
|
self.index = 0;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
self.index += 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if self.scale_max < sample {
|
|
|
|
|
|
|
|
self.scale_max = sample;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn iter_data_from_head(&self) -> Chain<Iter<f32>, Iter<f32>> {
|
|
|
|
|
|
|
|
let (left, right) = self.list_of_fps.split_at(self.index);
|
|
|
|
|
|
|
|
right.iter().chain(left.iter())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn current_average_label(&self) -> (f32, String) {
|
|
|
|
|
|
|
|
let (left, right) = self.list_of_fps.split_at(self.index);
|
|
|
|
|
|
|
|
((left.iter().rev().chain(right.iter().rev()).take(50).sum::<f32>() / 50.0), "FPS".to_string())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn new(label: String) -> ImguiPerformanceProfilerLine {
|
|
|
|
|
|
|
|
ImguiPerformanceProfilerLine {
|
|
|
|
|
|
|
|
label,
|
|
|
|
|
|
|
|
list_of_fps: [0.0; 400],
|
|
|
|
|
|
|
|
index: 0,
|
|
|
|
|
|
|
|
scale_min: 0.0,
|
|
|
|
|
|
|
|
scale_max: 0.0
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[system]
|
|
|
|
#[system]
|
|
|
|
#[write_component(Camera)]
|
|
|
|
#[write_component(Camera)]
|
|
|
|
#[write_component(Position)]
|
|
|
|
#[write_component(Position)]
|
|
|
|
#[write_component(ImguiPerformanceProfiler)]
|
|
|
|
#[write_component(ImguiPerformanceProfilerLine)]
|
|
|
|
#[write_component(Point3<f32>)]
|
|
|
|
#[write_component(Point3<f32>)]
|
|
|
|
#[write_component(Mesh)]
|
|
|
|
#[write_component(Mesh)]
|
|
|
|
#[write_component(DirectionalLight)]
|
|
|
|
#[write_component(DirectionalLight)]
|
|
|
@ -94,21 +135,10 @@ pub fn render_test(
|
|
|
|
#[resource] imgui_platform: &mut Arc<Mutex<ImguiPlatform>>,
|
|
|
|
#[resource] imgui_platform: &mut Arc<Mutex<ImguiPlatform>>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
|
|
|
|
|
|
|
|
let mut query = <(&mut ImguiPerformanceProfiler)>::query();
|
|
|
|
let mut query = <(&mut ImguiPerformanceProfilerLine)>::query();
|
|
|
|
for (mut profiler) in query.iter_mut(world) {
|
|
|
|
for (mut profiler) in query.iter_mut(world) {
|
|
|
|
let delta_time = loop_state.delta_time.as_secs_f32();
|
|
|
|
let delta_time = loop_state.delta_time.as_secs_f32();
|
|
|
|
let profiler :&mut ImguiPerformanceProfiler = profiler; // trick clion into giving me the type, ugh
|
|
|
|
profiler.add_sample(delta_time);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
profiler.top_text = (profiler.list_of_fps.iter().sum::<f32>() / profiler.list_of_fps.len() as f32).to_string();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
profiler.list_of_fps[profiler.index] = 1.0 / delta_time;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if profiler.index >= 399 {
|
|
|
|
|
|
|
|
profiler.index = 0;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
profiler.index += 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let mut encoder = renderer
|
|
|
|
let mut encoder = renderer
|
|
|
|