From cf1ff964ffa28e8dc166226b46a44db3c84b76fb Mon Sep 17 00:00:00 2001 From: Derick M <58572875+TurtIeSocks@users.noreply.github.com> Date: Tue, 5 Nov 2024 15:56:47 -0500 Subject: [PATCH] fix: respect initial sink speed --- .github/workflows/publish.yml | 10 +++++----- examples/querying.rs | 22 ++++++++++++---------- src/channel.rs | 14 +++++++++++++- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 633d6fc..468a68c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -47,17 +47,17 @@ jobs: working-directory: ./macros run: cargo publish --dry-run - # Step 2: Build and verify the main crate - - name: Build and verify the main crate - run: cargo publish --dry-run - - # Step 3: Publish the macros crate to crates.io + # Step 2: Publish the macros crate to crates.io - name: Publish the macros crate to crates.io working-directory: ./macros env: CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} run: cargo publish + # Step 3: Build and verify the main crate + - name: Build and verify the main crate + run: cargo publish --dry-run + # Step 4: Publish the main crate to crates.io - name: Publish the main crate to crates.io env: diff --git a/examples/querying.rs b/examples/querying.rs index 5b00425..a605cf5 100644 --- a/examples/querying.rs +++ b/examples/querying.rs @@ -28,8 +28,15 @@ fn setup(mut commands: Commands) { } fn play_sfx(mut commands: Commands) { - commands.spawn((AudioFiles::FireOGG, PlaybackSettings::DESPAWN)); - commands.spawn((AudioFiles::SprayOGG, PlaybackSettings::DESPAWN, SfxChannel)); + commands.spawn(( + AudioFiles::FireOGG, + PlaybackSettings::DESPAWN.with_speed(2.0), + )); + commands.spawn(( + AudioFiles::SprayOGG, + PlaybackSettings::DESPAWN.with_speed(0.5), + SfxChannel, + )); } // This system will run after the `AudioSink` components have been added to any entities on the `SfxChannel` @@ -49,15 +56,10 @@ fn do_something_with_sfx( // This system will run after the `AudioSink` components have been added to any `FireOGG` entities fn do_something_with_fire( - sfx_query: Query<(Entity, &Name, &AudioSink), (Added, With)>, + mut sfx_query: Query<(Entity, &Name, &mut AudioSink), (Added, With)>, ) { - for (entity, name, sink) in sfx_query.iter() { + for (entity, name, mut sink) in sfx_query.iter_mut() { sink.set_speed(1.25); - info!( - "Fire: {} ({}) is playing at speed {}", - name, - entity, - sink.speed() - ); + warn!("{}: is playing at speed {}", entity, sink.speed()); } } diff --git a/src/channel.rs b/src/channel.rs index f2e4016..722fca8 100644 --- a/src/channel.rs +++ b/src/channel.rs @@ -51,6 +51,7 @@ impl ChannelRegistration for App { ( tick_audio_cache::, ecs_system::, + // update_internal_timer_on_speed_change::, update_volume_on_insert::, settings_event_reader::.run_if(on_event::>()), update_track_volumes:: @@ -103,6 +104,17 @@ fn update_volume_on_insert( } } +// fn update_internal_timer_on_speed_change( +// sink_query: Query<(Entity, &AudioSink), (Changed, With)>, +// settings: Res>, +// mut settings_ew: EventWriter>, +// ) { +// for (entity, sink) in sink_query.iter() { +// bevy::log::info!("{}: speed changed to {}", entity, sink.speed()); +// // settings_ew.send(SettingsEvent::new().with_speed(sink.speed)); +// } +// } + fn ecs_system( query: Query< (Entity, &AudioFiles, Option<&PlaybackSettings>, &DelayMode), @@ -160,7 +172,7 @@ fn play_event_reader( let can_play = audio_cache.can_play(&event.id); if delay_mode == DelayMode::Immediate || can_play { if can_play { - let next_delay = delay_mode.get_delay(event.id.duration()); + let next_delay = delay_mode.get_delay(event.id.duration() / settings.speed); audio_cache.set_entry(event.id, next_delay); } if let Some(handler) = asset_loader.get(&event.id) {