Skip to content

Commit

Permalink
migrate to bevy 0.14.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-tennert committed Sep 20, 2024
1 parent b4dea08 commit ec54a49
Show file tree
Hide file tree
Showing 21 changed files with 1,787 additions and 907 deletions.
2,363 changes: 1,666 additions & 697 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ opt-level = 3
opt-level = 's'
lto = "thin"

[build-dependencies]
embed-resource = "1.6.3"
#[build-dependencies]
#embed-resource = "1.6.3"

[dependencies]
#bevy = { git = "https://github.com/bevyengine/bevy", branch = "release-0.11.3", features = ["dynamic_linking"] }
bevy = { version = "0.12.1" }
bevy_easings = "0.12.2"
bevy = { version = "0.14.2" }
bevy_easings = "0.14"
#bevy_panorbit_camera = { git = "https://github.com/jan-tennert/bevy_panorbit_camera", rev = "7e3c3f8" }
bevy-inspector-egui = { git = "https://github.com/barsoosayque/bevy-inspector-egui", branch = "main", default-features = false }
bevy-inspector-egui = { version = "0.26.0", default-features = false }
#bevy_mod_picking = "0.15"
bevy_egui = "0.24"
bevy_egui = "0.29.0"
chrono = "0.4.23"
serde_json = "1.0.107"
serde = { version = "1.0.189", features = ["derive"] }
winit = "0.28.7"
image = "0.24.7"
bevy_mod_billboard = "0.5.1"
bevy_mod_billboard = "0.7.0"
blocking = "1.5.1"
8 changes: 0 additions & 8 deletions build.rs

This file was deleted.

1 change: 0 additions & 1 deletion horizon-ui
Submodule horizon-ui deleted from 243280
86 changes: 0 additions & 86 deletions src/arrows.rs
Original file line number Diff line number Diff line change
@@ -1,88 +1,2 @@
use bevy::prelude::{Color, Gizmos, Quat, Vec3};

pub struct ArrowBuilder<'a, 's> {
gizmos: &'a mut Gizmos<'s>,
start: Vec3,
end: Vec3,
color: Color,
tip_length: f32,
}

/// A builder returned by [`Gizmos::arrow`] and [`Gizmos::arrow_2d`]
impl ArrowBuilder<'_, '_> {
/// Change the length of the tips to be `length`.
/// The default tip length is [length of the arrow]/10.
///
/// # Example
/// ```
/// # use bevy_gizmos::prelude::*;
/// # use bevy_render::prelude::*;
/// # use bevy_math::prelude::*;
/// fn system(mut gizmos: Gizmos) {
/// gizmos.arrow(Vec3::ZERO, Vec3::ONE, Color::GREEN)
/// .with_tip_length(3.);
/// }
/// # bevy_ecs::system::assert_is_system(system);
/// ```
#[doc(alias = "arrow_head_length")]
pub fn with_tip_length(&mut self, length: f32) {
self.tip_length = length;
}
}

impl Drop for ArrowBuilder<'_, '_> {
/// Draws the arrow, by drawing lines with the stored [`Gizmos`]
fn drop(&mut self) {
// first, draw the body of the arrow
self.gizmos.line(self.start, self.end, self.color);
// now the hard part is to draw the head in a sensible way
// put us in a coordinate system where the arrow is pointing towards +x and ends at the origin
let pointing = (self.end - self.start).normalize();
let rotation = Quat::from_rotation_arc(Vec3::X, pointing);
let tips = [
Vec3::new(-1., 1., 0.),
Vec3::new(-1., 0., 1.),
Vec3::new(-1., -1., 0.),
Vec3::new(-1., 0., -1.),
];
// - extend the vectors so their length is `tip_length`
// - rotate the world so +x is facing in the same direction as the arrow
// - translate over to the tip of the arrow
let tips = tips.map(|v| rotation * (v.normalize() * self.tip_length) + self.end);
for v in tips {
// then actually draw the tips
self.gizmos.line(self.end, v, self.color);
}
}
}

pub trait ArrowGizmos<'s> {
fn arrow(&mut self, start: Vec3, end: Vec3, color: Color) -> ArrowBuilder<'_, 's> ;
}

