From 20fb00bfda51712e9897b761f38f4b9b70a3bd8f Mon Sep 17 00:00:00 2001 From: Salzian Date: Sun, 24 Sep 2023 17:52:26 +0200 Subject: [PATCH 1/5] Live update --- Cargo.toml | 7 +++++++ README.md | 9 +++++++++ examples/spatial.rs | 6 +++--- src/fmod_studio.rs | 19 ++++++++++++------- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b8895cb..03aa8f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,12 +12,19 @@ anyhow = "1.0.75" bevy = { version = "0.11.2", default-features = false, features = ["bevy_audio"] } bevy_mod_sysfail = "3.0.0" libfmod = "2.206.2" +log = "0.4.20" [dev-dependencies] # The examples need the default features of bevy bevy = { version = "0.11.2", default-features = true } smooth-bevy-cameras = "0.9.0" +[features] +default = [] + +# This is some documentation. +live-update = [] + [[example]] name = "minimal" diff --git a/README.md b/README.md index dc828ef..5628526 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,15 @@ FMOD Studio comes with an Examples project. Open it and build the project. Then You can also configure FMOD Studio to build to a folder you specify. Run examples with `cargo run --example`. See the source code of the examples for more details. +## Live Update + +To enable live update, you need to enable the `live-update` feature. While you can do so in Cargo.toml, I recommend +to explicitly enable it with the `--features` flag. This way, you won't accidentally include it in your release builds. + +```sh +cargo run --example minimal --features live-update +``` + ## Versioning | bevy_fmod | Bevy | FMOD (tested version, newer may work) | diff --git a/examples/spatial.rs b/examples/spatial.rs index 2c5db45..a14fe76 100644 --- a/examples/spatial.rs +++ b/examples/spatial.rs @@ -33,9 +33,9 @@ fn main() { DefaultPlugins, FmodPlugin { audio_banks_paths: &[ - "./assets/Master.bank", - "./assets/Master.strings.bank", - "./assets/Music.bank", + "./assets/fmod/demo_project/Build/Desktop/Master.bank", + "./assets/fmod/demo_project/Build/Desktop/Master.strings.bank", + "./assets/fmod/demo_project/Build/Desktop/Music.bank", ], }, )) diff --git a/src/fmod_studio.rs b/src/fmod_studio.rs index 9052fd7..39a92c9 100644 --- a/src/fmod_studio.rs +++ b/src/fmod_studio.rs @@ -5,7 +5,8 @@ use std::path::{Path, PathBuf}; use bevy::ecs::system::Resource; use bevy::log::{debug, trace}; use libfmod::ffi::{ - FMOD_INIT_3D_RIGHTHANDED, FMOD_STUDIO_INIT_NORMAL, FMOD_STUDIO_LOAD_BANK_NORMAL, + FMOD_INIT_3D_RIGHTHANDED, FMOD_STUDIO_INIT_LIVEUPDATE, FMOD_STUDIO_INIT_NORMAL, + FMOD_STUDIO_LOAD_BANK_NORMAL, }; use libfmod::Studio; @@ -52,13 +53,17 @@ impl FmodStudio { fn init_studio() -> Studio { let studio = Studio::create().expect("Failed to create FMOD studio"); + let mut studio_flags = FMOD_STUDIO_INIT_NORMAL; + + #[cfg(feature = "live-update")] + { + studio_flags |= FMOD_STUDIO_INIT_LIVEUPDATE; + } + + debug!("Initializing FMOD studio with flags: {}", studio_flags); + studio - .initialize( - 1024, - FMOD_STUDIO_INIT_NORMAL, - FMOD_INIT_3D_RIGHTHANDED, - None, - ) + .initialize(1024, studio_flags, FMOD_INIT_3D_RIGHTHANDED, None) .expect("Failed to initialize FMOD studio"); studio From beccb1312b6a27d61fb062e50ac35752323dfcdc Mon Sep 17 00:00:00 2001 From: Salzian Date: Sun, 24 Sep 2023 17:52:26 +0200 Subject: [PATCH 2/5] Live update --- Cargo.toml | 5 +++++ README.md | 9 +++++++++ examples/spatial.rs | 6 +++--- src/fmod_studio.rs | 19 ++++++++++++------- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b8895cb..5de441b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,12 +12,17 @@ anyhow = "1.0.75" bevy = { version = "0.11.2", default-features = false, features = ["bevy_audio"] } bevy_mod_sysfail = "3.0.0" libfmod = "2.206.2" +log = "0.4.20" [dev-dependencies] # The examples need the default features of bevy bevy = { version = "0.11.2", default-features = true } smooth-bevy-cameras = "0.9.0" +[features] +default = [] +live-update = [] + [[example]] name = "minimal" diff --git a/README.md b/README.md index dc828ef..5628526 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,15 @@ FMOD Studio comes with an Examples project. Open it and build the project. Then You can also configure FMOD Studio to build to a folder you specify. Run examples with `cargo run --example`. See the source code of the examples for more details. +## Live Update + +To enable live update, you need to enable the `live-update` feature. While you can do so in Cargo.toml, I recommend +to explicitly enable it with the `--features` flag. This way, you won't accidentally include it in your release builds. + +```sh +cargo run --example minimal --features live-update +``` + ## Versioning | bevy_fmod | Bevy | FMOD (tested version, newer may work) | diff --git a/examples/spatial.rs b/examples/spatial.rs index 2c5db45..a14fe76 100644 --- a/examples/spatial.rs +++ b/examples/spatial.rs @@ -33,9 +33,9 @@ fn main() { DefaultPlugins, FmodPlugin { audio_banks_paths: &[ - "./assets/Master.bank", - "./assets/Master.strings.bank", - "./assets/Music.bank", + "./assets/fmod/demo_project/Build/Desktop/Master.bank", + "./assets/fmod/demo_project/Build/Desktop/Master.strings.bank", + "./assets/fmod/demo_project/Build/Desktop/Music.bank", ], }, )) diff --git a/src/fmod_studio.rs b/src/fmod_studio.rs index 9052fd7..39a92c9 100644 --- a/src/fmod_studio.rs +++ b/src/fmod_studio.rs @@ -5,7 +5,8 @@ use std::path::{Path, PathBuf}; use bevy::ecs::system::Resource; use bevy::log::{debug, trace}; use libfmod::ffi::{ - FMOD_INIT_3D_RIGHTHANDED, FMOD_STUDIO_INIT_NORMAL, FMOD_STUDIO_LOAD_BANK_NORMAL, + FMOD_INIT_3D_RIGHTHANDED, FMOD_STUDIO_INIT_LIVEUPDATE, FMOD_STUDIO_INIT_NORMAL, + FMOD_STUDIO_LOAD_BANK_NORMAL, }; use libfmod::Studio; @@ -52,13 +53,17 @@ impl FmodStudio { fn init_studio() -> Studio { let studio = Studio::create().expect("Failed to create FMOD studio"); + let mut studio_flags = FMOD_STUDIO_INIT_NORMAL; + + #[cfg(feature = "live-update")] + { + studio_flags |= FMOD_STUDIO_INIT_LIVEUPDATE; + } + + debug!("Initializing FMOD studio with flags: {}", studio_flags); + studio - .initialize( - 1024, - FMOD_STUDIO_INIT_NORMAL, - FMOD_INIT_3D_RIGHTHANDED, - None, - ) + .initialize(1024, studio_flags, FMOD_INIT_3D_RIGHTHANDED, None) .expect("Failed to initialize FMOD studio"); studio From a665ec81dbcf7806c757798d255a99129a7e6920 Mon Sep 17 00:00:00 2001 From: Salzian Date: Sun, 24 Sep 2023 17:54:45 +0200 Subject: [PATCH 3/5] reset spatial.rs to main --- examples/spatial.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/spatial.rs b/examples/spatial.rs index a14fe76..2c5db45 100644 --- a/examples/spatial.rs +++ b/examples/spatial.rs @@ -33,9 +33,9 @@ fn main() { DefaultPlugins, FmodPlugin { audio_banks_paths: &[ - "./assets/fmod/demo_project/Build/Desktop/Master.bank", - "./assets/fmod/demo_project/Build/Desktop/Master.strings.bank", - "./assets/fmod/demo_project/Build/Desktop/Music.bank", + "./assets/Master.bank", + "./assets/Master.strings.bank", + "./assets/Music.bank", ], }, )) From b8ab8b56f732df176dde9dcd4f697cac89121238 Mon Sep 17 00:00:00 2001 From: Salzian Date: Sun, 24 Sep 2023 19:14:11 +0200 Subject: [PATCH 4/5] Fix compiler warning when feature is not enabled --- src/fmod_studio.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/fmod_studio.rs b/src/fmod_studio.rs index 39a92c9..a19f28f 100644 --- a/src/fmod_studio.rs +++ b/src/fmod_studio.rs @@ -4,9 +4,10 @@ use std::path::{Path, PathBuf}; use bevy::ecs::system::Resource; use bevy::log::{debug, trace}; +#[cfg(feature = "live-update")] +use libfmod::ffi::FMOD_STUDIO_INIT_LIVEUPDATE; use libfmod::ffi::{ - FMOD_INIT_3D_RIGHTHANDED, FMOD_STUDIO_INIT_LIVEUPDATE, FMOD_STUDIO_INIT_NORMAL, - FMOD_STUDIO_LOAD_BANK_NORMAL, + FMOD_INIT_3D_RIGHTHANDED, FMOD_STUDIO_INIT_NORMAL, FMOD_STUDIO_LOAD_BANK_NORMAL, }; use libfmod::Studio; @@ -53,12 +54,10 @@ impl FmodStudio { fn init_studio() -> Studio { let studio = Studio::create().expect("Failed to create FMOD studio"); - let mut studio_flags = FMOD_STUDIO_INIT_NORMAL; + let studio_flags = FMOD_STUDIO_INIT_NORMAL; #[cfg(feature = "live-update")] - { - studio_flags |= FMOD_STUDIO_INIT_LIVEUPDATE; - } + let studio_flags = studio_flags | FMOD_STUDIO_INIT_LIVEUPDATE; debug!("Initializing FMOD studio with flags: {}", studio_flags); From 91472b5d15a19798d4a145b3ecccfd4b41069765 Mon Sep 17 00:00:00 2001 From: Salzian Date: Sun, 24 Sep 2023 19:14:28 +0200 Subject: [PATCH 5/5] Include live update link in README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 5628526..dfe17cf 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,11 @@ Run examples with `cargo run --example`. See the source code of the examples for ## Live Update +> Live update is a way of connecting FMOD Studio to your game as it runs, +> allowing you to update and monitor audio content in real time. +> +> + To enable live update, you need to enable the `live-update` feature. While you can do so in Cargo.toml, I recommend to explicitly enable it with the `--features` flag. This way, you won't accidentally include it in your release builds.