Fix audio feature

This commit is contained in:
hodasemi 2023-01-16 13:27:54 +01:00 committed by Michael Hübner
parent 6024ae6806
commit 784eba4e41
4 changed files with 19 additions and 9 deletions

View file

@ -14,6 +14,7 @@ assetpath = { git = "https://gavania.de/hodasemi/vulkan_lib.git" }
anyhow = { version = "1.0.68", features = ["backtrace"] } anyhow = { version = "1.0.68", features = ["backtrace"] }
cgmath = "0.18.0" cgmath = "0.18.0"
# optional
audio = { git = "https://gavania.de/hodasemi/audio.git", optional = true }
[features] [features]
audio = []
# audio = ["context/sound"]

View file

@ -2,6 +2,9 @@ use std::sync::{Arc, Mutex};
use vulkan_rs::prelude::*; use vulkan_rs::prelude::*;
#[cfg(feature = "audio")]
use audio::*;
pub trait ContextInterface: Send + Sync { pub trait ContextInterface: Send + Sync {
fn device(&self) -> &Arc<Device>; fn device(&self) -> &Arc<Device>;
fn queue(&self) -> &Arc<Mutex<Queue>>; fn queue(&self) -> &Arc<Mutex<Queue>>;
@ -13,6 +16,9 @@ pub trait ContextInterface: Send + Sync {
fn images(&self) -> TargetMode<Vec<Arc<Image>>>; fn images(&self) -> TargetMode<Vec<Arc<Image>>>;
fn width(&self) -> u32; fn width(&self) -> u32;
fn height(&self) -> u32; fn height(&self) -> u32;
#[cfg(feature = "audio")]
fn sound_handler(&self) -> &mut SoundHandler;
} }
pub enum TargetMode<T> { pub enum TargetMode<T> {

View file

@ -4,6 +4,9 @@ use crate::prelude::*;
use anyhow::Result; use anyhow::Result;
use assetpath::AssetPath; use assetpath::AssetPath;
#[cfg(feature = "audio")]
use audio::*;
use std::sync::Arc; use std::sync::Arc;
/// `Audible` gives the ability to play a sound /// `Audible` gives the ability to play a sound
@ -19,11 +22,11 @@ impl Audible {
path.set_prefix(&gui_handler.resource_base_path().full_path()); path.set_prefix(&gui_handler.resource_base_path().full_path());
} }
let sound = let sound = gui_handler.context().sound_handler().load_sound(
gui_handler path,
.context() "gui",
.sound() SoundInterpretation::Generic,
.load_sound(path, "gui", SoundInterpretation::Generic)?; )?;
Ok(Arc::new(Audible { gui_handler, sound })) Ok(Arc::new(Audible { gui_handler, sound }))
} }
@ -39,7 +42,7 @@ impl Drop for Audible {
fn drop(&mut self) { fn drop(&mut self) {
self.gui_handler self.gui_handler
.context() .context()
.sound() .sound_handler()
.remove_sound(&self.sound) .remove_sound(&self.sound)
.unwrap(); .unwrap();
} }

View file

@ -271,7 +271,7 @@ impl GuiHandler {
} }
#[cfg(feature = "audio")] #[cfg(feature = "audio")]
pub(crate) fn context(&self) -> &Arc<Context> { pub(crate) fn context(&self) -> &Arc<dyn ContextInterface> {
&self.context &self.context
} }