Fix audio feature
This commit is contained in:
parent
6024ae6806
commit
784eba4e41
4 changed files with 19 additions and 9 deletions
|
@ -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"]
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue