Skip to content

Commit

Permalink
feat: Integrating AudioCenter into bones (#445)
Browse files Browse the repository at this point in the history
Moved AudioCenter out of jumpy -> bones.

Reworked to remove the dependency on using a game's settings struct
directly + streamlining the interfaces such as having both play_sound
and play_music be super easy to use, with extra _advanced and _custom
methods for different levels of advanced features/usability on music.

Tested both music/sounds work.
  • Loading branch information
RockasMockas authored Aug 24, 2024
1 parent 71878a2 commit 66f35a5
Show file tree
Hide file tree
Showing 7 changed files with 419 additions and 32 deletions.
28 changes: 16 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion framework_crates/bones_framework/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ egui_plot = "0.23"
ttf-parser = { version = "0.24", default-features = false, optional = true }

# Audio
kira = { version = "0.8.6", features = ["cpal"], default-features = false, optional = true }
kira = { version = "0.9.4", features = ["cpal"], default-features = false, optional = true }

# Localization
fluent = { version = "0.15", optional = true }
Expand Down
43 changes: 43 additions & 0 deletions framework_crates/bones_framework/src/audio.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//! Audio session, systems, and resources.
pub mod audio_center;
pub mod audio_manager;

use crate::prelude::*;
pub use audio_center::*;
pub use audio_manager::*;
pub use kira;
pub use kira::sound::static_sound::StaticSoundData;
use kira::sound::static_sound::StaticSoundHandle;

/// Name of the default bones audio session
pub const DEFAULT_BONES_AUDIO_SESSION: &str = "BONES_AUDIO";

/// Sets up audio-related resources and the default bones audio session
pub fn game_plugin(game: &mut Game) {
AudioSource::register_schema();
game.init_shared_resource::<AudioCenter>();
game.insert_shared_resource(AudioManager::default());
game.init_shared_resource::<AssetServer>();

let session = game.sessions.create(DEFAULT_BONES_AUDIO_SESSION);
// Audio doesn't do any rendering
session.visible = false;
session
.stages
.add_system_to_stage(First, _process_audio_events)
.add_system_to_stage(Last, _kill_finished_audios);
}

/// Holds the handles and the volume to be played for a piece of Audio.
#[derive(HasSchema)]
#[schema(no_clone, no_default, opaque)]
#[repr(C)]
pub struct Audio {
/// The handle for the audio.
handle: StaticSoundHandle,
/// The original volume requested for the audio.
volume: f64,
/// The bones handle for the audio source.
bones_handle: Handle<AudioSource>,
}
Loading

0 comments on commit 66f35a5

Please sign in to comment.