Add controller-driven debug menu
This commit is contained in:
@@ -93,7 +93,7 @@ pub struct AttackHitbox {
|
||||
}
|
||||
|
||||
pub fn update_active_hitbox_list(script: &FighterAttackScript, list: &mut Vec<usize>, frame: u32) {
|
||||
*list = script.hitboxes.iter().enumerate().filter(|(i, hb)| {
|
||||
*list = script.hitboxes.iter().enumerate().filter(|(_, hb)| {
|
||||
hb.start_frame <= frame && hb.end_frame > frame
|
||||
}).map(|(i, _)| i).collect()
|
||||
}
|
||||
|
||||
+72
-19
@@ -14,7 +14,9 @@ use crate::fighter::{
|
||||
};
|
||||
use crate::input::FighterInput;
|
||||
use crate::math::vec3::FGVec3;
|
||||
use crate::player::Player;
|
||||
use crate::scripting::FighterAttackScript;
|
||||
use crate::debug_tools::{DebugSettings, FighterDebugRowKind};
|
||||
|
||||
pub fn debug_draw_ecb(
|
||||
ecbs: Query<(
|
||||
@@ -39,13 +41,77 @@ pub fn debug_draw_ecb(
|
||||
}
|
||||
pub fn fighter_debug(
|
||||
mut contexts: EguiContexts,
|
||||
query: Query<(&FighterVelocity, &FighterInput, &StateNameDebug)>,
|
||||
query: Query<(
|
||||
&Player,
|
||||
&FighterVelocity,
|
||||
&FighterInput,
|
||||
&FighterAnimationFrame,
|
||||
&StateNameDebug,
|
||||
&FighterAnimations,
|
||||
&FighterTranslation,
|
||||
&FighterFacingDirection,
|
||||
)>,
|
||||
anims: Res<Assets<BakedFighterAnimations>>,
|
||||
settings: Res<DebugSettings>,
|
||||
) -> Result {
|
||||
for (i, (vel, input, name)) in query.iter().enumerate() {
|
||||
egui::Window::new(format!("Player {}", i)).show(contexts.ctx_mut()?, |ui| {
|
||||
ui.label(format!("State: {}", name.0));
|
||||
ui.label(format!("{:?}", vel));
|
||||
ui.label(format!("{:?}", input.get_last_frame()));
|
||||
let mut fighters = query.iter().collect::<Vec<_>>();
|
||||
fighters.sort_unstable_by_key(|(player, ..)| player.handle);
|
||||
|
||||
for (player, velocity, input, animation_frame, state_name, animations, translation, facing) in fighters {
|
||||
let Some(rows) = settings.player_rows(player.handle) else {
|
||||
continue;
|
||||
};
|
||||
if rows.iter().all(|row| *row == FighterDebugRowKind::None) {
|
||||
continue;
|
||||
}
|
||||
|
||||
egui::Window::new(format!("Player {}", player.handle + 1)).show(contexts.ctx_mut()?, |ui| {
|
||||
for row in rows {
|
||||
match row {
|
||||
FighterDebugRowKind::None => {}
|
||||
FighterDebugRowKind::CurrentState => {
|
||||
let frame_count = anims
|
||||
.get(&animations.baked)
|
||||
.and_then(|animation| animation.frame_count(animation_frame.kind));
|
||||
if let Some(frame_count) = frame_count {
|
||||
ui.label(format!(
|
||||
"State: {:?} ({:?} {}/{})",
|
||||
state_name.0, animation_frame.kind, animation_frame.frame, frame_count
|
||||
));
|
||||
} else {
|
||||
ui.label(format!("State: {:?} ({:?})", state_name.0, animation_frame.kind));
|
||||
}
|
||||
}
|
||||
FighterDebugRowKind::Velocity => {
|
||||
ui.label(format!("Velocity: ({:.2}, {:.2})", velocity.0.x, velocity.0.y));
|
||||
}
|
||||
FighterDebugRowKind::Input => {
|
||||
const STICK_SIZE: f32 = 50.0;
|
||||
const STICK_SIZE_FRACTION: f32 = 0.75;
|
||||
let last_frame = input.get_last_frame();
|
||||
let movement = egui::Vec2::new(last_frame.movement.x.to_num(), -last_frame.movement.y.to_num::<f32>());
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
let (_, rect) = ui.allocate_space(egui::Vec2::new(STICK_SIZE*(1.0 + STICK_SIZE_FRACTION), STICK_SIZE*(1.0 + STICK_SIZE_FRACTION)));
|
||||
let painter = ui.painter();
|
||||
let button_bg = egui::Rgba::WHITE * egui::Rgba::from_white_alpha(0.25);
|
||||
painter.circle_filled(rect.center(), STICK_SIZE * 0.5, button_bg);
|
||||
painter.circle_filled(
|
||||
rect.center() + STICK_SIZE * 0.5 * movement,
|
||||
STICK_SIZE * STICK_SIZE_FRACTION * 0.5,
|
||||
button_bg,
|
||||
);
|
||||
ui.label(format!("X: {:.2}\nY:{:.2}", last_frame.movement.x, last_frame.movement.y));
|
||||
});
|
||||
}
|
||||
FighterDebugRowKind::Position => {
|
||||
ui.label(format!("Position: {:?}", translation.0));
|
||||
},
|
||||
FighterDebugRowKind::Facing => {
|
||||
ui.label(format!("Facing: {:?}", facing));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Ok(())
|
||||
@@ -110,16 +176,3 @@ pub fn attack_debug(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_config(
|
||||
mut config_store: ResMut<GizmoConfigStore>,
|
||||
keyboard: Res<ButtonInput<KeyCode>>,
|
||||
_real_time: Res<Time<Real>>,
|
||||
_virtual_time: ResMut<Time<Virtual>>,
|
||||
) {
|
||||
if keyboard.just_pressed(KeyCode::KeyT) {
|
||||
for (_, config, _) in config_store.iter_mut() {
|
||||
config.depth_bias = if config.depth_bias == 0. { -1. } else { 0. };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+16
-5
@@ -147,11 +147,22 @@ impl Plugin for FighterPlugin {
|
||||
.rollback_component_with_copy::<FighterFacingDirection>()
|
||||
.rollback_resource_with_reflect::<StageCollision>()
|
||||
// Debug views.
|
||||
.add_systems(FixedPostUpdate, debug::debug_draw_ecb)
|
||||
.add_systems(EguiPrimaryContextPass, debug::fighter_debug)
|
||||
.add_systems(FixedPostUpdate, debug::animation_debug)
|
||||
.add_systems(FixedPostUpdate, debug::attack_debug)
|
||||
.add_systems(EguiPrimaryContextPass, debug::update_config)
|
||||
.add_systems(
|
||||
FixedPostUpdate,
|
||||
debug::debug_draw_ecb.run_if(crate::debug_tools::ecb_enabled),
|
||||
)
|
||||
.add_systems(
|
||||
EguiPrimaryContextPass,
|
||||
debug::fighter_debug.run_if(crate::debug_tools::fighter_info_enabled),
|
||||
)
|
||||
.add_systems(
|
||||
FixedPostUpdate,
|
||||
debug::animation_debug.run_if(crate::debug_tools::animation_bones_enabled),
|
||||
)
|
||||
.add_systems(
|
||||
FixedPostUpdate,
|
||||
debug::attack_debug.run_if(crate::debug_tools::attack_hitboxes_enabled),
|
||||
)
|
||||
.rollback_component_with_clone::<FighterState>()
|
||||
.rollback_component_with_clone::<FighterHitboxes>()
|
||||
.checksum_component_with_hash::<FighterState>()
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
//! this module is what turns that into a position.
|
||||
|
||||
use bevy::prelude::*;
|
||||
use fixed::types::I16F16;
|
||||
|
||||
use crate::{fighter::{FighterFacingDirection, baked_animation::FixedMat4}, math::{int::FGi32, vec::FGVec2, vec3::FGVec3}};
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use crate::fighter::{attack::{AttackKind, update_active_hitbox_list}, state::{FighterState, FighterStateImpl, ground::GroundedStateCommon, wait::WaitState}};
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, Hash)]
|
||||
pub struct GroundAttackState {
|
||||
pub attack_kind: AttackKind,
|
||||
|
||||
@@ -10,7 +10,6 @@ use crate::fighter::attack::FighterAttackScriptAssets;
|
||||
use crate::fighter::baked_animation::{BakedFighterAnimations, FixedMat4};
|
||||
use crate::fighter::ecb::FighterPreviousECB;
|
||||
use crate::fighter::manifest::FighterManifest;
|
||||
use crate::fighter::state::ground_attack::GroundAttackState;
|
||||
use crate::fighter::visual::FighterAnimations;
|
||||
use crate::fighter::{
|
||||
Fighter, FighterECB, FighterFacingDirection, FighterHitboxes, FighterPreviousTranslation, FighterTranslation, FighterVelocity,
|
||||
|
||||
Reference in New Issue
Block a user