pause physics + bevy systems in menu or when window is defocused
This commit is contained in:
parent
7b6282d13b
commit
de9b8d99e8
26
src/actor.rs
26
src/actor.rs
|
@ -35,29 +35,35 @@ impl Plugin for ActorPlugin {
|
|||
app.add_systems(
|
||||
FixedUpdate,
|
||||
(
|
||||
update_physics_lifeforms,
|
||||
update_power,
|
||||
handle_gravity,
|
||||
handle_wants_maxrotation,
|
||||
handle_wants_maxvelocity.run_if(any_with_component::<WantsMaxVelocity>),
|
||||
handle_wants_lookat.run_if(alive),
|
||||
update_physics_lifeforms.run_if(game_running),
|
||||
update_power.run_if(game_running),
|
||||
handle_gravity.run_if(game_running),
|
||||
handle_wants_maxrotation.run_if(game_running),
|
||||
handle_wants_maxvelocity
|
||||
.run_if(game_running)
|
||||
.run_if(any_with_component::<WantsMaxVelocity>),
|
||||
handle_wants_lookat.run_if(game_running).run_if(alive),
|
||||
),
|
||||
);
|
||||
app.add_systems(
|
||||
PostUpdate,
|
||||
handle_gforce
|
||||
.run_if(game_running)
|
||||
.after(PhysicsSet::Sync)
|
||||
.after(sync::position_to_transform),
|
||||
);
|
||||
app.add_systems(
|
||||
Update,
|
||||
(
|
||||
handle_input.run_if(in_control),
|
||||
handle_collisions,
|
||||
handle_damage,
|
||||
handle_input.run_if(in_control).run_if(game_running),
|
||||
handle_collisions.run_if(game_running),
|
||||
handle_damage.run_if(game_running),
|
||||
),
|
||||
);
|
||||
app.add_systems(PostUpdate, (handle_vehicle_enter_exit,));
|
||||
app.add_systems(
|
||||
PostUpdate,
|
||||
(handle_vehicle_enter_exit.run_if(game_running),),
|
||||
);
|
||||
app.add_event::<VehicleEnterExitEvent>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,15 +32,23 @@ pub struct CameraPlugin;
|
|||
impl Plugin for CameraPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, setup_camera);
|
||||
app.add_systems(Update, handle_input.run_if(in_control));
|
||||
app.add_systems(Update, update_map_only_object_visibility.run_if(alive));
|
||||
app.add_systems(Update, handle_input.run_if(in_control).run_if(game_running));
|
||||
app.add_systems(
|
||||
Update,
|
||||
update_map_only_object_visibility
|
||||
.run_if(alive)
|
||||
.run_if(game_running),
|
||||
);
|
||||
app.add_systems(
|
||||
PostUpdate,
|
||||
manage_player_actor.in_set(sync::SyncSet::PositionToTransform),
|
||||
manage_player_actor
|
||||
.run_if(game_running)
|
||||
.in_set(sync::SyncSet::PositionToTransform),
|
||||
);
|
||||
app.add_systems(
|
||||
PostUpdate,
|
||||
sync_camera_to_player
|
||||
.run_if(game_running)
|
||||
.after(PhysicsSet::Sync)
|
||||
.after(apply_input_to_player)
|
||||
.before(TransformSystem::TransformPropagate),
|
||||
|
@ -48,12 +56,16 @@ impl Plugin for CameraPlugin {
|
|||
app.add_systems(
|
||||
PostUpdate,
|
||||
update_mapcam_center
|
||||
.run_if(game_running)
|
||||
.before(sync::position_to_transform)
|
||||
.in_set(sync::SyncSet::PositionToTransform),
|
||||
);
|
||||
app.add_systems(Update, update_map_camera.run_if(in_control));
|
||||
app.add_systems(Update, update_fov.run_if(alive));
|
||||
app.add_systems(PreUpdate, apply_input_to_player);
|
||||
app.add_systems(
|
||||
Update,
|
||||
update_map_camera.run_if(in_control).run_if(game_running),
|
||||
);
|
||||
app.add_systems(Update, update_fov.run_if(alive).run_if(game_running));
|
||||
app.add_systems(PreUpdate, apply_input_to_player.run_if(game_running));
|
||||
app.insert_resource(MapCam::default());
|
||||
|
||||
// To center the renderer origin on the player camera,
|
||||
|
@ -66,6 +78,7 @@ impl Plugin for CameraPlugin {
|
|||
app.add_systems(
|
||||
PostUpdate,
|
||||
position_to_transform
|
||||
.run_if(game_running)
|
||||
.after(sync::position_to_transform)
|
||||
.in_set(sync::SyncSet::PositionToTransform),
|
||||
);
|
||||
|
|
20
src/chat.rs
20
src/chat.rs
|
@ -75,12 +75,20 @@ impl Plugin for ChatPlugin {
|
|||
app.add_systems(
|
||||
Update,
|
||||
(
|
||||
handle_reply_keys.before(handle_chat_timer),
|
||||
handle_chat_timer.before(handle_chat_events),
|
||||
handle_new_conversations.before(handle_chat_events),
|
||||
handle_chat_events.before(handle_chat_scripts),
|
||||
handle_chat_scripts,
|
||||
update_chat_variables,
|
||||
handle_reply_keys
|
||||
.run_if(game_running)
|
||||
.before(handle_chat_timer),
|
||||
handle_chat_timer
|
||||
.run_if(game_running)
|
||||
.before(handle_chat_events),
|
||||
handle_new_conversations
|
||||
.run_if(game_running)
|
||||
.before(handle_chat_events),
|
||||
handle_chat_events
|
||||
.run_if(game_running)
|
||||
.before(handle_chat_scripts),
|
||||
handle_chat_scripts.run_if(game_running),
|
||||
update_chat_variables.run_if(game_running),
|
||||
),
|
||||
);
|
||||
app.add_event::<StartConversationEvent>();
|
||||
|
|
14
src/cmd.rs
14
src/cmd.rs
|
@ -29,15 +29,21 @@ impl Plugin for CmdPlugin {
|
|||
app.add_systems(
|
||||
Update,
|
||||
handle_spawn_events
|
||||
.run_if(game_running)
|
||||
.before(spawn_entities)
|
||||
.before(spawn_scenes),
|
||||
);
|
||||
app.add_systems(Update, spawn_entities);
|
||||
app.add_systems(Update, spawn_scenes.after(spawn_entities));
|
||||
app.add_systems(Update, process_mesh);
|
||||
app.add_systems(Update, spawn_entities.run_if(game_running));
|
||||
app.add_systems(
|
||||
Update,
|
||||
spawn_scenes.run_if(game_running).after(spawn_entities),
|
||||
);
|
||||
app.add_systems(Update, process_mesh.run_if(game_running));
|
||||
app.add_systems(
|
||||
PreUpdate,
|
||||
hide_colliders.run_if(any_with_component::<NeedsSceneColliderRemoved>),
|
||||
hide_colliders
|
||||
.run_if(game_running)
|
||||
.run_if(any_with_component::<NeedsSceneColliderRemoved>),
|
||||
);
|
||||
app.add_event::<SpawnEvent>();
|
||||
app.add_event::<SpawnActorEvent>();
|
||||
|
|
|
@ -72,6 +72,10 @@ pub fn in_control(settings: Res<Settings>) -> bool {
|
|||
return settings.in_control();
|
||||
}
|
||||
|
||||
pub fn game_running(settings: Res<Settings>) -> bool {
|
||||
return settings.is_game_running();
|
||||
}
|
||||
|
||||
pub fn in_shadow(
|
||||
light_source_pos: DVec3,
|
||||
light_source_r: f64,
|
||||
|
|
36
src/game.rs
36
src/game.rs
|
@ -26,20 +26,28 @@ pub struct GamePlugin;
|
|||
impl Plugin for GamePlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, setup);
|
||||
app.add_systems(Update, handle_cheats.run_if(in_control));
|
||||
app.add_systems(Update, debug);
|
||||
app.add_systems(
|
||||
Update,
|
||||
handle_cheats.run_if(game_running).run_if(in_control),
|
||||
);
|
||||
app.add_systems(Update, debug.run_if(game_running));
|
||||
app.add_systems(PostUpdate, handle_game_event);
|
||||
app.add_systems(PreUpdate, handle_player_death);
|
||||
app.add_systems(Update, handle_window_focus);
|
||||
app.add_systems(PreUpdate, handle_player_death.run_if(game_running));
|
||||
app.add_systems(
|
||||
PostUpdate,
|
||||
update_id2pos.in_set(bevy_xpbd_3d::plugins::sync::SyncSet::PositionToTransform),
|
||||
update_id2pos
|
||||
.run_if(game_running)
|
||||
.in_set(bevy_xpbd_3d::plugins::sync::SyncSet::PositionToTransform),
|
||||
);
|
||||
app.add_systems(PostUpdate, update_id2v);
|
||||
app.add_systems(
|
||||
Update,
|
||||
handle_achievement_event.run_if(on_event::<AchievementEvent>()),
|
||||
handle_achievement_event
|
||||
.run_if(game_running)
|
||||
.run_if(on_event::<AchievementEvent>()),
|
||||
);
|
||||
app.add_systems(Update, check_achievements);
|
||||
app.add_systems(Update, check_achievements.run_if(game_running));
|
||||
app.insert_resource(Id2Pos(HashMap::new()));
|
||||
app.insert_resource(Id2V(HashMap::new()));
|
||||
app.insert_resource(JupiterPos(DVec3::ZERO));
|
||||
|
@ -609,3 +617,19 @@ fn check_achievements(
|
|||
ew_achievement.send(AchievementEvent::InJupitersShadow);
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_window_focus(
|
||||
mut settings: ResMut<Settings>,
|
||||
mut er_focus: EventReader<bevy::window::WindowFocused>,
|
||||
mut physicstime: ResMut<Time<Physics>>,
|
||||
) {
|
||||
for event in er_focus.read() {
|
||||
settings.window_focused = event.focused;
|
||||
}
|
||||
|
||||
if settings.is_game_running() {
|
||||
physicstime.unpause();
|
||||
} else {
|
||||
physicstime.pause();
|
||||
}
|
||||
}
|
||||
|
|
21
src/hud.rs
21
src/hud.rs
|
@ -57,26 +57,31 @@ impl Plugin for HudPlugin {
|
|||
app.add_systems(
|
||||
Update,
|
||||
(
|
||||
update_hud,
|
||||
update_dashboard,
|
||||
update_speedometer,
|
||||
update_gauges,
|
||||
handle_input.run_if(in_control),
|
||||
handle_target_event,
|
||||
update_hud.run_if(game_running),
|
||||
update_dashboard.run_if(game_running),
|
||||
update_speedometer.run_if(game_running),
|
||||
update_gauges.run_if(game_running),
|
||||
handle_input.run_if(game_running).run_if(in_control),
|
||||
handle_target_event.run_if(game_running),
|
||||
),
|
||||
);
|
||||
app.add_systems(
|
||||
PostUpdate,
|
||||
(
|
||||
update_overlay_visibility,
|
||||
update_avatar.run_if(on_event::<UpdateAvatarEvent>()),
|
||||
update_overlay_visibility.run_if(game_running),
|
||||
update_avatar
|
||||
.run_if(game_running)
|
||||
.run_if(on_event::<UpdateAvatarEvent>()),
|
||||
update_ar_overlays
|
||||
.run_if(game_running)
|
||||
.after(camera::position_to_transform)
|
||||
.in_set(sync::SyncSet::PositionToTransform),
|
||||
update_poi_overlays
|
||||
.run_if(game_running)
|
||||
.after(camera::position_to_transform)
|
||||
.in_set(sync::SyncSet::PositionToTransform),
|
||||
update_target_selectagon
|
||||
.run_if(game_running)
|
||||
.after(PhysicsSet::Sync)
|
||||
.after(camera::apply_input_to_player)
|
||||
.before(TransformSystem::TransformPropagate),
|
||||
|
|
|
@ -39,6 +39,7 @@ pub struct Settings {
|
|||
pub god_mode: bool,
|
||||
pub version: String,
|
||||
pub alive: bool,
|
||||
pub window_focused: bool,
|
||||
pub mute_sfx: bool,
|
||||
pub noise_cancellation_mode: usize,
|
||||
pub noise_cancellation_modes: Vec<(String, f32)>,
|
||||
|
@ -171,6 +172,7 @@ impl Default for Settings {
|
|||
god_mode: false,
|
||||
version,
|
||||
alive: true,
|
||||
window_focused: true,
|
||||
mute_sfx: false,
|
||||
noise_cancellation_mode: 0,
|
||||
noise_cancellation_modes: vec![
|
||||
|
@ -308,6 +310,10 @@ impl Settings {
|
|||
*self = Self::default();
|
||||
}
|
||||
|
||||
pub fn is_game_running(&self) -> bool {
|
||||
!self.menu_active && self.window_focused
|
||||
}
|
||||
|
||||
pub fn reset_player_settings(&mut self) {
|
||||
println!("Resetting player settings!");
|
||||
let default = Self::default();
|
||||
|
|
|
@ -22,14 +22,17 @@ impl Plugin for VisualPlugin {
|
|||
app.add_systems(Startup, setup.after(menu::setup).after(hud::setup));
|
||||
app.add_systems(
|
||||
Startup,
|
||||
spawn_effects.after(setup).after(camera::setup_camera),
|
||||
spawn_effects
|
||||
.run_if(game_running)
|
||||
.after(setup)
|
||||
.after(camera::setup_camera),
|
||||
);
|
||||
app.add_systems(Update, spawn_effects);
|
||||
app.add_systems(Update, update_fadein);
|
||||
app.add_systems(Update, update_fadeout);
|
||||
app.add_systems(Update, update_fade_material);
|
||||
app.add_systems(Update, update_grow);
|
||||
app.add_systems(Update, play_animations);
|
||||
app.add_systems(Update, spawn_effects.run_if(game_running));
|
||||
app.add_systems(Update, update_fadein.run_if(game_running));
|
||||
app.add_systems(Update, update_fadeout.run_if(game_running));
|
||||
app.add_systems(Update, update_fade_material.run_if(game_running));
|
||||
app.add_systems(Update, update_grow.run_if(game_running));
|
||||
app.add_systems(Update, play_animations.run_if(game_running));
|
||||
// Blackout disabled for now
|
||||
//app.add_systems(Update, update_blackout);
|
||||
app.add_event::<SpawnEffectEvent>();
|
||||
|
|
15
src/world.rs
15
src/world.rs
|
@ -37,10 +37,17 @@ pub struct WorldPlugin;
|
|||
impl Plugin for WorldPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, setup);
|
||||
app.add_systems(Update, handle_respawn.run_if(on_event::<RespawnEvent>()));
|
||||
app.add_systems(
|
||||
Update,
|
||||
handle_despawn_at.run_if(any_with_component::<DespawnAt>),
|
||||
handle_respawn
|
||||
.run_if(game_running)
|
||||
.run_if(on_event::<RespawnEvent>()),
|
||||
);
|
||||
app.add_systems(
|
||||
Update,
|
||||
handle_despawn_at
|
||||
.run_if(game_running)
|
||||
.run_if(any_with_component::<DespawnAt>),
|
||||
);
|
||||
app.add_plugins(PhysicsPlugins::default());
|
||||
//app.add_plugins(PhysicsDebugPlugin::default());
|
||||
|
@ -52,8 +59,8 @@ impl Plugin for WorldPlugin {
|
|||
ASTEROID_UPDATE_INTERVAL,
|
||||
TimerMode::Repeating,
|
||||
)));
|
||||
app.add_systems(Update, spawn_despawn_asteroids);
|
||||
app.add_systems(PostUpdate, handle_despawn_asteroids);
|
||||
app.add_systems(Update, spawn_despawn_asteroids.run_if(game_running));
|
||||
app.add_systems(PostUpdate, handle_despawn_asteroids.run_if(game_running));
|
||||
app.add_event::<DespawnAsteroidEvent>();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue