debug egui
This commit is contained in:
+46
-5
@@ -1,4 +1,5 @@
|
|||||||
use bevy::{
|
use bevy::{
|
||||||
|
asset::uuid::timestamp::context,
|
||||||
diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin},
|
diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
};
|
};
|
||||||
@@ -206,6 +207,39 @@ fn update_view_debug_text(mut text: Single<&mut Text, With<ViewDebugText>>) {
|
|||||||
text.0 = format!("View: {SCREEN_WIDTH:.0}x{SCREEN_HEIGHT:.0}");
|
text.0 = format!("View: {SCREEN_WIDTH:.0}x{SCREEN_HEIGHT:.0}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn debug_panel(
|
||||||
|
mut contexts: EguiContexts,
|
||||||
|
store: Res<DiagnosticsStore>,
|
||||||
|
run_seed: Res<RunSeed>,
|
||||||
|
mut main_camera: Single<&mut Camera, (With<MainCamera>, Without<DebugCamera>)>,
|
||||||
|
mut debug_camera: Single<&mut Camera, (With<DebugCamera>, Without<MainCamera>)>,
|
||||||
|
) {
|
||||||
|
egui::Window::new("Debug").show(contexts.ctx_mut().expect("gui context missing"), |ui| {
|
||||||
|
// Fps
|
||||||
|
let fps = store
|
||||||
|
.get(&FrameTimeDiagnosticsPlugin::FPS)
|
||||||
|
.and_then(|diagnostic| diagnostic.smoothed());
|
||||||
|
|
||||||
|
match fps {
|
||||||
|
Some(fps) => ui.label(format!("FPS: {fps:.0}")),
|
||||||
|
None => ui.label("FPS: -"),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Run seed
|
||||||
|
ui.label(format!("Seed: {}", run_seed.0));
|
||||||
|
// Resolution
|
||||||
|
ui.label(format!("View: {SCREEN_WIDTH:.0}x{SCREEN_HEIGHT:.0}"));
|
||||||
|
|
||||||
|
ui.separator();
|
||||||
|
|
||||||
|
let state = if debug_camera.is_active { "ON" } else { "OFF" };
|
||||||
|
if ui.button(format!("Debug camera: {state}")).clicked() {
|
||||||
|
main_camera.is_active = !main_camera.is_active;
|
||||||
|
debug_camera.is_active = !debug_camera.is_active;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Real time tuning movement & inertia sliders
|
// Real time tuning movement & inertia sliders
|
||||||
fn move_tuning_panel(mut contexts: EguiContexts, mut settings: ResMut<MoveSettings>) {
|
fn move_tuning_panel(mut contexts: EguiContexts, mut settings: ResMut<MoveSettings>) {
|
||||||
egui::Window::new("Movement / Inertia ").show(
|
egui::Window::new("Movement / Inertia ").show(
|
||||||
@@ -227,6 +261,12 @@ fn move_tuning_panel(mut contexts: EguiContexts, mut settings: ResMut<MoveSettin
|
|||||||
ui.add(
|
ui.add(
|
||||||
egui::Slider::new(&mut settings.vertical_rate, 0.0..=10000.0).text("Vertical rate"),
|
egui::Slider::new(&mut settings.vertical_rate, 0.0..=10000.0).text("Vertical rate"),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
ui.separator();
|
||||||
|
|
||||||
|
if ui.button("Reset").clicked() {
|
||||||
|
*settings = MoveSettings::default();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -241,7 +281,7 @@ impl Plugin for DebugPlugin {
|
|||||||
spawn_debug_camera,
|
spawn_debug_camera,
|
||||||
setup_debug_camera.after(spawn_debug_camera),
|
setup_debug_camera.after(spawn_debug_camera),
|
||||||
spawn_debug_frame,
|
spawn_debug_frame,
|
||||||
spawn_debug_texts,
|
// spawn_debug_texts,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.add_systems(
|
.add_systems(
|
||||||
@@ -250,15 +290,16 @@ impl Plugin for DebugPlugin {
|
|||||||
draw_view_frame,
|
draw_view_frame,
|
||||||
follow_player_debug,
|
follow_player_debug,
|
||||||
toggle_debug_camera,
|
toggle_debug_camera,
|
||||||
update_seed_debug_text,
|
// update_seed_debug_text,
|
||||||
update_fps_debug_text,
|
// update_fps_debug_text,
|
||||||
update_view_debug_text,
|
// update_view_debug_text,
|
||||||
)
|
)
|
||||||
.run_if(in_state(GameState::InGame)),
|
.run_if(in_state(GameState::InGame)),
|
||||||
)
|
)
|
||||||
|
// Egui debug
|
||||||
.add_systems(
|
.add_systems(
|
||||||
EguiPrimaryContextPass,
|
EguiPrimaryContextPass,
|
||||||
move_tuning_panel.run_if(in_state(GameState::InGame)),
|
(move_tuning_panel, debug_panel).run_if(in_state(GameState::InGame)),
|
||||||
)
|
)
|
||||||
.add_plugins(FrameTimeDiagnosticsPlugin::default())
|
.add_plugins(FrameTimeDiagnosticsPlugin::default())
|
||||||
.add_systems(OnExit(GameState::InGame), cleanup_debug);
|
.add_systems(OnExit(GameState::InGame), cleanup_debug);
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ use crate::{
|
|||||||
gameplay::collision::Collider,
|
gameplay::collision::Collider,
|
||||||
world::{
|
world::{
|
||||||
Chunk,
|
Chunk,
|
||||||
generator::generate_chunk,
|
|
||||||
grid::{GridRect, grid_to_world},
|
grid::{GridRect, grid_to_world},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -22,11 +21,11 @@ pub fn spawn_obstacle_chunk(commands: &mut Commands, id: i64, run_seed: u64) {
|
|||||||
|
|
||||||
let depth = -id;
|
let depth = -id;
|
||||||
|
|
||||||
let data = generate_chunk(run_seed, depth);
|
// let data = generate_chunk(run_seed, depth);
|
||||||
|
|
||||||
for rect in data.rects {
|
// for rect in data.rects {
|
||||||
spawn_rect(commands, id, rect);
|
// spawn_rect(commands, id, rect);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spawn_rect(commands: &mut Commands, id: i64, rect: GridRect) {
|
fn spawn_rect(commands: &mut Commands, id: i64, rect: GridRect) {
|
||||||
|
|||||||
Reference in New Issue
Block a user