impl<'s> ArrowGizmos<'s> for Gizmos<'s> {
/// Draw an arrow in 3D, from `start` to `end`. Has four tips for convienent viewing from any direction.
///
/// This should be called for each frame the arrow needs to be rendered.
///
/// # Example
/// ```
/// # use bevy_gizmos::prelude::*;
/// # use bevy_render::prelude::*;
/// # use bevy_math::prelude::*;
/// fn system(mut gizmos: Gizmos) {
/// gizmos.arrow(Vec3::ZERO, Vec3::ONE, Color::GREEN);
/// }
/// # bevy_ecs::system::assert_is_system(system);
/// ```
fn arrow(&mut self, start: Vec3, end: Vec3, color: Color) -> ArrowBuilder<'_, 's> {
let length = (end - start).length();
ArrowBuilder {
gizmos: self,
start,
end,
color,
tip_length: length / 10.,
}
}
}
7 changes: 4 additions & 3 deletions src/body.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::collections::VecDeque;

use bevy::color::Color;
use bevy::color::palettes::css;
use bevy::core::Name;
use bevy::math::{DVec3, Vec3};
use bevy::prelude::{Bundle, Color, Component, default, Entity, Handle, Reflect, Scene, Transform};
use bevy::prelude::{Bundle, Component, default, Entity, Handle, Reflect, Scene, Transform, Srgba};

use crate::constants::M_TO_UNIT;
use crate::serialization::SerializedBody;
Expand Down Expand Up @@ -60,7 +61,7 @@ pub struct BillboardVisible(pub bool);
impl Default for OrbitSettings {

fn default() -> Self {
OrbitSettings { color: Color::GREEN, lines: VecDeque::with_capacity(3000), force_direction: DVec3::ZERO, draw_lines: false, step: 0.0, period: 0.0, display_force: false, display_velocity: false, arrow_scale: 1, hide_lines: false, }
OrbitSettings { color: css::GREEN.into(), lines: VecDeque::with_capacity(3000), force_direction: DVec3::ZERO, draw_lines: false, step: 0.0, period: 0.0, display_force: false, display_velocity: false, arrow_scale: 1, hide_lines: false, }
}

}
Expand Down
5 changes: 3 additions & 2 deletions src/camera.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use bevy::{
input::mouse::{MouseMotion, MouseWheel},
prelude::{
App, Component, EventReader, in_state, Input, IntoSystemConfigs, Mat3, MouseButton, Plugin, Projection,
App, Component, EventReader, in_state, IntoSystemConfigs, Mat3, MouseButton, Plugin, Projection,
Quat, Query, Res,
ResMut, Transform, Update, Vec2, Vec3
},
reflect::Reflect, window::Window,
};
use bevy::prelude::ButtonInput;
use bevy_egui::EguiContexts;

