Skip to content

Commit

Permalink
Merge branch 'bevyengine:main' into fix-pr-8942
Browse files Browse the repository at this point in the history
  • Loading branch information
tygyh authored Dec 7, 2023
2 parents f8d7321 + a4c2728 commit 03b6106
Show file tree
Hide file tree
Showing 68 changed files with 221 additions and 182 deletions.
9 changes: 5 additions & 4 deletions crates/bevy_audio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ impl Plugin for AudioPlugin {
.run_if(audio_output_available)
.after(TransformSystem::TransformPropagate), // For spatial audio transforms
)
.add_systems(
PostUpdate,
(update_emitter_positions, update_listener_positions).in_set(AudioPlaySet),
)
.init_resource::<AudioOutput>();

#[cfg(any(feature = "mp3", feature = "flac", feature = "wav", feature = "vorbis"))]
Expand All @@ -107,11 +111,8 @@ impl AddAudioSource for App {
{
self.init_asset::<T>().add_systems(
PostUpdate,
play_queued_audio_system::<T>.in_set(AudioPlaySet),
(play_queued_audio_system::<T>, cleanup_finished_audio::<T>).in_set(AudioPlaySet),
);
self.add_systems(PostUpdate, cleanup_finished_audio::<T>.in_set(AudioPlaySet));
self.add_systems(PostUpdate, update_emitter_positions.in_set(AudioPlaySet));
self.add_systems(PostUpdate, update_listener_positions.in_set(AudioPlaySet));
self
}
}
17 changes: 16 additions & 1 deletion crates/bevy_ecs/src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ mod tests {
},
system::{
Commands, In, IntoSystem, Local, NonSend, NonSendMut, ParamSet, Query, Res, ResMut,
Resource, System, SystemState,
Resource, StaticSystemParam, System, SystemState,
},
world::{FromWorld, World},
};
Expand Down Expand Up @@ -1602,14 +1602,29 @@ mod tests {
unimplemented!()
}

fn static_system_param(_: StaticSystemParam<Query<'static, 'static, &W<u32>>>) {
unimplemented!()
}

fn exclusive_with_state(
_: &mut World,
_: Local<bool>,
_: (&mut QueryState<&W<i32>>, &mut SystemState<Query<&W<u32>>>),
_: (),
) {
unimplemented!()
}

fn not(In(val): In<bool>) -> bool {
!val
}

assert_is_system(returning::<Result<u32, std::io::Error>>.map(Result::unwrap));
assert_is_system(returning::<Option<()>>.map(drop));
assert_is_system(returning::<&str>.map(u64::from_str).map(Result::unwrap));
assert_is_system(static_system_param);
assert_is_system(exclusive_in_out::<(), Result<(), std::io::Error>>.map(bevy_utils::error));
assert_is_system(exclusive_with_state);
assert_is_system(returning::<bool>.pipe(exclusive_in_out::<bool, ()>));

returning::<()>.run_if(returning::<bool>.pipe(not));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@ use bevy_ecs::schedule::State;
/// This type can be used as a resource to keep the current state of an input, by reacting to
/// events from the input. For a given input value:
///
/// * [`Input::pressed`] will return `true` between a press and a release event.
/// * [`Input::just_pressed`] will return `true` for one frame after a press event.
/// * [`Input::just_released`] will return `true` for one frame after a release event.
/// * [`ButtonInput::pressed`] will return `true` between a press and a release event.
/// * [`ButtonInput::just_pressed`] will return `true` for one frame after a press event.
/// * [`ButtonInput::just_released`] will return `true` for one frame after a release event.
///
/// ## Multiple systems
///
/// In case multiple systems are checking for [`Input::just_pressed`] or [`Input::just_released`]
/// In case multiple systems are checking for [`ButtonInput::just_pressed`] or [`ButtonInput::just_released`]
/// but only one should react, for example in the case of triggering
/// [`State`] change, you should consider clearing the input state, either by:
///
/// * Using [`Input::clear_just_pressed`] or [`Input::clear_just_released`] instead.
/// * Calling [`Input::clear`] or [`Input::reset`] immediately after the state change.
/// * Using [`ButtonInput::clear_just_pressed`] or [`ButtonInput::clear_just_released`] instead.
/// * Calling [`ButtonInput::clear`] or [`ButtonInput::reset`] immediately after the state change.
///
/// ## Note
///
/// When adding this resource for a new input type, you should:
///
/// * Call the [`Input::press`] method for each press event.
/// * Call the [`Input::release`] method for each release event.
/// * Call the [`Input::clear`] method at each frame start, before processing events.
/// * Call the [`ButtonInput::press`] method for each press event.
/// * Call the [`ButtonInput::release`] method for each release event.
/// * Call the [`ButtonInput::clear`] method at each frame start, before processing events.
///
/// Note: Calling `clear` from a [`ResMut`] will trigger change detection.
/// It may be preferable to use [`DetectChangesMut::bypass_change_detection`]
Expand All @@ -45,7 +45,7 @@ use bevy_ecs::schedule::State;
///[`DetectChangesMut::bypass_change_detection`]: bevy_ecs::change_detection::DetectChangesMut::bypass_change_detection
#[derive(Debug, Clone, Resource, Reflect)]
#[reflect(Default)]
pub struct Input<T: Copy + Eq + Hash + Send + Sync + 'static> {
pub struct ButtonInput<T: Copy + Eq + Hash + Send + Sync + 'static> {
/// A collection of every button that is currently being pressed.
pressed: HashSet<T>,
/// A collection of every button that has just been pressed.
Expand All @@ -54,7 +54,7 @@ pub struct Input<T: Copy + Eq + Hash + Send + Sync + 'static> {
just_released: HashSet<T>,
}

