From 0d0cca9ff44d40fd802434c24439ce4a58f13cc8 Mon Sep 17 00:00:00 2001 From: Roms1383 Date: Sat, 28 Dec 2024 11:37:04 +0700 Subject: [PATCH 1/3] :memo: update docs --- README.md | 2 +- book/pages/AUDIO_SETTINGS_EXT.md | 31 ++------------------- book/pages/AUDIO_SYSTEM.md | 7 ++++- book/pages/INTEGRATION.md | 6 ++++ book/pages/SPATIALIZATION.md | 48 ++++++++------------------------ 5 files changed, 26 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index 2a26c9244..afd08f6ec 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # audioware -![Cyberpunk 2077 version compatibility](https://img.shields.io/badge/Cyberpunk_2077-patch_2.12a-yellow) [![Nexus](https://img.shields.io/badge/Nexus-Audioware-orange)](https://www.nexusmods.com/cyberpunk2077/mods/12001) [![download](https://img.shields.io/github/v/release/cyb3rpsych0s1s/audioware?display_name=tag&label=Download)](https://github.com/cyb3rpsych0s1s/audioware/releases/latest) [![build](https://github.com/cyb3rpsych0s1s/audioware/actions/workflows/quality.yml/badge.svg)](https://github.com/cyb3rpsych0s1s/audioware/actions) [![docs](https://github.com/cyb3rpsych0s1s/audioware/actions/workflows/pages.yml/badge.svg)][BOOK] +![Cyberpunk 2077 version compatibility](https://img.shields.io/badge/Cyberpunk_2077-patch_2.2-yellow) [![Nexus](https://img.shields.io/badge/Nexus-Audioware-orange)](https://www.nexusmods.com/cyberpunk2077/mods/12001) [![download](https://img.shields.io/github/v/release/cyb3rpsych0s1s/audioware?display_name=tag&label=Download)](https://github.com/cyb3rpsych0s1s/audioware/releases/latest) [![build](https://github.com/cyb3rpsych0s1s/audioware/actions/workflows/quality.yml/badge.svg)](https://github.com/cyb3rpsych0s1s/audioware/actions) [![docs](https://github.com/cyb3rpsych0s1s/audioware/actions/workflows/pages.yml/badge.svg)][BOOK] ![Cover image](https://cyb3rpsych0s1s.github.io/audioware/assets/cover.webp) diff --git a/book/pages/AUDIO_SETTINGS_EXT.md b/book/pages/AUDIO_SETTINGS_EXT.md index 903593600..8b9199de4 100644 --- a/book/pages/AUDIO_SETTINGS_EXT.md +++ b/book/pages/AUDIO_SETTINGS_EXT.md @@ -4,41 +4,14 @@ Earlier we saw that [settings](./SETTINGS.md) can be defined in [manifest](./MAN but these settings can also be specified in scripts: ```swift -// builder is a mutable ref -let builder: ref = AudioSettingsExtBuilder.Create(); -// it supports the same settings as definable in manifest, except start_position -builder.SetFadeInTween(ElasticTween.ImmediateIn(5.0, 0.25)); -builder.SetPanning(0.3); -builder.SetPlaybackRate(1.1); -builder.SetVolume(0.9); -// once built it returns an immutable ref with different type -let settings: ref = builder.Build(); +let ext = new AudioSettingsExt(); +ext.fadeIn = LinearTween.Immediate(2.0); GameInstance .GetAudioSystemExt(game) .Play(n"still_dre", GetPlayer(game).GetEntityID(), n"V", scnDialogLineType.Regular, settings); ``` -~~~admonish hint collapsible=true, title='Alternate builder shorter syntax click to open' -The `AudioSettingsExtBuilder` also accepts a shorter syntax: -```swift -GameInstance - .GetAudioSystemExt(game) - .Play( - n"still_dre", - GetPlayer(game).GetEntityID(), - n"V", - scnDialogLineType.Regular, - AudioSettingsExtBuilder.Create() - .WithFadeInTween(ElasticTween.ImmediateIn(5.0, 0.25)) - .WithPanning(0.3) - .WithPlaybackRate(1.1) - .WithVolume(0.9) - .Build() - ); -``` -~~~ - ```admonish youtube title="YouTube demo" ``` diff --git a/book/pages/AUDIO_SYSTEM.md b/book/pages/AUDIO_SYSTEM.md index 3c0ff9600..d79803269 100644 --- a/book/pages/AUDIO_SYSTEM.md +++ b/book/pages/AUDIO_SYSTEM.md @@ -16,5 +16,10 @@ Currently all these methods are supported: - [Play](https://nativedb.red4ext.com/gameGameAudioSystem#Play) - [Stop](https://nativedb.red4ext.com/gameGameAudioSystem#Stop) - [Switch](https://nativedb.red4ext.com/gameGameAudioSystem#Switch) -- [PlayOnEmitter](https://nativedb.red4ext.com/gameGameAudioSystem#PlayOnEmitter) - [Parameter](https://nativedb.red4ext.com/gameGameAudioSystem#Parameter): see [Parameters](./PARAMETERS.md) + +```admonish warning title="Breaking changes in 1.3.0+" +Support for [PlayOnEmitter](https://nativedb.red4ext.com/gameGameAudioSystem#PlayOnEmitter) since there's no way to associate a `tag_name` when called from vanilla. + +Likewise, the methods above can only be used to play sounds on tracks, not on spatial emitters. +``` diff --git a/book/pages/INTEGRATION.md b/book/pages/INTEGRATION.md index 41b7c1ceb..450a95e36 100644 --- a/book/pages/INTEGRATION.md +++ b/book/pages/INTEGRATION.md @@ -32,6 +32,12 @@ As previously stated, audio will dynamically have its frequencies adjusted by [U This is currently not implemented for cars. +## ๐ŸŠโ€โ™‚๏ธ Dynamic time dilation + +Since `1.3.0`, audio will dynamically have its pitch adjusted whenever time dilation changes (e.g. when using Sandevistan). + +You can also opt-out on a per-sound basis. + ## ๐Ÿงน Clean game sessions Spatial scene along with its emitters, every track and currently playing sounds will be completely stopped and reset on every save load. diff --git a/book/pages/SPATIALIZATION.md b/book/pages/SPATIALIZATION.md index 970003343..486846450 100644 --- a/book/pages/SPATIALIZATION.md +++ b/book/pages/SPATIALIZATION.md @@ -5,11 +5,10 @@ Thanks to [kira][kira] Audioware supports audio spatialization, which means audi ## Registration Audio emitter(s) must be registered before you can emit audio from them, but they are automatically cleaned up whenever emitter despawns or dies. +You must provide a `tag_name` which Audioware uses to track emitters internally. ```swift -if !GameInstance.GetAudioSystemExt(game).IsRegisteredEmitter(emitterID) { - GameInstance.GetAudioSystemExt(game).RegisterEmitter(emitterID); -} +GameInstance.GetAudioSystemExt(game).RegisterEmitter(emitterID, n"MyMod"); ``` ```admonish warning title="Types" @@ -21,34 +20,9 @@ You don't need to manually unregister your audio emitter(s), even if you can do Audioware does it automatically whenever emitter despawns or dies. Dying emitter still emit. ~~~ -
How to easily e.g. fade a sound out whenever an Entity is dying click to open - -```swift -/// for Humans -@wrapMethod(NPCDeathListener) -protected cb func OnStatPoolCustomLimitReached(value: Float) -> Bool { - let wasAlive = !this.npc.m_wasJustKilledOrDefeated; - let out = wrappedMethod(value); - if wasAlive && this.npc.m_wasJustKilledOrDefeated { - let id = this.npc.GetEntityID(); - let name = this.npc.GetDisplayName(); // or whatever you named it - // fades for 2sec, with intensity 0.2 - let fadeOut = LinearTween.ImmediateOut(2.0, 0.2); - - GameInstance - .GetAudioSystemExt(this.npc.GetGame()) - .Stop(n"my_custom_audio", id, name, fadeOut); - } - return out; -} -/// for Robots -@wrapMethod(NPCDeathListener) -protected cb func OnStatPoolMinValueReached(value: Float) -> Bool { ... } -``` - -> A courtesy of [Demon9ne](https://next.nexusmods.com/profile/Demon9ne), thanks for the snippet! - -
+~~~admonish hint title="Dying emitter (1.3.0+)" +You don't need to manually fade out or stop your audio on dying emitter(s), even if you can do so: Audioware does it automatically whenever emitter dies (stop) or gets incapacitated / defeated (fade-out). +~~~ ```admonish hint V cannot be an audio emitter because (s)he is the listener. @@ -60,10 +34,10 @@ Then, simply use the `OnEmitter` variants of the methods: ```swift // โš ๏ธ emitterID and emitterCName must be both valid and non-default -GameInstance.GetAudioSystemExt(game).PlayOnEmitter(n"my_custom_audio", emitterID, emitterCName); +GameInstance.GetAudioSystemExt(game).PlayOnEmitter(n"my_custom_audio", emitterID, n"MyMod"); // if should stop at some point... -GameInstance.GetAudioSystemExt(game).StopOnEmitter(n"my_custom_audio", emitterID, emitterCName); +GameInstance.GetAudioSystemExt(game).StopOnEmitter(n"my_custom_audio", emitterID, n"MyMod"); ``` ```admonish youtube title="YouTube demo" @@ -103,17 +77,17 @@ public class AutoEmittersSystem extends ScriptableSystem { tween.startTime = RandRangeF(1.0, 3.0); tween.duration = RandRangeF(3.0, 4.5); let emitterID: EntityID; - let emitterCName: CName = n"DummyTest"; + let tagName: CName = n"MyMod"; let game = this.GetGameInstance(); // get entity V currently looks at (crosshair) let target = GameInstance.GetTargetingSystem(game).GetLookAtObject(GetPlayer(game)); if !IsDefined(target) { return; } emitterID = target.GetEntityID(); - if !GameInstance.GetAudioSystemExt(game).IsRegisteredEmitter(emitterID) { - GameInstance.GetAudioSystemExt(game).RegisterEmitter(emitterID); + if !GameInstance.GetAudioSystemExt(game).IsRegisteredEmitter(emitterID, tagName) { + GameInstance.GetAudioSystemExt(game).RegisterEmitter(emitterID, tagName); } - GameInstance.GetAudioSystemExt(game).PlayOnEmitter(eventName, emitterID, emitterCName); + GameInstance.GetAudioSystemExt(game).PlayOnEmitter(eventName, emitterID, tagName); } } ``` From 91de8365a3d653dc2b05d18bf2b33b5d7adfff5a Mon Sep 17 00:00:00 2001 From: Roms1383 Date: Sat, 28 Dec 2024 12:43:28 +0700 Subject: [PATCH 2/3] :triangular_flag_on_post: intercept save handling controller only on debug mode --- crates/audioware/src/hooks/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/audioware/src/hooks/mod.rs b/crates/audioware/src/hooks/mod.rs index 822a55592..c640667c8 100644 --- a/crates/audioware/src/hooks/mod.rs +++ b/crates/audioware/src/hooks/mod.rs @@ -10,12 +10,14 @@ mod time_system; mod events; pub fn attach(env: &SdkEnv) { - save_handling_controller::attach_hook(env); audio_system::attach_hooks(env); entity::attach_hook(env); time_dilatable::attach_hooks(env); time_system::attach_hooks(env); + #[cfg(debug_assertions)] + save_handling_controller::attach_hook(env); + #[cfg(feature = "research")] { // events::audio::attach_hook(env); // ๐ŸŒŠ From 33d2d24a784816e6b1bc3f50c1e88894fd0b4463 Mon Sep 17 00:00:00 2001 From: Roms1383 Date: Sat, 28 Dec 2024 13:12:15 +0700 Subject: [PATCH 3/3] :bug: emitter settings conversion --- crates/audioware/src/abi/mod.rs | 2 +- crates/audioware/src/abi/types.rs | 8 ++------ crates/audioware/src/error.rs | 2 -- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/crates/audioware/src/abi/mod.rs b/crates/audioware/src/abi/mod.rs index 5a64bd5f6..d1ca09ac1 100644 --- a/crates/audioware/src/abi/mod.rs +++ b/crates/audioware/src/abi/mod.rs @@ -302,7 +302,7 @@ impl SceneLifecycle for AudioSystemExt { } }; let emitter_settings = match TargetFootprint::try_new(emitter_settings, *entity_id) { - Ok(emitter_settings) => Some(emitter_settings), + Ok(emitter_settings) => emitter_settings, Err(e) => { warns!( "{}", diff --git a/crates/audioware/src/abi/types.rs b/crates/audioware/src/abi/types.rs index 8b9231629..83c09b4f8 100644 --- a/crates/audioware/src/abi/types.rs +++ b/crates/audioware/src/abi/types.rs @@ -395,13 +395,9 @@ impl TargetFootprint { pub fn try_new( value: Ref, entity_id: EntityId, - ) -> Result> { + ) -> Result, Vec> { use crate::engine::ToDistances; - let value = value.into_settings_ext(entity_id.to_distances()); - if value.is_none() { - return Err(vec![ValidationError::InvalidEmitterSettings]); - } - Ok(Self(value.unwrap())) + Ok(value.into_settings_ext(entity_id.to_distances()).map(Self)) } } diff --git a/crates/audioware/src/error.rs b/crates/audioware/src/error.rs index 4adb9a118..a489195cb 100644 --- a/crates/audioware/src/error.rs +++ b/crates/audioware/src/error.rs @@ -64,8 +64,6 @@ pub enum ValidationError { InvalidTagName, #[snafu(display("entity_id cannot be undefined or V."))] InvalidTargetId, - #[snafu(display("invalid emitter_settings."))] - InvalidEmitterSettings, } impl From for Error {