Skip to content

Commit

Permalink
Adding functionality for pausing
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-tennert committed Oct 13, 2023
1 parent 7b485c0 commit 96b8d5e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 1 addition & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ runner = "wasm-server-runner"

[dependencies]
#bevy = { git = "https://github.com/bevyengine/bevy", branch = "release-0.11.3", features = ["dynamic_linking"] }
bevy = { version = "0.11.3" }
bevy = { version = "0.11.3", features = ["dynamic_linking"] }
bevy_easings = "0.11.1"
#bevy_panorbit_camera = { git = "https://github.com/jan-tennert/bevy_panorbit_camera", rev = "7e3c3f8" }
bevy-inspector-egui = { version = "0.20", default-features = false }
Expand All @@ -25,22 +25,6 @@ bevy_egui = "0.22"
chrono = "0.4.23"
itertools = "0.11.0"

[profile.wasm-release]
# Use release profile as default values
inherits = "release"

# Optimize with size in mind, also try "s", sometimes it is better.
# This doesn't increase compilation times compared to -O3, great improvements
opt-level = "z"

# Do a second optimization pass removing duplicate or unused code from dependencies.
# Slows compile times, marginal improvements
lto = "fat"

# When building crates, optimize larger chunks at a time
# Slows compile times, marginal improvements
codegen-units = 1

[patch.crates-io]
bevy = { git = "https://github.com/jan-tennert/bevy", branch = "skybox-fix" }
bevy_ecs = { git = "https://github.com/jan-tennert/bevy", branch = "skybox-fix" }
Expand Down
16 changes: 14 additions & 2 deletions src/physics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ pub struct Pause(pub bool);

fn update_acceleration(
mut query: Query<(&Mass, &mut Acceleration, &SimPosition)>,
pause: Res<Pause>
) {
if pause.0 {
return;
}
let mut other_bodies: Vec<(&Mass, Mut<Acceleration>, &SimPosition)> = Vec::new();
for (mass, mut acc, sim_pos) in query.iter_mut() {
acc.0 = DVec3::ZERO;
Expand All @@ -56,8 +60,12 @@ fn update_acceleration(
fn update_velocity(
mut query: Query<(&mut Velocity, &Acceleration)>,
time: Res<Time>,
speed: Res<Speed>
speed: Res<Speed>,
pause: Res<Pause>
) {
if pause.0 {
return;
}
for (mut vel, acc) in query.iter_mut() {
vel.0 += acc.0 * time.delta_seconds() as f64 * speed.0;
}
Expand All @@ -68,8 +76,12 @@ pub fn update_position(
time: Res<Time>,
speed: Res<Speed>,
selected_entity: Res<SelectedEntity>,
mut gizmos: Gizmos
mut gizmos: Gizmos,
pause: Res<Pause>
) {
if pause.0 {
return;
}
let delta_time = time.delta_seconds() as f64;
// Calculate the offset based on the selected entity's position
let offset = match selected_entity.0 {
Expand Down
2 changes: 1 addition & 1 deletion src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub fn time_ui(
date.format("%d.%m.%Y"),
speed.format()
));
let time_text = if pause.0 { "Pause" } else { "Resume" };
let time_text = if !pause.0 { "Pause" } else { "Resume" };
if ui.button(time_text).clicked() || keys.just_pressed(KeyCode::Space) {
pause.0 = !pause.0;
}
Expand Down

0 comments on commit 96b8d5e

Please sign in to comment.