-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Integrating AudioCenter into bones (#445)
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
1 parent
71878a2
commit 66f35a5
Showing
7 changed files
with
419 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>, | ||
} |
Oops, something went wrong.