diff options
| author | Freya Murphy <freya@freyacat.org> | 2025-11-21 22:25:37 -0500 |
|---|---|---|
| committer | Freya Murphy <freya@freyacat.org> | 2025-11-21 22:25:37 -0500 |
| commit | 654277d89471010f57794b8022385d2a99a15a14 (patch) | |
| tree | c10f98cfae20517c23007b941214a4c5f34bfd51 /graphics/src/audio.rs | |
| parent | dungeon: add chest usage/textures (diff) | |
| download | DungeonCrawl-654277d89471010f57794b8022385d2a99a15a14.tar.gz DungeonCrawl-654277d89471010f57794b8022385d2a99a15a14.tar.bz2 DungeonCrawl-654277d89471010f57794b8022385d2a99a15a14.zip | |
audio: create orchestration system
Diffstat (limited to 'graphics/src/audio.rs')
| -rw-r--r-- | graphics/src/audio.rs | 46 |
1 files changed, 0 insertions, 46 deletions
diff --git a/graphics/src/audio.rs b/graphics/src/audio.rs deleted file mode 100644 index 981defb..0000000 --- a/graphics/src/audio.rs +++ /dev/null @@ -1,46 +0,0 @@ -//! The `audio` crate stores all audio assets that need to be loaded during runtime - -use raylib::audio::RaylibAudio; - -macro_rules! load_audio { - ($handle:expr, $filepath:expr) => { - if cfg!(any(feature = "static", target_arch = "wasm32")) { - let bytes = include_bytes!(concat!("../../", $filepath)); - let wave = $handle.new_wave_from_memory(".ogg", bytes)?; - $handle.new_sound_from_wave(&wave)? - } else { - $handle.new_sound($filepath)? - } - }; -} - -type Sound = raylib::audio::Sound<'static>; - -/// The `Audio` container initalizes the audio subsystem -/// for raylib, leaks it (to gurentee audio is statically loaded), -/// then loads all needed audio samples -#[derive(Debug)] -pub struct Audio { - pub speak: Sound, -} -impl Audio { - pub(crate) fn load() -> crate::Result<Self> { - // Phantom handle to the raylib audio subsystem - // Raylib doesnt use a handle, but the rust bindings - // have one to ensure memory safety. - // - // We must leak this handle after allocating it, - // if we dont then all audio will be unloaded :( - // - // NOTE: would this cause issues if `Audio::load` was - // called multiple times? - let handle = Box::leak(Box::new(RaylibAudio::init_audio_device()?)); - - // yes i know this is sans undertale, it was funny - // and i cannot think of anything better yet, haha - // - freya - let speak = load_audio!(handle, "assets/speak.ogg"); - - Ok(Self { speak }) - } -} |