Skip to content

Commit

Permalink
Add framerate display. \n + Fix object selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatekii committed Aug 19, 2019
1 parent 4d354b8 commit d3f9a84
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/app_state.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::stats::Stats;
use crate::vector_tile::object::Object;
use crate::interaction::collider::Collider;
use lyon::math::Point;
Expand All @@ -21,6 +22,7 @@ pub struct AppState {
pub zoom: f32,
pub hovered_objects: Vec<Object>,
pub selected_objects: Vec<EditableObject>,
pub stats: Stats,
}

impl AppState {
Expand All @@ -40,6 +42,7 @@ impl AppState {
zoom,
hovered_objects: vec![],
selected_objects: vec![],
stats: Stats::new(),
}
}

Expand Down
21 changes: 15 additions & 6 deletions src/drawing/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,25 @@ impl HUD {
mouse_pos[0],
mouse_pos[1]
));
ui.text(im_str!(
"Frametime {:.2} at zoom {:.2}",
app_state.stats.get_average(),
app_state.zoom
));
});

let window = imgui::Window::new(im_str!("Hello too"));
window
.size([400.0, 200.0], Condition::FirstUseEver)
.position([400.0, 200.0], Condition::FirstUseEver)
.build(&ui, || {
let mut item = 0;
// for i in 0..app_state.selected_objects.len() {
// if app_state.selected_objects[i].selected {
// item = i;
// }
// }
let mut item: i32 = 0;
for i in 0..app_state.selected_objects.len() {
if app_state.selected_objects[i].selected {
app_state.selected_objects[i].selected = false;
item = i as i32;
}
}
let items = app_state.selected_objects.iter().map(|o| im_str!("{:?}", o.object)).collect::<Vec<_>>();
let mut item_refs = vec![];
for item in &items {
Expand All @@ -100,6 +106,9 @@ impl HUD {
&item_refs,
5
);
if item >= 0 && items.len() > 0 {
app_state.selected_objects[item as usize].selected = true;
}
});

ui.show_demo_window(&mut true);
Expand Down
6 changes: 2 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ fn main() {
let mut mouse_down = false;
let mut last_pos = wgpu::winit::dpi::LogicalPosition::new(0.0, 0.0);

let mut stats = stats::Stats::new();

loop {
use wgpu::winit::{Event, WindowEvent, ElementState, MouseButton, MouseScrollDelta, KeyboardInput, VirtualKeyCode};
events_loop.poll_events(|event| {
Expand Down Expand Up @@ -111,9 +109,9 @@ fn main() {
painter.update_styles(app_state.zoom.max(14.0), &mut app_state.css_cache);
painter.paint(&mut hud, &mut app_state);

stats.capture_frame();
app_state.stats.capture_frame();
if CONFIG.general.display_framerate {
println!("Frametime {:.2} at zoom {:.2}", stats.get_average(), app_state.zoom);
println!("Frametime {:.2} at zoom {:.2}", app_state.stats.get_average(), app_state.zoom);
}

if !status {
Expand Down

0 comments on commit d3f9a84

Please sign in to comment.