impl<T: Copy + Eq + Hash + Send + Sync + 'static> Default for Input<T> {
impl<T: Copy + Eq + Hash + Send + Sync + 'static> Default for ButtonInput<T> {
fn default() -> Self {
Self {
pressed: Default::default(),
Expand All @@ -64,7 +64,7 @@ impl<T: Copy + Eq + Hash + Send + Sync + 'static> Default for Input<T> {
}
}

impl<T> Input<T>
impl<T> ButtonInput<T>
where
T: Copy + Eq + Hash + Send + Sync + 'static,
{
Expand Down Expand Up @@ -112,7 +112,7 @@ where

/// Clears the `just_pressed` state of the `input` and returns `true` if the `input` has just been pressed.
///
/// Future calls to [`Input::just_pressed`] for the given input will return false until a new press event occurs.
/// Future calls to [`ButtonInput::just_pressed`] for the given input will return false until a new press event occurs.
pub fn clear_just_pressed(&mut self, input: T) -> bool {
self.just_pressed.remove(&input)
}
Expand All @@ -129,7 +129,7 @@ where

/// Clears the `just_released` state of the `input` and returns `true` if the `input` has just been released.
///
/// Future calls to [`Input::just_released`] for the given input will return false until a new release event occurs.
/// Future calls to [`ButtonInput::just_released`] for the given input will return false until a new release event occurs.
pub fn clear_just_released(&mut self, input: T) -> bool {
self.just_released.remove(&input)
}
Expand All @@ -143,7 +143,7 @@ where

/// Clears the `pressed`, `just_pressed`, and `just_released` data for every input.
///
/// See also [`Input::clear`] for simulating elapsed time steps.
/// See also [`ButtonInput::clear`] for simulating elapsed time steps.
pub fn reset_all(&mut self) {
self.pressed.clear();
self.just_pressed.clear();
Expand All @@ -152,7 +152,7 @@ where

/// Clears the `just pressed` and `just released` data for every input.
///
/// See also [`Input::reset_all`] for a full reset.
/// See also [`ButtonInput::reset_all`] for a full reset.
pub fn clear(&mut self) {
self.just_pressed.clear();
self.just_released.clear();
Expand All @@ -178,9 +178,9 @@ where
mod test {
use bevy_reflect::TypePath;

use crate::Input;
use crate::ButtonInput;

/// Used for testing the functionality of [`Input`].
/// Used for testing the functionality of [`ButtonInput`].
#[derive(TypePath, Copy, Clone, Eq, PartialEq, Hash)]
enum DummyInput {
Input1,
Expand All @@ -189,7 +189,7 @@ mod test {

#[test]
fn test_press() {
let mut input = Input::default();
let mut input = ButtonInput::default();
assert!(!input.pressed.contains(&DummyInput::Input1));
assert!(!input.just_pressed.contains(&DummyInput::Input1));
input.press(DummyInput::Input1);
Expand All @@ -199,15 +199,15 @@ mod test {

#[test]
fn test_pressed() {
let mut input = Input::default();
let mut input = ButtonInput::default();
assert!(!input.pressed(DummyInput::Input1));
input.press(DummyInput::Input1);
assert!(input.pressed(DummyInput::Input1));
}

#[test]
fn test_any_pressed() {
let mut input = Input::default();
let mut input = ButtonInput::default();
assert!(!input.any_pressed([DummyInput::Input1]));
assert!(!input.any_pressed([DummyInput::Input2]));
assert!(!input.any_pressed([DummyInput::Input1, DummyInput::Input2]));
Expand All @@ -219,7 +219,7 @@ mod test {

#[test]
fn test_release() {
let mut input = Input::default();
let mut input = ButtonInput::default();
input.press(DummyInput::Input1);
assert!(input.pressed.contains(&DummyInput::Input1));
assert!(!input.just_released.contains(&DummyInput::Input1));
Expand All @@ -230,7 +230,7 @@ mod test {

#[test]
fn test_release_all() {
let mut input = Input::default();
let mut input = ButtonInput::default();
input.press(DummyInput::Input1);
input.press(DummyInput::Input2);
input.release_all();
Expand All @@ -241,15 +241,15 @@ mod test {

#[test]
fn test_just_pressed() {
let mut input = Input::default();
let mut input = ButtonInput::default();
assert!(!input.just_pressed(DummyInput::Input1));
input.press(DummyInput::Input1);
assert!(input.just_pressed(DummyInput::Input1));
}

#[test]
fn test_any_just_pressed() {
let mut input = Input::default();
let mut input = ButtonInput::default();
assert!(!input.any_just_pressed([DummyInput::Input1]));
assert!(!input.any_just_pressed([DummyInput::Input2]));
assert!(!input.any_just_pressed([DummyInput::Input1, DummyInput::Input2]));
Expand All @@ -261,7 +261,7 @@ mod test {

#[test]
fn test_clear_just_pressed() {
let mut input = Input::default();
let mut input = ButtonInput::default();
input.press(DummyInput::Input1);
assert!(input.just_pressed(DummyInput::Input1));
input.clear_just_pressed(DummyInput::Input1);
Expand All @@ -270,7 +270,7 @@ mod test {

#[test]
fn test_just_released() {
let mut input = Input::default();
let mut input = ButtonInput::default();
input.press(DummyInput::Input1);
assert!(!input.just_released(DummyInput::Input1));
input.release(DummyInput::Input1);
Expand All @@ -279,7 +279,7 @@ mod test {

#[test]
fn test_any_just_released() {
let mut input = Input::default();
let mut input = ButtonInput::default();
input.press(DummyInput::Input1);
assert!(!input.any_just_released([DummyInput::Input1]));
assert!(!input.any_just_released([DummyInput::Input2]));
Expand All @@ -292,7 +292,7 @@ mod test {

#[test]
fn test_clear_just_released() {
let mut input = Input::default();
let mut input = ButtonInput::default();
input.press(DummyInput::Input1);
input.release(DummyInput::Input1);
assert!(input.just_released(DummyInput::Input1));
Expand All @@ -302,7 +302,7 @@ mod test {

#[test]
fn test_reset() {
let mut input = Input::default();
let mut input = ButtonInput::default();

// Pressed
input.press(DummyInput::Input1);
Expand All @@ -328,7 +328,7 @@ mod test {

#[test]
fn test_reset_all() {
let mut input = Input::default();
let mut input = ButtonInput::default();

input.press(DummyInput::Input1);
input.press(DummyInput::Input2);
Expand All @@ -344,7 +344,7 @@ mod test {

#[test]
fn test_clear() {
let mut input = Input::default();
let mut input = ButtonInput::default();

// Pressed
input.press(DummyInput::Input1);
Expand All @@ -370,7 +370,7 @@ mod test {

#[test]
fn test_get_pressed() {
let mut input = Input::default();
let mut input = ButtonInput::default();
input.press(DummyInput::Input1);
input.press(DummyInput::Input2);
let pressed = input.get_pressed();
Expand All @@ -382,7 +382,7 @@ mod test {

#[test]
fn test_get_just_pressed() {
let mut input = Input::default();
let mut input = ButtonInput::default();
input.press(DummyInput::Input1);
input.press(DummyInput::Input2);
let just_pressed = input.get_just_pressed();
Expand All @@ -394,7 +394,7 @@ mod test {

#[test]
fn test_get_just_released() {
let mut input = Input::default();
let mut input = ButtonInput::default();
input.press(DummyInput::Input1);
input.press(DummyInput::Input2);
input.release(DummyInput::Input1);
Expand All @@ -408,7 +408,7 @@ mod test {

#[test]
fn test_general_input_handling() {
let mut input = Input::default();
let mut input = ButtonInput::default();

// Test pressing
input.press(DummyInput::Input1);
Expand Down Expand Up @@ -453,7 +453,7 @@ mod test {
assert!(!input.just_released(DummyInput::Input2));

// Set up an `Input` to test resetting
let mut input = Input::default();
let mut input = ButtonInput::default();

input.press(DummyInput::Input1);
input.release(DummyInput::Input2);
Expand Down
Loading

0 comments on commit 03b6106

Please sign in to comment.