use crate::{lock_on::LockOn, physics::apply_physics, SimState};
Expand Down Expand Up @@ -48,7 +49,7 @@ pub fn pan_orbit_camera(
mut windows: Query<&mut Window>,
mut ev_motion: EventReader<MouseMotion>,
mut ev_scroll: EventReader<MouseWheel>,
input_mouse: Res<Input<MouseButton>>,
input_mouse: Res<ButtonInput<MouseButton>>,
mut query: Query<(&mut PanOrbitCamera, &mut Transform, &Projection)>,
mut lock_on: ResMut<LockOn>,
mut egui_ctx: EguiContexts,
Expand Down
12 changes: 6 additions & 6 deletions src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn debug_window(
.scroll2([true, true])
.default_width(250.0)
.show(egui_ctx.ctx_mut(), |ui| {
if let Some(fps) = diagnostics.get(FrameTimeDiagnosticsPlugin::FPS) {
if let Some(fps) = diagnostics.get(&FrameTimeDiagnosticsPlugin::FPS) {
if let Some(value) = fps.smoothed() {
// Update the value of the second section
ui.horizontal(|ui| {
Expand All @@ -57,7 +57,7 @@ fn debug_window(
});
}
}
if let Some(frametime) = diagnostics.get(FrameTimeDiagnosticsPlugin::FRAME_TIME) {
if let Some(frametime) = diagnostics.get(&FrameTimeDiagnosticsPlugin::FRAME_TIME) {
if let Some(value) = frametime.smoothed() {
// Update the value of the second section
ui.horizontal(|ui| {
Expand All @@ -66,7 +66,7 @@ fn debug_window(
});
}
}
if let Some(frametime) = diagnostics.get(FrameTimeDiagnosticsPlugin::FRAME_COUNT) {
if let Some(frametime) = diagnostics.get(&FrameTimeDiagnosticsPlugin::FRAME_COUNT) {
if let Some(value) = frametime.value() {
// Update the value of the second section
ui.horizontal(|ui| {
Expand All @@ -80,7 +80,7 @@ fn debug_window(
ui.label(RichText::new("Total amount of bodies: ").strong());
ui.label(format!("{:?}", body_count));
});
if let Some(frametime) = diagnostics.get(NBODY_STEPS) {
if let Some(frametime) = diagnostics.get(&NBODY_STEPS) {
if let Some(value) = frametime.smoothed() {
// Update the value of the second section
ui.horizontal(|ui| {
Expand All @@ -89,7 +89,7 @@ fn debug_window(
});
}
}
if let Some(frametime) = diagnostics.get(NBODY_STEP_TIME) {
if let Some(frametime) = diagnostics.get(&NBODY_STEP_TIME) {
if let Some(value) = frametime.average() {
// Update the value of the second section
ui.horizontal(|ui| {
Expand All @@ -98,7 +98,7 @@ fn debug_window(
});
}
}
if let Some(frametime) = diagnostics.get(NBODY_TOTAL_TIME) {
if let Some(frametime) = diagnostics.get(&NBODY_TOTAL_TIME) {
if let Some(value) = frametime.average() {
// Update the value of the second section
ui.horizontal(|ui| {
Expand Down
12 changes: 6 additions & 6 deletions src/direction.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy::{app::{App, Plugin}, prelude::{Color, Entity, Gizmos, in_state, IntoSystemConfigs, Query, Transform, Update, With}};

use crate::{arrows::ArrowGizmos, body::{BodyChildren, Diameter, Moon, OrbitSettings, Planet, Velocity}, camera::pan_orbit_camera, SimState};
use bevy::color::palettes::css;
use crate::{body::{BodyChildren, Diameter, Moon, OrbitSettings, Planet, Velocity}, camera::pan_orbit_camera, SimState};

pub struct DirectionPlugin;

Expand All @@ -20,19 +20,19 @@ fn display_force_and_velocity(
) {
for (transform, _, orbit, diameter, velocity) in &planet_query {
if orbit.display_force {
gizmos.arrow(transform.translation, transform.translation + (orbit.force_direction * diameter.num as f64 * orbit.arrow_scale as f64).as_vec3(), Color::BLUE);
gizmos.arrow(transform.translation, transform.translation + (orbit.force_direction * diameter.num as f64 * orbit.arrow_scale as f64).as_vec3(), css::BLUE);
}
if orbit.display_velocity {
gizmos.arrow(transform.translation, transform.translation +(velocity.0.normalize() * diameter.num as f64 * orbit.arrow_scale as f64).as_vec3(), Color::RED);
gizmos.arrow(transform.translation, transform.translation +(velocity.0.normalize() * diameter.num as f64 * orbit.arrow_scale as f64).as_vec3(), css::RED);
}
}
for (entity, transform, orbit, diameter, velocity) in &moon_query {
if orbit.display_force {
gizmos.arrow(transform.translation, transform.translation +(orbit.force_direction * diameter.num as f64 * orbit.arrow_scale as f64).as_vec3(), Color::BLUE);
gizmos.arrow(transform.translation, transform.translation +(orbit.force_direction * diameter.num as f64 * orbit.arrow_scale as f64).as_vec3(), css::BLUE);
}
if orbit.display_velocity {
if let Some((_, _, _, _, vel)) = planet_query.iter().find(|(_, ch, _, _, _)| ch.0.contains(&entity)) {
gizmos.arrow(transform.translation, transform.translation +((velocity.0 - vel.0).normalize() * diameter.num as f64 * orbit.arrow_scale as f64).as_vec3(), Color::RED);
gizmos.arrow(transform.translation, transform.translation +((velocity.0 - vel.0).normalize() * diameter.num as f64 * orbit.arrow_scale as f64).as_vec3(), css::RED);
}
}
}
Expand Down
14 changes: 8 additions & 6 deletions src/egui_input_block.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bevy::{input::InputSystem, prelude::{Input, KeyCode, MouseButton, Plugin, Res, ResMut, Resource}};
use bevy::{input::InputSystem, prelude::{KeyCode, MouseButton, Plugin, Res, ResMut, Resource}};
use bevy::app::{PostUpdate, PreUpdate};
use bevy::prelude::IntoSystemConfigs;
use bevy::prelude::{ButtonInput, IntoSystemConfigs};
use bevy_egui::{EguiContexts, EguiSet};

//Block input when hovering over egui interfaces
Expand Down Expand Up @@ -28,14 +28,16 @@ impl Plugin for BlockInputPlugin {
}

fn egui_wants_input(mut state: ResMut<EguiBlockInputState>, mut contexts: EguiContexts) {
state.wants_keyboard_input = contexts.ctx_mut().wants_keyboard_input();
state.wants_pointer_input = contexts.ctx_mut().wants_pointer_input();
if let Some(ctx) = contexts.try_ctx_mut() {
state.wants_keyboard_input = ctx.wants_keyboard_input();
state.wants_pointer_input = ctx.wants_pointer_input();
}
}

fn egui_block_input(
state: Res<EguiBlockInputState>,
mut keys: ResMut<Input<KeyCode>>,
mut mouse_buttons: ResMut<Input<MouseButton>>,
mut keys: ResMut<ButtonInput<KeyCode>>,
mut mouse_buttons: ResMut<ButtonInput<MouseButton>>,
) {
if state.wants_keyboard_input {
keys.reset_all();
Expand Down
13 changes: 7 additions & 6 deletions src/input.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use bevy::{prelude::{App, in_state, Input, IntoSystemConfigs, KeyCode, Plugin, Query, Res, ResMut, Update, Vec3}, window::{Window, WindowMode}};
use bevy::{prelude::{App, in_state, IntoSystemConfigs, KeyCode, Plugin, Query, Res, ResMut, Update, Vec3}, window::{Window, WindowMode}};
use bevy::prelude::ButtonInput;
use bevy_egui::{egui::{self}, EguiContexts, EguiSettings};

use crate::{camera::PanOrbitCamera, SimState, ui::{UiState, StepType}, physics::{Pause, SubSteps}, speed::Speed};
Expand Down Expand Up @@ -45,7 +46,7 @@ fn key_window(
}

fn global_input_system(
keys: Res<Input<KeyCode>>,
keys: Res<ButtonInput<KeyCode>>,
mut windows: Query<&mut Window>,
) {
if keys.just_pressed(KeyCode::F11) {
Expand All @@ -60,7 +61,7 @@ fn global_input_system(
}

fn sim_input_system(
keys: Res<Input<KeyCode>>,
keys: Res<ButtonInput<KeyCode>>,
mut ui_state: ResMut<UiState>,
mut camera: Query<&mut PanOrbitCamera>,
mut pause: ResMut<Pause>,
Expand All @@ -74,17 +75,17 @@ fn sim_input_system(
};
if keys.just_pressed(KeyCode::F10) {
ui_state.visible = !ui_state.visible
} else if keys.just_pressed(KeyCode::C) {
} else if keys.just_pressed(KeyCode::KeyC) {
camera.single_mut().focus = Vec3::ZERO;
} else if keys.just_pressed(KeyCode::Space) {
pause.0 = !pause.0;
} else if keys.just_pressed(KeyCode::Left) {
} else if keys.just_pressed(KeyCode::ArrowLeft) {
if timestep_selected {
speed.small_step_down();
} else {
sub_steps.small_step_down();
}
} else if keys.just_pressed(KeyCode::Right) {
} else if keys.just_pressed(KeyCode::ArrowRight) {
if timestep_selected {
speed.small_step_up();
} else {
Expand Down
Loading

0 comments on commit ec54a49

Please sign in to comment.