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 bevy::{
|
||||
prelude::*,
|
||||
tasks::ParallelIterator,
|
||||
utils::{HashMap, HashSet},
|
||||
};
|
||||
use bevy_spatial::{kdtree::KDTree3, SpatialAccess};
|
||||
|
@ -80,12 +79,7 @@ pub fn update_vel(
|
|||
time: Res<Time>,
|
||||
positions: Res<Positions>,
|
||||
index: Res<NNTree>,
|
||||
paused: Res<Paused>,
|
||||
) {
|
||||
if **paused {
|
||||
return;
|
||||
}
|
||||
|
||||
let dt = time.delta_secs();
|
||||
let max_delta = MAX_DELTA_V * dt;
|
||||
toids
|
||||
|
@ -160,12 +154,7 @@ pub fn update_pos(
|
|||
mut positions: ResMut<Positions>,
|
||||
mut lookat: ResMut<LookAt>,
|
||||
time: Res<Time>,
|
||||
paused: Res<Paused>,
|
||||
) {
|
||||
if **paused {
|
||||
return;
|
||||
}
|
||||
|
||||
let mut new_look = Vec3::ZERO;
|
||||
let dt = time.delta_secs();
|
||||
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())
|
||||
.add_systems(Startup, (setup, setup_ambient_light))
|
||||
//.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))
|
||||
.run();
|
||||
}
|
||||
|
@ -42,12 +45,11 @@ fn setup(
|
|||
models: Res<AssetServer>,
|
||||
) {
|
||||
let rand = &mut rand::thread_rng();
|
||||
let cam = Camera3d::default();
|
||||
|
||||
let camera = commands
|
||||
.spawn((
|
||||
Transform::from_xyz(0., 5.0, 25.).looking_at(Vec3::new(0.0, 5.0, 0.0), Vec3::Y),
|
||||
cam,
|
||||
Camera3d::default(),
|
||||
Visibility::Hidden,
|
||||
))
|
||||
.id();
|
||||
|
@ -67,7 +69,8 @@ fn setup(
|
|||
// instructions
|
||||
commands.spawn((
|
||||
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,
|
||||
..Default::default()
|
||||
},
|
||||
|
@ -100,3 +103,7 @@ fn close_on_esc(
|
|||
fn setup_ambient_light(mut ambient_light: ResMut<AmbientLight>) {
|
||||
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