Skip to content

Commit

Permalink
fix: respect initial sink speed
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Nov 5, 2024
1 parent f650aa7 commit cf1ff96
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 12 additions & 10 deletions examples/querying.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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<AudioSink>, With<FireOGG>)>,
mut sfx_query: Query<(Entity, &Name, &mut AudioSink), (Added<AudioSink>, With<FireOGG>)>,
) {
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());
}
}
14 changes: 13 additions & 1 deletion src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impl ChannelRegistration for App {
(
tick_audio_cache::<Channel>,
ecs_system::<Channel>,
// update_internal_timer_on_speed_change::<Channel>,
update_volume_on_insert::<Channel>,
settings_event_reader::<Channel>.run_if(on_event::<SettingsEvent<Channel>>()),
update_track_volumes::<Channel>
Expand Down Expand Up @@ -103,6 +104,17 @@ fn update_volume_on_insert<Channel: ACBounds>(
}
}

// fn update_internal_timer_on_speed_change<Channel: ACBounds>(
// sink_query: Query<(Entity, &AudioSink), (Changed<AudioSink>, With<Channel>)>,
// settings: Res<ChannelSettings<Channel>>,
// mut settings_ew: EventWriter<SettingsEvent<Channel>>,
// ) {
// 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<Channel: ACBounds>(
query: Query<
(Entity, &AudioFiles, Option<&PlaybackSettings>, &DelayMode),
Expand Down Expand Up @@ -160,7 +172,7 @@ fn play_event_reader<Channel: ACBounds>(
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) {
Expand Down

0 comments on commit cf1ff96

Please sign in to comment.