~starkingdoms/starkingdoms

46b01f1b5387cb0aa191e9f983a237ae42726d68 — core 23 days ago 2c4d032
feat: additional debug information in joint-debug F6
2 files changed, 13 insertions(+), 5 deletions(-)

M crates/unified/src/client/ship/thrusters.rs
M crates/unified/src/thrust.rs
M crates/unified/src/client/ship/thrusters.rs => crates/unified/src/client/ship/thrusters.rs +11 -4
@@ 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() {

M crates/unified/src/thrust.rs => crates/unified/src/thrust.rs +2 -1
@@ 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<Entity>
    pub thrusters_on: BTreeSet<Entity>,
    pub converged: bool
}
\ No newline at end of file