add altitude/pressure gauges

This commit is contained in:
yuni 2024-11-27 14:35:39 +01:00
parent 14d4305965
commit 44fa57a276
3 changed files with 34 additions and 7 deletions

View file

@ -1127,15 +1127,17 @@ fn handle_gravity(
fn handle_atmosphere(
time: Res<Time>,
mut settings: ResMut<Settings>,
q_atmosphere: Query<(&Position, Option<&LinearVelocity>, &HasAtmosphere)>,
mut q_actor: Query<
(&Position, &mut LinearVelocity),
(&Position, &mut LinearVelocity, Option<&PlayerCamera>),
(With<ExperiencesAtmosphere>, Without<HasAtmosphere>),
>,
) {
let dt = time.delta_seconds() as f64;
let mut reset_player_gauges = false;
for (pos, mut v) in &mut q_actor {
for (pos, mut v, player) in &mut q_actor {
for (atmo_pos, atmo_v, atmo) in &q_atmosphere {
let distance = atmo_pos.distance(pos.0);
if distance < atmo.r_outer {
@ -1154,6 +1156,12 @@ fn handle_atmosphere(
let friction = dv * (1.0 - height).powf(16.0) * dt * 10.0;
v.0 -= friction;
if player.is_some() {
settings.atmo_pressure = Some(friction.length() as f32);
settings.atmo_altitude = Some(height as f32);
reset_player_gauges = false;
}
if distance < atmo.r_inner {
let outward = (pos.0 - atmo_pos.0).normalize();
// depth is 0.0 on "surface" and 1.0 at center
@ -1166,4 +1174,9 @@ fn handle_atmosphere(
}
}
}
if reset_player_gauges {
settings.atmo_pressure = None;
settings.atmo_altitude = None;
}
}

View file

@ -686,7 +686,8 @@ pub fn setup(
},));
});
let mut bundle_speedometer_text = TextBundle::from_sections([
TextSection::new("", style_speedometer.clone()), // speed relative to target
TextSection::new("", style_speedometer.clone()), // atmospheric conditions
TextSection::new("", style_speedometer.clone()), // g-force
TextSection::new("", style_speedometer.clone()), // speed relative to target
TextSection::new("", style_speedometer.clone()), // speed relative to orbit
])
@ -874,8 +875,18 @@ fn update_speedometer(
speedometer2.width = Val::Vw(wid);
}
if let Ok(mut speed_text) = q_node_speed.get_single_mut() {
// Atmospheric conditions
let mut atmo = String::new();
if let Some(val) = settings.atmo_altitude {
atmo += format!("Altitude: {val:.6}\n").as_str();
}
if let Some(val) = settings.atmo_pressure {
atmo += format!("Pressure: {val:.6}\n").as_str();
}
speed_text.sections[0].value = atmo;
// G forces
speed_text.sections[0].value = if let Ok(gforce) = q_player.get_single() {
speed_text.sections[1].value = if let Ok(gforce) = q_player.get_single() {
if gforce.gforce > 0.0001 {
format!("{:.1}g\n", gforce.gforce)
} else {
@ -886,8 +897,7 @@ fn update_speedometer(
};
// Velocity relative to target
speed_text.sections[1].value = if let Ok(target_v) = q_target.get_single() {
let delta_v = (target_v.0 - cam_v.0).length();
speed_text.sections[2].value = if let Ok(target_v) = q_target.get_single() { let delta_v = (target_v.0 - cam_v.0).length();
if delta_v > 0.0001 {
format!("Δv {}\n", nature::readable_speed(delta_v))
} else {
@ -898,7 +908,7 @@ fn update_speedometer(
};
// "Absolute velocity", or velocity relative to orbit
speed_text.sections[2].value = if speed > 0.0001 {
speed_text.sections[3].value = if speed > 0.0001 {
nature::readable_speed(speed)
} else {
"".to_string()

View file

@ -52,6 +52,8 @@ pub struct Settings {
pub fov_highspeed: f32,
pub zoom_fov: f32,
pub zoom_sensitivity_factor: f32,
pub atmo_pressure: Option<f32>,
pub atmo_altitude: Option<f32>,
pub font_size_hud: f32,
pub font_size_fps: f32,
pub font_size_conversations: f32,
@ -200,6 +202,8 @@ impl Default for Settings {
fov_highspeed: 25.0,
zoom_fov: 15.0,
zoom_sensitivity_factor: 0.25,
atmo_pressure: None,
atmo_altitude: None,
font_size_hud: 24.0,
font_size_fps: 14.0,
font_size_conversations: 32.0,