use run condition for pausing
This commit is contained in:
parent
80b2ca1893
commit
7d9651bca0
2 changed files with 11 additions and 15 deletions
11
src/lib.rs
11
src/lib.rs
|
@ -1,7 +1,6 @@
|
||||||
use argh::FromArgs;
|
use argh::FromArgs;
|
||||||
use bevy::{
|
use bevy::{
|
||||||
prelude::*,
|
prelude::*,
|
||||||
tasks::ParallelIterator,
|
|
||||||
utils::{HashMap, HashSet},
|
utils::{HashMap, HashSet},
|
||||||
};
|
};
|
||||||
use bevy_spatial::{kdtree::KDTree3, SpatialAccess};
|
use bevy_spatial::{kdtree::KDTree3, SpatialAccess};
|
||||||
|
@ -80,12 +79,7 @@ pub fn update_vel(
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
positions: Res<Positions>,
|
positions: Res<Positions>,
|
||||||
index: Res<NNTree>,
|
index: Res<NNTree>,
|
||||||
paused: Res<Paused>,
|
|
||||||
) {
|
) {
|
||||||
if **paused {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let dt = time.delta_secs();
|
let dt = time.delta_secs();
|
||||||
let max_delta = MAX_DELTA_V * dt;
|
let max_delta = MAX_DELTA_V * dt;
|
||||||
toids
|
toids
|
||||||
|
@ -160,12 +154,7 @@ pub fn update_pos(
|
||||||
mut positions: ResMut<Positions>,
|
mut positions: ResMut<Positions>,
|
||||||
mut lookat: ResMut<LookAt>,
|
mut lookat: ResMut<LookAt>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
paused: Res<Paused>,
|
|
||||||
) {
|
) {
|
||||||
if **paused {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut new_look = Vec3::ZERO;
|
let mut new_look = Vec3::ZERO;
|
||||||
let dt = time.delta_secs();
|
let dt = time.delta_secs();
|
||||||
for (mut xform, vel, entity) in toids.iter_mut() {
|
for (mut xform, vel, entity) in toids.iter_mut() {
|
||||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -29,7 +29,10 @@ fn main() {
|
||||||
.insert_resource(Paused::default())
|
.insert_resource(Paused::default())
|
||||||
.add_systems(Startup, (setup, setup_ambient_light))
|
.add_systems(Startup, (setup, setup_ambient_light))
|
||||||
//.add_systems(Update, update_gizmos)
|
//.add_systems(Update, update_gizmos)
|
||||||
.add_systems(Update, (update_pos, update_buddies, update_vel))
|
.add_systems(
|
||||||
|
Update,
|
||||||
|
(update_pos, update_buddies, update_vel).run_if(not_paused),
|
||||||
|
)
|
||||||
.add_systems(Update, (rotate_camera, close_on_esc))
|
.add_systems(Update, (rotate_camera, close_on_esc))
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
@ -42,12 +45,11 @@ fn setup(
|
||||||
models: Res<AssetServer>,
|
models: Res<AssetServer>,
|
||||||
) {
|
) {
|
||||||
let rand = &mut rand::thread_rng();
|
let rand = &mut rand::thread_rng();
|
||||||
let cam = Camera3d::default();
|
|
||||||
|
|
||||||
let camera = commands
|
let camera = commands
|
||||||
.spawn((
|
.spawn((
|
||||||
Transform::from_xyz(0., 5.0, 25.).looking_at(Vec3::new(0.0, 5.0, 0.0), Vec3::Y),
|
Transform::from_xyz(0., 5.0, 25.).looking_at(Vec3::new(0.0, 5.0, 0.0), Vec3::Y),
|
||||||
cam,
|
Camera3d::default(),
|
||||||
Visibility::Hidden,
|
Visibility::Hidden,
|
||||||
))
|
))
|
||||||
.id();
|
.id();
|
||||||
|
@ -67,7 +69,8 @@ fn setup(
|
||||||
// instructions
|
// instructions
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
Text::new(
|
Text::new(
|
||||||
"Up and down for camera forward and back; hold shift to change height.\nLeft or right to move left or right.\nPress 'ESC' to quit; SPACE to pause."), TextFont {
|
"Up and down for camera forward and back; hold shift to change height.\nLeft or right to move left or right.\nPress 'ESC' to quit; SPACE to pause."),
|
||||||
|
TextFont {
|
||||||
font_size: 20.0,
|
font_size: 20.0,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
@ -100,3 +103,7 @@ fn close_on_esc(
|
||||||
fn setup_ambient_light(mut ambient_light: ResMut<AmbientLight>) {
|
fn setup_ambient_light(mut ambient_light: ResMut<AmbientLight>) {
|
||||||
ambient_light.brightness = 100.0;
|
ambient_light.brightness = 100.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn not_paused(paused: Option<Res<Paused>>) -> bool {
|
||||||
|
!paused.map(|p| **p).unwrap_or(false)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue