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"] }
cgmath = "0.18.0"
# optional
audio = { git = "https://gavania.de/hodasemi/audio.git", optional = true }
[features]
audio = []
# audio = ["context/sound"]

View file

@ -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<Device>;
fn queue(&self) -> &Arc<Mutex<Queue>>;
@ -13,6 +16,9 @@ pub trait ContextInterface: Send + Sync {
fn images(&self) -> TargetMode<Vec<Arc<Image>>>;
fn width(&self) -> u32;
fn height(&self) -> u32;
#[cfg(feature = "audio")]
fn sound_handler(&self) -> &mut SoundHandler;
}
pub enum TargetMode<T> {

View file

@ -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();
}

View file

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