|
|
|
@ -3,7 +3,8 @@ use std::path::PathBuf;
|
|
|
|
|
use std::time::Instant;
|
|
|
|
|
|
|
|
|
|
use cgmath::{Deg, Euler, Point3, Quaternion, Rad};
|
|
|
|
|
use imgui::FontSource;
|
|
|
|
|
use imgui::*;
|
|
|
|
|
use imgui::{Condition, FontSource, Ui};
|
|
|
|
|
use legion::systems::CommandBuffer;
|
|
|
|
|
use legion::world::SubWorld;
|
|
|
|
|
use legion::IntoQuery;
|
|
|
|
@ -17,16 +18,76 @@ use rapier3d::na::{Isometry3, Vector, Vector3};
|
|
|
|
|
use rapier3d::pipeline::{ChannelEventCollector, PhysicsPipeline};
|
|
|
|
|
|
|
|
|
|
use crate::camera::{Camera, CameraController};
|
|
|
|
|
use crate::components::{Collider, LoopState, Mesh, Physics, Position};
|
|
|
|
|
use crate::components::{Collider, ImguiWindow, LoopState, Mesh, Physics, Position};
|
|
|
|
|
use crate::geometry::RawMesh;
|
|
|
|
|
use crate::physics::state::PhysicsState;
|
|
|
|
|
use crate::render::state::RenderState;
|
|
|
|
|
use crate::render::system::ImguiPerformanceProfilerLine;
|
|
|
|
|
use crate::runtime::state::RuntimeState;
|
|
|
|
|
|
|
|
|
|
pub fn quad_color(color: [f32; 4]) -> [[f32; 4]; 4] {
|
|
|
|
|
[color, color, color, color]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[system]
|
|
|
|
|
#[write_component(Mesh)]
|
|
|
|
|
pub fn runtime_load(world: &mut SubWorld, #[resource] runtime_state: &mut RuntimeState) {
|
|
|
|
|
pub fn runtime_load(
|
|
|
|
|
cmd: &mut CommandBuffer,
|
|
|
|
|
world: &mut SubWorld,
|
|
|
|
|
#[resource] runtime_state: &mut RuntimeState,
|
|
|
|
|
) {
|
|
|
|
|
runtime_state.preload_meshes(PathBuf::from("./resources"));
|
|
|
|
|
|
|
|
|
|
let entity: Entity = cmd.push((
|
|
|
|
|
ImguiWindow {
|
|
|
|
|
// a window that does everything for the performance profiler
|
|
|
|
|
window: || {
|
|
|
|
|
imgui::Window::new(im_str!("Performance Profiler"))
|
|
|
|
|
.size([400.0, 500.0], Condition::FirstUseEver)
|
|
|
|
|
.position([50.0, 50.0], Condition::FirstUseEver)
|
|
|
|
|
},
|
|
|
|
|
func: |ui: &Ui, a: &ImguiPerformanceProfilerLine| {
|
|
|
|
|
ui.text(im_str!("Performance Graph"));
|
|
|
|
|
|
|
|
|
|
let draw_list = ui.get_window_draw_list();
|
|
|
|
|
let top_left = ui.cursor_screen_pos();
|
|
|
|
|
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 y_scale = region_size[1] / a.scale_max;
|
|
|
|
|
a.iter_data_from_head()
|
|
|
|
|
.fold((0, 0.0f32), |accum, &fps_val| {
|
|
|
|
|
let x1 = accum.0 as f32 * x_scale + top_left[0];
|
|
|
|
|
let y1 = top_left[1] + region_size[1] - accum.1 * y_scale;
|
|
|
|
|
let x2 = (accum.0 as f32 + 1.0) * x_scale + top_left[0];
|
|
|
|
|
let y2 = top_left[1] + region_size[1] - fps_val * y_scale;
|
|
|
|
|
let p1 = [x1, y1];
|
|
|
|
|
let p2 = [x2, y2];
|
|
|
|
|
draw_list
|
|
|
|
|
.add_line(p1, p2, [1.0, 1.0, 0.0])
|
|
|
|
|
.thickness(1.0)
|
|
|
|
|
.build();
|
|
|
|
|
(accum.0 + 1, fps_val)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let text_x = (region_size[0] - region_size[0]/5.0 + 75.0);
|
|
|
|
|
let text_y = top_left[1] + region_size[1] - a.current_average_label().0 * y_scale;
|
|
|
|
|
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));
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
ImguiPerformanceProfilerLine::new("RenderFFS".to_string()),
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[system]
|
|
|
|
|