Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kanerogers/issue52 #126

Merged
merged 12 commits into from
Jan 20, 2022
Merged
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ opt-level = 3

[profile.dev.package.image]
opt-level = 3

[profile.dev.package.symphonia]
opt-level = 3
2 changes: 1 addition & 1 deletion examples/beat-saber-clone/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ serde_json = "1.0"
approx = "0.5"

[target.'cfg(target_os = "android")'.dependencies]
ndk-glue = "0.5.0"
ndk-glue = "=0.6.0"

[package.metadata.android]
apk_label = "Hotham Beat Saber Example"
Expand Down
Binary file not shown.
11 changes: 9 additions & 2 deletions examples/beat-saber-clone/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ use hotham::{
gltf_loader::{self, add_model_to_world},
legion::{Resources, Schedule, World},
resources::{
physics_context::PANEL_COLLISION_GROUP, GuiContext, HapticContext, PhysicsContext,
RenderContext, XrContext,
physics_context::PANEL_COLLISION_GROUP, AudioContext, GuiContext, HapticContext,
PhysicsContext, RenderContext, XrContext,
},
schedule_functions::{
apply_haptic_feedback, begin_frame, begin_pbr_renderpass, end_frame, end_pbr_renderpass,
Expand Down Expand Up @@ -75,6 +75,7 @@ pub fn real_main() -> HothamResult<()> {
&render_context.descriptor_set_layouts,
)?;
let haptic_context = HapticContext::default();
let mut audio_context = AudioContext::default();

// Add Environment
add_environment_models(&models, &mut world, &vulkan_context, &render_context);
Expand All @@ -99,6 +100,11 @@ pub fn real_main() -> HothamResult<()> {
&mut physics_context,
);

// Add Sound
let mp3_bytes = include_bytes!("../../../test_assets/Quartet 14 - Clip.mp3").to_vec();
let audio_source = audio_context.create_audio_source(mp3_bytes);
world.push((audio_source,));

// // Add Blue Saber
// add_saber(
// Colour::Blue,
Expand Down Expand Up @@ -163,6 +169,7 @@ pub fn real_main() -> HothamResult<()> {
resources.insert(0 as usize);
resources.insert(GameState::default());
resources.insert(haptic_context);
resources.insert(audio_context);

let schedule = Schedule::builder()
.add_thread_local_fn(begin_frame)
Expand Down
2 changes: 1 addition & 1 deletion examples/simple-scene/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ path = "src/main.rs"
hotham = {path = "../../hotham"}

[target.'cfg(target_os = "android")'.dependencies]
ndk-glue = "0.5.0"
ndk-glue = "0.6.0"

[package.metadata.android]
apk_label = "Hotham Simple Scene Example"
Expand Down
10 changes: 6 additions & 4 deletions hotham/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ shaderc = "0.7"
anyhow = "1.0"
ash = "0.33.2"
console = "0.14"
cpal = {git = "https://github.com/RustAudio/cpal", rev = "f8b1ab53b46ef7a635c89c8758674cb36caea190"}
crossbeam = "0.8.1"
ctrlc = {version = "3", features = ["termination"]}
egui = "0.15"
generational-arena = "0.2.8"
gltf = {version = "0.16", features = ["KHR_materials_pbrSpecularGlossiness"]}
hotham-debug-server = {path = "../hotham-debug-server"}
image = "0.23"
Expand All @@ -25,13 +27,13 @@ memoffset = "0.5.1"
mint = "0.5.6"
nalgebra = {features = ["convert-mint", "serde-serialize"], version = "0.29.0"}
oddio = "0.5"
openxr = {features = ["loaded", "mint"], version = "0.15.5"}
openxr = {features = ["loaded", "mint"], git = "https://github.com/Ralith/openxrs", rev = "ca06a64557abc94559bdb30ceafb51b031e5ac9a"}
rand = "0.8"
rapier3d = "0.11.1"
renderdoc = "0.10"
schemars = "0.8"
serde = {version = "1.0", features = ["derive"]}
serde_json = "1.0"
symphonia = {version = "0.4", features = ["mp3"]}
thiserror = "1.0"
uuid = {version = "0.8", features = ["serde", "v4"]}

Expand All @@ -40,8 +42,8 @@ approx = "0.5"

[target.'cfg(target_os = "android")'.dependencies]
jni = "0.18.0"
ndk = "0.4.0"
ndk-glue = "0.5"
ndk = "0.6.0"
ndk-glue = "=0.6.0"

[dev-dependencies.criterion]
features = ["html_reports"]
Expand Down
2 changes: 2 additions & 0 deletions hotham/src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod primitive;
pub mod rigid_body;
pub mod root;
pub mod skin;
pub mod sound_emitter;
pub mod transform;
pub mod transform_matrix;
pub mod visible;
Expand All @@ -32,6 +33,7 @@ pub use primitive::Primitive;
pub use rigid_body::RigidBody;
pub use root::Root;
pub use skin::Skin;
pub use sound_emitter::SoundEmitter;
pub use transform::Transform;
pub use transform_matrix::TransformMatrix;
pub use visible::Visible;
59 changes: 59 additions & 0 deletions hotham/src/components/sound_emitter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use std::sync::Arc;

use oddio::{Frames, Stop};

type AudioHandle = oddio::Handle<oddio::SpatialBuffered<oddio::Stop<oddio::FramesSignal<f32>>>>;

pub struct SoundEmitter {
pub frames: Arc<Frames<f32>>,
pub handle: Option<AudioHandle>,
pub next_state: SoundState,
}

#[derive(Debug, Clone, Copy)]
pub enum SoundState {
Stopped,
Playing,
Paused,
}

impl SoundEmitter {
pub fn new(frames: Arc<Frames<f32>>) -> Self {
Self {
frames,
handle: None,
next_state: SoundState::Stopped,
}
}

pub fn current_state(&mut self) -> SoundState {
if let Some(handle) = self.handle.as_mut() {
let control = handle.control::<Stop<_>, _>();
if control.is_paused() {
return SoundState::Paused;
}
if control.is_stopped() {
return SoundState::Stopped;
}
return SoundState::Playing;
} else {
return SoundState::Stopped;
}
}

pub fn play(&mut self) {
self.next_state = SoundState::Playing;
}

pub fn pause(&mut self) {
self.next_state = SoundState::Paused;
}

pub fn stop(&mut self) {
self.next_state = SoundState::Stopped;
}

pub fn resume(&mut self) {
self.next_state = SoundState::Playing;
}
}
Loading