don't show the inspector unless inpsector is configured

This commit is contained in:
Joe Ardent 2023-01-25 17:18:49 -08:00
parent 651f471b97
commit 1b559f3d44
4 changed files with 47 additions and 22 deletions

View File

@ -61,7 +61,7 @@ fn gravity(
fn falling_cat( fn falling_cat(
mut bike_query: Query<(&Transform, &mut ExternalForce, &mut CyberBikeControl)>, mut bike_query: Query<(&Transform, &mut ExternalForce, &mut CyberBikeControl)>,
diagnostics: Res<Diagnostics>, _diagnostics: Res<Diagnostics>,
settings: Res<CatControllerSettings>, settings: Res<CatControllerSettings>,
) { ) {
let (xform, mut forces, mut control_vars) = bike_query.single_mut(); let (xform, mut forces, mut control_vars) = bike_query.single_mut();
@ -82,13 +82,14 @@ fn falling_cat(
let mag = (settings.kp * error) + (settings.kws * weighted_sum) + (settings.kd * derivative); let mag = (settings.kp * error) + (settings.kws * weighted_sum) + (settings.kd * derivative);
if let Some(count) = diagnostics #[cfg(feature = "inspector")]
if let Some(count) = _diagnostics
.get(FrameTimeDiagnosticsPlugin::FRAME_COUNT) .get(FrameTimeDiagnosticsPlugin::FRAME_COUNT)
.and_then(|d| d.smoothed()) .and_then(|d| d.smoothed())
.map(|x| x as u64) .map(|x| x as u64)
{ {
if count % 30 == 0 { if count % 30 == 0 {
dbg!(&control_vars, mag, cos); dbg!(&control_vars, mag, cos, derivative);
} }
} }

View File

@ -1,6 +1,6 @@
use std::fmt::Debug; use std::fmt::Debug;
use bevy::prelude::{shape::Capsule as Tire, *}; use bevy::prelude::{shape::UVSphere as Tire, *};
use bevy_rapier3d::{ use bevy_rapier3d::{
geometry::Group, geometry::Group,
prelude::{ prelude::{
@ -54,12 +54,12 @@ impl Default for WheelConfig {
fn default() -> Self { fn default() -> Self {
Self { Self {
front_forward: 0.9, front_forward: 0.9,
front_stance: 1.2, front_stance: 0.65,
rear_back: 1.1, rear_back: 1.1,
y: -1.0, y: -1.5,
limits: [0.1, 1.0], limits: [-1.0, 1.0],
stiffness: 10.0, stiffness: 20.0,
damping: 0.7, damping: 1.0,
radius: 0.3, radius: 0.3,
} }
} }
@ -140,11 +140,27 @@ fn spawn_cyberbike(
.insert(CyberBikeControl::default()) .insert(CyberBikeControl::default())
.id(); .id();
//return; spawn_tires(&mut commands, &xform, bike, &wheel_conf, &mut meshterials);
re_tire(&mut commands, &xform, bike, &wheel_conf, &mut meshterials);
} }
fn re_tire( fn re_tire(
mut commands: Commands,
wheel_conf: ResMut<WheelConfig>,
mut meshterials: Meshterial,
bquery: Query<(Entity, &Transform), With<CyberBikeBody>>,
wheels: Query<Entity, With<CyberWheel>>,
) {
// we fuck with values in the egui inspector
let (bike, xform) = bquery.single();
if wheel_conf.is_changed() {
for wheel in wheels.iter() {
commands.entity(wheel).despawn_recursive();
}
spawn_tires(&mut commands, xform, bike, &wheel_conf, &mut meshterials);
}
}
fn spawn_tires(
commands: &mut Commands, commands: &mut Commands,
xform: &Transform, xform: &Transform,
bike: Entity, bike: Entity,
@ -164,8 +180,6 @@ fn re_tire(
let tire = Tire { let tire = Tire {
radius: wheel_rad, radius: wheel_rad,
rings: 1,
depth: 0.2,
..Default::default() ..Default::default()
}; };
let material = StandardMaterial { let material = StandardMaterial {
@ -191,7 +205,7 @@ fn re_tire(
// left front // left front
{ {
let wheel_x = -conf.front_stance; let wheel_x = -conf.front_stance;
let wheel_z = conf.front_forward; let wheel_z = -conf.front_forward;
let offset = Vec3::new(wheel_x, wheel_y, wheel_z); let offset = Vec3::new(wheel_x, wheel_y, wheel_z);
wheel_poses.push(offset); wheel_poses.push(offset);
} }
@ -199,15 +213,15 @@ fn re_tire(
// right front // right front
{ {
let wheel_x = conf.front_stance; let wheel_x = conf.front_stance;
let wheel_z = conf.front_forward; let wheel_z = -conf.front_forward;
let offset = Vec3::new(wheel_x, wheel_y, wheel_z); let offset = Vec3::new(wheel_x, wheel_y, wheel_z);
wheel_poses.push(offset); wheel_poses.push(offset);
} }
// rear // rear
{ {
let wheel_x = -conf.front_stance; let wheel_x = 0.0;
let wheel_z = conf.front_forward; let wheel_z = conf.rear_back;
let offset = Vec3::new(wheel_x, wheel_y, wheel_z); let offset = Vec3::new(wheel_x, wheel_y, wheel_z);
wheel_poses.push(offset); wheel_poses.push(offset);
} }
@ -224,7 +238,7 @@ fn re_tire(
let damping = 0.3; let damping = 0.3;
let prismatic = PrismaticJointBuilder::new(Vec3::Y) let prismatic = PrismaticJointBuilder::new(Vec3::Y)
.local_anchor2(offset) .local_anchor1(offset)
.limits(limits) .limits(limits)
.motor_position(0.0, stiffness, damping); .motor_position(0.0, stiffness, damping);
let joint = ImpulseJoint::new(bike, prismatic); let joint = ImpulseJoint::new(bike, prismatic);
@ -267,6 +281,7 @@ impl Plugin for CyberBikePlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.insert_resource(WheelConfig::default()) app.insert_resource(WheelConfig::default())
.register_type::<WheelConfig>() .register_type::<WheelConfig>()
.add_startup_system_to_stage(StartupStage::PostStartup, spawn_cyberbike); .add_startup_system_to_stage(StartupStage::PostStartup, spawn_cyberbike)
.add_system(re_tire);
} }
} }

View File

@ -35,6 +35,13 @@ fn update_debug_cam(mut offset: ResMut<DebugCamOffset>, mut keys: ResMut<Input<K
_ => continue, _ => continue,
} }
} }
if keys.get_just_released().len() > 0 {
keys.reset_all();
if shifted {
keys.press(KeyCode::LShift);
}
}
} }
fn update_input(mut events: EventReader<GamepadEvent>, mut istate: ResMut<InputState>) { fn update_input(mut events: EventReader<GamepadEvent>, mut istate: ResMut<InputState>) {

View File

@ -2,6 +2,7 @@ use bevy::prelude::{
AlignSelf, App, AssetServer, Color, Commands, Component, Plugin, Query, Res, Style, Text, AlignSelf, App, AssetServer, Color, Commands, Component, Plugin, Query, Res, Style, Text,
TextBundle, TextSection, TextStyle, With, TextBundle, TextSection, TextStyle, With,
}; };
#[cfg(feature = "inspector")]
use bevy_inspector_egui::quick::WorldInspectorPlugin; use bevy_inspector_egui::quick::WorldInspectorPlugin;
use bevy_rapier3d::prelude::Velocity; use bevy_rapier3d::prelude::Velocity;
@ -50,8 +51,9 @@ pub struct CyberUIPlugin;
impl Plugin for CyberUIPlugin { impl Plugin for CyberUIPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_plugin(WorldInspectorPlugin) #[cfg(feature = "inspector")]
.add_startup_system(setup_ui) app.add_plugin(WorldInspectorPlugin);
.add_system(update_ui);
app.add_startup_system(setup_ui).add_system(update_ui);
} }
} }