From 46b01f1b5387cb0aa191e9f983a237ae42726d68 Mon Sep 17 00:00:00 2001 From: core Date: Sat, 22 Nov 2025 21:37:11 -0500 Subject: [PATCH] feat: additional debug information in joint-debug F6 --- crates/unified/src/client/ship/thrusters.rs | 15 +++++++++++---- crates/unified/src/thrust.rs | 3 ++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/crates/unified/src/client/ship/thrusters.rs b/crates/unified/src/client/ship/thrusters.rs index 9afe3068f3369d1fd3b1ee432dea743ffff8aa7a..a2bfaedb1ac419cfeb4e604735643f7b6d2431d4 100644 --- a/crates/unified/src/client/ship/thrusters.rs +++ b/crates/unified/src/client/ship/thrusters.rs @@ -1,7 +1,7 @@ use std::collections::BTreeSet; use std::time::Instant; use bevy::app::App; -use bevy::color::palettes::basic::WHITE; +use bevy::color::palettes::basic::{RED, WHITE}; use bevy::color::palettes::css::LIMEGREEN; use bevy::math::Vec3Swizzles; use leafwing_input_manager::prelude::ActionState; @@ -36,11 +36,15 @@ fn draw_thruster_debug( if !thruster_debug_res.0 { return }; for thruster in thrusters { // Draw white if it's just a thruster, bright green if it's in the current thrust solution - let color = if thrust_solution.thrusters_on.contains(&thruster.1) { + let mut color = if thrust_solution.thrusters_on.contains(&thruster.1) { LIMEGREEN } else { WHITE }; + // Exception: if the thrust solution failed to converge, RED + if !thrust_solution.converged { + color = RED; + } gizmos.arrow_2d( thruster.2.translation().xy(), thruster.2.translation().xy() + thruster.2.rotation().mul_vec3(thruster.0.thrust_vector.extend(0.0)).xy(), @@ -67,6 +71,8 @@ fn solve_thrust( debug!("input changed, recalculating thrust solution"); let start = Instant::now(); + solution.thrusters_on.clear(); + solution.converged = false; // determine our target vector: // unit vector in the intended direction of movement @@ -98,8 +104,8 @@ fn solve_thrust( if target_unit_vector == Vec3::ZERO { debug!("no buttons are pressed; zeroing thrust solution"); - solution.thrusters_on.clear(); debug!("solved thrust in {}ms", start.elapsed().as_millis()); + solution.converged = true; return; } @@ -188,7 +194,8 @@ fn solve_thrust( debug!("solution alignment (higher is better): {}", ssolution.objective()); let mut new_soln = ThrustSolution { - thrusters_on: BTreeSet::default() + thrusters_on: BTreeSet::default(), + converged: true }; for thruster in all_thrusters.iter().enumerate() { diff --git a/crates/unified/src/thrust.rs b/crates/unified/src/thrust.rs index 6f05e4b836e9e7088c8d778b285a26e00d53ec7f..a3297f5562984fbaefb5bd636f2fbcd860b1436b 100644 --- a/crates/unified/src/thrust.rs +++ b/crates/unified/src/thrust.rs @@ -7,5 +7,6 @@ use serde::{Deserialize, Serialize}; /// Any thrusters not in this set should be off. #[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone, Resource)] pub struct ThrustSolution { - pub thrusters_on: BTreeSet + pub thrusters_on: BTreeSet, + pub converged: bool } \ No newline at end of file