debug egui

This commit is contained in:
2026-09-20 16:01:38 +02:00
parent a31e1c3b98
commit 8d24093585
2 changed files with 67 additions and 5 deletions
+65 -3
View File
@@ -1,6 +1,7 @@
use bevy::{ use bevy::{
asset::uuid::timestamp::context, asset::uuid::timestamp::context,
diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin}, diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin},
math::curve::cores::ChunkedUnevenCoreError,
prelude::*, prelude::*,
}; };
use bevy_egui::{EguiContexts, EguiPrimaryContextPass, egui}; use bevy_egui::{EguiContexts, EguiPrimaryContextPass, egui};
@@ -9,10 +10,11 @@ use crate::{
config::{SCREEN_HEIGHT, SCREEN_WIDTH}, config::{SCREEN_HEIGHT, SCREEN_WIDTH},
gameplay::{ gameplay::{
camera::MainCamera, camera::MainCamera,
player::{MoveSettings, Player}, player::{FallStarted, MoveSettings, Player, Velocity, spawn_player},
score::Depth,
}, },
states::GameState, states::GameState,
world::RunSeed, world::{Chunk, RunSeed},
}; };
#[derive(Component)] #[derive(Component)]
@@ -210,9 +212,14 @@ fn update_view_debug_text(mut text: Single<&mut Text, With<ViewDebugText>>) {
fn debug_panel( fn debug_panel(
mut contexts: EguiContexts, mut contexts: EguiContexts,
store: Res<DiagnosticsStore>, store: Res<DiagnosticsStore>,
run_seed: Res<RunSeed>, mut run_seed: ResMut<RunSeed>,
player: Single<(Entity, &Transform, &Velocity), With<Player>>,
chunk: Query<Entity, With<Chunk>>,
mut main_camera: Single<&mut Camera, (With<MainCamera>, Without<DebugCamera>)>, mut main_camera: Single<&mut Camera, (With<MainCamera>, Without<DebugCamera>)>,
mut debug_camera: Single<&mut Camera, (With<DebugCamera>, Without<MainCamera>)>, mut debug_camera: Single<&mut Camera, (With<DebugCamera>, Without<MainCamera>)>,
mut commands: Commands,
mut fall_started: ResMut<FallStarted>,
mut depth: ResMut<Depth>,
) { ) {
egui::Window::new("Debug").show(contexts.ctx_mut().expect("gui context missing"), |ui| { egui::Window::new("Debug").show(contexts.ctx_mut().expect("gui context missing"), |ui| {
// Fps // Fps
@@ -225,8 +232,28 @@ fn debug_panel(
None => ui.label("FPS: -"), None => ui.label("FPS: -"),
}; };
// Frame time in ms
match store
.get(&FrameTimeDiagnosticsPlugin::FRAME_TIME)
.and_then(|d| d.smoothed())
{
Some(ms) => ui.label(format!("Frame: {ms:.2} ms")),
None => ui.label("Frame : - ms"),
};
// Run seed // Run seed
ui.label(format!("Seed: {}", run_seed.0)); ui.label(format!("Seed: {}", run_seed.0));
let (player_entity, transform, velocity) = *player;
ui.label(format!(
"Position: ({:.0}, {:.0})",
transform.translation.x, transform.translation.y
));
ui.label(format!(
"Velocity: ({:.0},{:.0})",
velocity.0.x, velocity.0.y
));
// Resolution // Resolution
ui.label(format!("View: {SCREEN_WIDTH:.0}x{SCREEN_HEIGHT:.0}")); ui.label(format!("View: {SCREEN_WIDTH:.0}x{SCREEN_HEIGHT:.0}"));
@@ -237,6 +264,25 @@ fn debug_panel(
main_camera.is_active = !main_camera.is_active; main_camera.is_active = !main_camera.is_active;
debug_camera.is_active = !debug_camera.is_active; debug_camera.is_active = !debug_camera.is_active;
} }
ui.separator();
let restart = ui.button("Restart (same seed)").clicked();
let new_map = ui.button("Restart (new map)").clicked();
if restart || new_map {
for entity in chunk.iter() {
commands.entity(entity).despawn();
}
if new_map {
run_seed.0 = rand::random::<u64>();
}
fall_started.0 = false;
depth.0 = 0.0;
commands.entity(player_entity).despawn();
spawn_player(commands);
}
}); });
} }
@@ -267,6 +313,22 @@ fn move_tuning_panel(mut contexts: EguiContexts, mut settings: ResMut<MoveSettin
if ui.button("Reset").clicked() { if ui.button("Reset").clicked() {
*settings = MoveSettings::default(); *settings = MoveSettings::default();
} }
ui.separator();
let export_text = format!(
"pub const FALL_SPEED: f32 = {:.0};\npub const DIVE_SPEED: f32 = {:.0};\npub const HORIZONTAL_SPEED: f32 = {:.0};\npub const HORIZONTAL_ACCEL: f32 = {:.0};\npub const HORIZONTAL_FRICTION: f32 = {:.0};\npub const VERTICAL_RATE: f32 = {:.0};",
settings.fall_speed,
settings.dive_speed,
settings.horizontal_speed,
settings.horizontal_accel,
settings.horizontal_friction,
settings.vertical_rate,
);
// ui.monospace(&export_text);
if ui.button("Copy -> config.rs").clicked() {
ui.ctx().copy_text(export_text);
}
}, },
); );
} }
+2 -2
View File
@@ -18,14 +18,14 @@ pub struct Player;
// Speed of the player // Speed of the player
#[derive(Component)] #[derive(Component)]
pub struct Velocity(Vec2); pub struct Velocity(pub Vec2);
// Falling bool // Falling bool
#[derive(Resource, Default)] #[derive(Resource, Default)]
pub struct FallStarted(pub bool); pub struct FallStarted(pub bool);
// Spawn entity player // Spawn entity player
fn spawn_player(mut commands: Commands) { pub fn spawn_player(mut commands: Commands) {
commands.spawn(( commands.spawn((
Player, Player,
Collider { Collider {