Converted exclusive systems to parallel systems wherever possible (#2774)
Closes #2767. Converted: - `play_queued_audio_system` - `change_window`
This commit is contained in:
parent
9b1651afa1
commit
5155034a58
@ -1,6 +1,6 @@
|
||||
use crate::{Audio, AudioSource, Decodable};
|
||||
use bevy_asset::{Asset, Assets};
|
||||
use bevy_ecs::world::World;
|
||||
use bevy_ecs::system::{NonSend, Res, ResMut};
|
||||
use bevy_reflect::TypeUuid;
|
||||
use bevy_utils::tracing::warn;
|
||||
use rodio::{OutputStream, OutputStreamHandle, Sink, Source};
|
||||
@ -85,16 +85,13 @@ where
|
||||
}
|
||||
|
||||
/// Plays audio currently queued in the [`Audio`] resource through the [`AudioOutput`] resource
|
||||
pub fn play_queued_audio_system<Source: Asset>(world: &mut World)
|
||||
where
|
||||
Source: Decodable,
|
||||
{
|
||||
let world = world.cell();
|
||||
let audio_output = world.get_non_send::<AudioOutput<Source>>().unwrap();
|
||||
let mut audio = world.get_resource_mut::<Audio<Source>>().unwrap();
|
||||
let mut sinks = world.get_resource_mut::<Assets<AudioSink>>().unwrap();
|
||||
|
||||
if let Some(audio_sources) = world.get_resource::<Assets<Source>>() {
|
||||
pub fn play_queued_audio_system<Source: Asset + Decodable>(
|
||||
audio_output: NonSend<AudioOutput<Source>>,
|
||||
audio_sources: Option<Res<Assets<Source>>>,
|
||||
mut audio: ResMut<Audio<Source>>,
|
||||
mut sinks: ResMut<Assets<AudioSink>>,
|
||||
) {
|
||||
if let Some(audio_sources) = audio_sources {
|
||||
audio_output.try_play_queued(&*audio_sources, &mut *audio, &mut *sinks);
|
||||
};
|
||||
}
|
||||
|
@ -44,7 +44,6 @@ pub use audio_source::*;
|
||||
|
||||
use bevy_app::prelude::*;
|
||||
use bevy_asset::AddAsset;
|
||||
use bevy_ecs::system::IntoExclusiveSystem;
|
||||
|
||||
/// Adds support for audio playback to a Bevy Application
|
||||
///
|
||||
@ -60,7 +59,7 @@ impl Plugin for AudioPlugin {
|
||||
.init_resource::<Audio<AudioSource>>()
|
||||
.add_system_to_stage(
|
||||
CoreStage::PostUpdate,
|
||||
play_queued_audio_system::<AudioSource>.exclusive_system(),
|
||||
play_queued_audio_system::<AudioSource>,
|
||||
);
|
||||
|
||||
#[cfg(any(feature = "mp3", feature = "flac", feature = "wav", feature = "vorbis"))]
|
||||
|
@ -14,6 +14,8 @@ pub use material::*;
|
||||
pub use pbr_material::*;
|
||||
pub use render::*;
|
||||
|
||||
use bevy_window::ModifiesWindows;
|
||||
|
||||
pub mod prelude {
|
||||
#[doc(hidden)]
|
||||
pub use crate::{
|
||||
@ -86,7 +88,8 @@ impl Plugin for PbrPlugin {
|
||||
CoreStage::PostUpdate,
|
||||
assign_lights_to_clusters
|
||||
.label(SimulationLightSystems::AssignLightsToClusters)
|
||||
.after(TransformSystem::TransformPropagate),
|
||||
.after(TransformSystem::TransformPropagate)
|
||||
.after(ModifiesWindows),
|
||||
)
|
||||
.add_system_to_stage(
|
||||
CoreStage::PostUpdate,
|
||||
|
@ -12,6 +12,8 @@ use crate::{
|
||||
view::{ComputedVisibility, Visibility, VisibleEntities},
|
||||
};
|
||||
use bevy_app::{App, CoreStage, Plugin};
|
||||
use bevy_ecs::schedule::ParallelSystemDescriptorCoercion;
|
||||
use bevy_window::ModifiesWindows;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct CameraPlugin;
|
||||
@ -32,11 +34,11 @@ impl Plugin for CameraPlugin {
|
||||
.register_type::<Camera2d>()
|
||||
.add_system_to_stage(
|
||||
CoreStage::PostUpdate,
|
||||
crate::camera::camera_system::<OrthographicProjection>,
|
||||
crate::camera::camera_system::<OrthographicProjection>.after(ModifiesWindows),
|
||||
)
|
||||
.add_system_to_stage(
|
||||
CoreStage::PostUpdate,
|
||||
crate::camera::camera_system::<PerspectiveProjection>,
|
||||
crate::camera::camera_system::<PerspectiveProjection>.after(ModifiesWindows),
|
||||
)
|
||||
.add_plugin(CameraTypePlugin::<Camera3d>::default())
|
||||
.add_plugin(CameraTypePlugin::<Camera2d>::default());
|
||||
|
@ -31,6 +31,7 @@ use bevy_asset::AddAsset;
|
||||
use bevy_ecs::{entity::Entity, schedule::ParallelSystemDescriptorCoercion};
|
||||
use bevy_render::{RenderApp, RenderStage};
|
||||
use bevy_sprite::SpriteSystem;
|
||||
use bevy_window::ModifiesWindows;
|
||||
|
||||
pub type DefaultTextPipeline = TextPipeline<Entity>;
|
||||
|
||||
@ -46,7 +47,7 @@ impl Plugin for TextPlugin {
|
||||
.register_type::<HorizontalAlign>()
|
||||
.init_asset_loader::<FontLoader>()
|
||||
.insert_resource(DefaultTextPipeline::default())
|
||||
.add_system_to_stage(CoreStage::PostUpdate, text2d_system);
|
||||
.add_system_to_stage(CoreStage::PostUpdate, text2d_system.after(ModifiesWindows));
|
||||
|
||||
if let Ok(render_app) = app.get_sub_app_mut(RenderApp) {
|
||||
render_app.add_system_to_stage(
|
||||
|
@ -31,6 +31,7 @@ use bevy_ecs::schedule::{ParallelSystemDescriptorCoercion, SystemLabel};
|
||||
use bevy_input::InputSystem;
|
||||
use bevy_math::Rect;
|
||||
use bevy_transform::TransformSystem;
|
||||
use bevy_window::ModifiesWindows;
|
||||
use update::{ui_z_system, update_clipping_system};
|
||||
|
||||
use crate::prelude::CameraUi;
|
||||
@ -84,7 +85,9 @@ impl Plugin for UiPlugin {
|
||||
// add these stages to front because these must run before transform update systems
|
||||
.add_system_to_stage(
|
||||
CoreStage::PostUpdate,
|
||||
widget::text_system.before(UiSystem::Flex),
|
||||
widget::text_system
|
||||
.before(UiSystem::Flex)
|
||||
.after(ModifiesWindows),
|
||||
)
|
||||
.add_system_to_stage(
|
||||
CoreStage::PostUpdate,
|
||||
@ -94,7 +97,8 @@ impl Plugin for UiPlugin {
|
||||
CoreStage::PostUpdate,
|
||||
flex_node_system
|
||||
.label(UiSystem::Flex)
|
||||
.before(TransformSystem::TransformPropagate),
|
||||
.before(TransformSystem::TransformPropagate)
|
||||
.after(ModifiesWindows),
|
||||
)
|
||||
.add_system_to_stage(
|
||||
CoreStage::PostUpdate,
|
||||
|
@ -21,7 +21,7 @@ pub mod prelude {
|
||||
}
|
||||
|
||||
use bevy_app::prelude::*;
|
||||
use bevy_ecs::event::Events;
|
||||
use bevy_ecs::{event::Events, schedule::SystemLabel};
|
||||
|
||||
pub struct WindowPlugin {
|
||||
pub add_primary_window: bool,
|
||||
@ -74,3 +74,6 @@ impl Plugin for WindowPlugin {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemLabel)]
|
||||
pub struct ModifiesWindows;
|
||||
|
@ -12,8 +12,9 @@ pub use winit_windows::*;
|
||||
|
||||
use bevy_app::{App, AppExit, CoreStage, Plugin};
|
||||
use bevy_ecs::{
|
||||
event::{Events, ManualEventReader},
|
||||
system::IntoExclusiveSystem,
|
||||
event::{EventWriter, Events, ManualEventReader},
|
||||
schedule::ParallelSystemDescriptorCoercion,
|
||||
system::{NonSend, ResMut},
|
||||
world::World,
|
||||
};
|
||||
use bevy_math::{ivec2, DVec2, Vec2};
|
||||
@ -22,9 +23,9 @@ use bevy_utils::{
|
||||
Instant,
|
||||
};
|
||||
use bevy_window::{
|
||||
CreateWindow, CursorEntered, CursorLeft, CursorMoved, FileDragAndDrop, ReceivedCharacter,
|
||||
RequestRedraw, WindowBackendScaleFactorChanged, WindowCloseRequested, WindowCreated,
|
||||
WindowFocused, WindowMoved, WindowResized, WindowScaleFactorChanged, Windows,
|
||||
CreateWindow, CursorEntered, CursorLeft, CursorMoved, FileDragAndDrop, ModifiesWindows,
|
||||
ReceivedCharacter, RequestRedraw, WindowBackendScaleFactorChanged, WindowCloseRequested,
|
||||
WindowCreated, WindowFocused, WindowMoved, WindowResized, WindowScaleFactorChanged, Windows,
|
||||
};
|
||||
use winit::{
|
||||
dpi::PhysicalPosition,
|
||||
@ -42,18 +43,18 @@ impl Plugin for WinitPlugin {
|
||||
app.init_non_send_resource::<WinitWindows>()
|
||||
.init_resource::<WinitSettings>()
|
||||
.set_runner(winit_runner)
|
||||
.add_system_to_stage(CoreStage::PostUpdate, change_window.exclusive_system());
|
||||
.add_system_to_stage(CoreStage::PostUpdate, change_window.label(ModifiesWindows));
|
||||
let event_loop = EventLoop::new();
|
||||
handle_initial_window_events(&mut app.world, &event_loop);
|
||||
app.insert_non_send_resource(event_loop);
|
||||
}
|
||||
}
|
||||
|
||||
fn change_window(world: &mut World) {
|
||||
let world = world.cell();
|
||||
let winit_windows = world.get_non_send::<WinitWindows>().unwrap();
|
||||
let mut windows = world.get_resource_mut::<Windows>().unwrap();
|
||||
|
||||
fn change_window(
|
||||
winit_windows: NonSend<WinitWindows>,
|
||||
mut windows: ResMut<Windows>,
|
||||
mut window_dpi_changed_events: EventWriter<WindowScaleFactorChanged>,
|
||||
) {
|
||||
for bevy_window in windows.iter_mut() {
|
||||
let id = bevy_window.id();
|
||||
for command in bevy_window.drain_commands() {
|
||||
@ -88,9 +89,6 @@ fn change_window(world: &mut World) {
|
||||
window.set_title(&title);
|
||||
}
|
||||
bevy_window::WindowCommand::SetScaleFactor { scale_factor } => {
|
||||
let mut window_dpi_changed_events = world
|
||||
.get_resource_mut::<Events<WindowScaleFactorChanged>>()
|
||||
.unwrap();
|
||||
window_dpi_changed_events.send(WindowScaleFactorChanged { id, scale_factor });
|
||||
}
|
||||
bevy_window::WindowCommand::SetResolution {
|
||||
|
Loading…
Reference in New Issue
Block a user