From 784eba4e4136312e23a2ffa0049f5793c1b96d4e Mon Sep 17 00:00:00 2001 From: hodasemi Date: Mon, 16 Jan 2023 13:27:54 +0100 Subject: [PATCH] Fix audio feature --- Cargo.toml | 5 +++-- src/context_interface.rs | 6 ++++++ src/guihandler/gui/audible.rs | 15 +++++++++------ src/guihandler/guihandler.rs | 2 +- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 884ec59..527d799 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ assetpath = { git = "https://gavania.de/hodasemi/vulkan_lib.git" } anyhow = { version = "1.0.68", features = ["backtrace"] } cgmath = "0.18.0" +# optional +audio = { git = "https://gavania.de/hodasemi/audio.git", optional = true } + [features] -audio = [] -# audio = ["context/sound"] diff --git a/src/context_interface.rs b/src/context_interface.rs index 0ff5eea..0c5fd70 100644 --- a/src/context_interface.rs +++ b/src/context_interface.rs @@ -2,6 +2,9 @@ use std::sync::{Arc, Mutex}; use vulkan_rs::prelude::*; +#[cfg(feature = "audio")] +use audio::*; + pub trait ContextInterface: Send + Sync { fn device(&self) -> &Arc; fn queue(&self) -> &Arc>; @@ -13,6 +16,9 @@ pub trait ContextInterface: Send + Sync { fn images(&self) -> TargetMode>>; fn width(&self) -> u32; fn height(&self) -> u32; + + #[cfg(feature = "audio")] + fn sound_handler(&self) -> &mut SoundHandler; } pub enum TargetMode { diff --git a/src/guihandler/gui/audible.rs b/src/guihandler/gui/audible.rs index 18b2f9e..f186da0 100644 --- a/src/guihandler/gui/audible.rs +++ b/src/guihandler/gui/audible.rs @@ -4,6 +4,9 @@ use crate::prelude::*; use anyhow::Result; use assetpath::AssetPath; +#[cfg(feature = "audio")] +use audio::*; + use std::sync::Arc; /// `Audible` gives the ability to play a sound @@ -19,11 +22,11 @@ impl Audible { path.set_prefix(&gui_handler.resource_base_path().full_path()); } - let sound = - gui_handler - .context() - .sound() - .load_sound(path, "gui", SoundInterpretation::Generic)?; + let sound = gui_handler.context().sound_handler().load_sound( + path, + "gui", + SoundInterpretation::Generic, + )?; Ok(Arc::new(Audible { gui_handler, sound })) } @@ -39,7 +42,7 @@ impl Drop for Audible { fn drop(&mut self) { self.gui_handler .context() - .sound() + .sound_handler() .remove_sound(&self.sound) .unwrap(); } diff --git a/src/guihandler/guihandler.rs b/src/guihandler/guihandler.rs index 431aabc..056fb01 100644 --- a/src/guihandler/guihandler.rs +++ b/src/guihandler/guihandler.rs @@ -271,7 +271,7 @@ impl GuiHandler { } #[cfg(feature = "audio")] - pub(crate) fn context(&self) -> &Arc { + pub(crate) fn context(&self) -> &Arc { &self.context }