diff --git a/docs/API.md b/docs/API.md index b4ce6e07..c69dddd3 100644 --- a/docs/API.md +++ b/docs/API.md @@ -20642,7 +20642,10 @@ aura visual. The effects of the aura stay on the actor until actor. Some auras also leave an effect on the ground where the actor stands. The ground effect of a spell that roots, for example the ice of Frost Nova, moves with the actor. Some auras also change the color of the -actor. +actor. The sound of the aura plays when it shows, from the actor. A few +auras repeat their sound until they end. A sound that does not play twice +at once in the world, for example the crack of Frost Nova's ice, plays one +time when many actors get the aura together. Some auras also have an animation, for example the stun of a stun aura. While the actor does not move, it plays the animation of its newest aura diff --git a/src/model/Scene.cpp b/src/model/Scene.cpp index 10f77d79..40ae26c1 100644 --- a/src/model/Scene.cpp +++ b/src/model/Scene.cpp @@ -1080,6 +1080,7 @@ int __fastcall Hide(void *self, void *) { for (Actor *actor : *F(self).actors) { Casts::Silence(*actor); Areas::Silence(*actor); + AuraVisuals::Silence(*actor); } return g_class.Base(Offsets::VTBL_FRAME_HIDE)(self, nullptr); } diff --git a/src/model/Scene.h b/src/model/Scene.h index 17238999..9809c6f1 100644 --- a/src/model/Scene.h +++ b/src/model/Scene.h @@ -160,6 +160,10 @@ struct AuraVisual { float worldYaw = 0.0f; float worldScale = 1.0f; bool worldFollows = false; + // The kit's sound when it loops (Sounds::KitLoops): its ID, and the loop + // playing at the actor (null while the scene is paused or hidden). + int loopSoundID = 0; + void *loopSound = nullptr; }; // The area kit of a spell's ground area while it runs: the shard emitter @@ -495,10 +499,13 @@ void ApplyColors(Actor &actor); // kit's, ApplyEffectAnimation 0x005FDE80), or -1. int PinnedAnimation(const Actor &actor); // From the actor's update, link and place: the world effects' light, -// visibility and placement. +// visibility and placement, and the loop sounds' place and pause. void Update(Actor &actor, float elapsedSec); void Link(Actor &actor); void Place(Actor &actor); +// Stops the loop sounds (the scene hid; its update stops). The update starts +// them again. +void Silence(Actor &actor); } // namespace AuraVisuals // The area kit of an actor that shows a spell's ground area @@ -700,6 +707,13 @@ void Heard(void *sceneFrame, const float (&point)[3], float (&out)[3]); void *Play(void *sceneFrame, int soundKitID, const float (&point)[3]); void *Loop(void *sceneFrame, int soundKitID, const float (&point)[3]); void Move(void *sceneFrame, void *sound, const float (&point)[3]); +// A sound's fade when its effect or missile stops: CEffect::Stop's `push +// 0x3E19999A` before Sound::Stop2 (0x006204B6) and the missile's free +// (0x0061CD70). +constexpr float kStopFadeSec = 0.15f; +// Whether a lasting kit (kinds 2 to 4) loops the sound rather than playing +// it once: bit 0x200 of its SoundEntries flags (FUN_SOUND_DEFINITION_KIT_LOOP). +bool KitLoops(int soundID); } // namespace Sounds // The scene camera (model/Scene.cpp). diff --git a/src/model/SceneAura.cpp b/src/model/SceneAura.cpp index b875d47b..4dc495e8 100644 --- a/src/model/SceneAura.cpp +++ b/src/model/SceneAura.cpp @@ -38,8 +38,14 @@ // stunned actor stands stunned. An aura's end does not pick again; its // animation plays on until its sequence ends, as on a unit. // -// What the world does and this does not: the state kit's sound, and the -// auras' priorities and visions (a scene shows every aura it is given). +// The kit's sound plays once per play at the actor (the first effect's arm +// pass, 0x00620C10 to 0x006210B9), or loops on it when its definition has +// bit 0x200 (AddEffectSound 0x0061FEC0) until the aura's end stops it with +// CEffect::Stop's fade. A definition with no-duplicates (0x20), as Frost +// Nova's and Fear's, plays once however many actors show it at once. +// +// What the world does and this does not: the auras' priorities and visions +// (a scene shows every aura it is given). #include "model/Scene.h" @@ -48,6 +54,7 @@ #include "dbc/Lookup.h" #include "model/M2.h" #include "model/VisualKit.h" +#include "sound/Play.h" #include #include @@ -87,6 +94,15 @@ void ShowOne(Actor &actor, AuraVisual &aura) { aura.shown = true; void *frame = actor.SceneFrame(); Model::VisualKit::Apply(frame, actor.model, aura.kit, false, &aura.effects); + // The kit's sound, once per play: a looping one stays on the unit until + // the aura's effects stop. + const auto sound = Game::Read(aura.kit, Offsets::OFF_SPELLVISUALKIT_SOUND); + if (Sounds::KitLoops(sound)) { + aura.loopSoundID = sound; + aura.loopSound = Sounds::Loop(frame, sound, actor.position); + } else if (sound > 0) { + Sounds::Play(frame, sound, actor.position); + } const uint8_t *effect = DBC::Record(Offsets::VAR_SPELLVISUALEFFECTNAME_RECORDS, Offsets::VAR_SPELLVISUALEFFECTNAME_COUNT, Game::Read(aura.kit, Offsets::OFF_SPELLVISUALKIT_WORLD_EFFECT)); @@ -109,6 +125,10 @@ void ShowOne(Actor &actor, AuraVisual &aura) { // model. void HideOne(Actor &actor, AuraVisual &aura, bool stop) { void *frame = actor.SceneFrame(); + if (aura.loopSound != nullptr) + Sound::Play::Stop(aura.loopSound, stop ? Sounds::kStopFadeSec : 0.0f); + aura.loopSound = nullptr; + aura.loopSoundID = 0; for (void *effect : aura.effects) { if (stop) { Model::VisualKit::Stop(frame, effect); @@ -211,10 +231,30 @@ void ApplyColors(Actor &actor) { } } +// The world has no pause; a paused scene (or actor) silences the loops, which +// start again when the pause ends, as a hidden scene's do when it shows. void Update(Actor &actor, float elapsedSec) { + const bool held = IsPaused(actor.SceneFrame()) || actor.paused || actor.globalPaused; for (AuraVisual &aura : actor.auraVisuals) { if (aura.worldEffect != nullptr) SettleLight(aura.worldEffect, aura.worldLight.get(), elapsedSec); + if (aura.loopSoundID == 0) + continue; + if (held && aura.loopSound != nullptr) { + Sound::Play::Stop(aura.loopSound, 0.0f); + aura.loopSound = nullptr; + } else if (!held && aura.loopSound == nullptr) { + aura.loopSound = Sounds::Loop(actor.SceneFrame(), aura.loopSoundID, actor.position); + } + } +} + +void Silence(Actor &actor) { + for (AuraVisual &aura : actor.auraVisuals) { + if (aura.loopSound != nullptr) { + Sound::Play::Stop(aura.loopSound, 0.0f); + aura.loopSound = nullptr; + } } } @@ -230,6 +270,7 @@ void Link(Actor &actor) { void Place(Actor &actor) { const float axisZ[3] = {0.0f, 0.0f, 1.0f}; for (AuraVisual &aura : actor.auraVisuals) { + Sounds::Move(actor.SceneFrame(), aura.loopSound, actor.position); if (aura.worldEffect == nullptr) continue; if (aura.worldFollows) { diff --git a/src/model/SceneSound.cpp b/src/model/SceneSound.cpp index d859c07f..d79b5b5e 100644 --- a/src/model/SceneSound.cpp +++ b/src/model/SceneSound.cpp @@ -141,6 +141,14 @@ void *Loop(void *sceneFrame, int soundKitID, const float (&point)[3]) { return Sound::Play::PlayKitLoopedAt(soundKitID, heard); } +bool KitLoops(int soundID) { + using Flag_t = bool(__fastcall *)(uint32_t id, char *out); + char loops = 0; + return soundID > 0 && + reinterpret_cast(Offsets::FUN_SOUND_DEFINITION_KIT_LOOP)(static_cast(soundID), &loops) && + loops != 0; +} + void Move(void *sceneFrame, void *sound, const float (&point)[3]) { if (sound == nullptr) return; diff --git a/src/model/SceneSpell.cpp b/src/model/SceneSpell.cpp index b0a8b0fc..e2cf7a0a 100644 --- a/src/model/SceneSpell.cpp +++ b/src/model/SceneSpell.cpp @@ -155,7 +155,6 @@ constexpr int kAnimCombatWound = 9; constexpr int kAnimInFlight = 144; constexpr float kReleaseTimeoutSec = 2.0f; // 0x0060A814 constexpr float kMaxSpeed = 100.0f; // 0x0080C854 -constexpr float kSoundFadeSec = 0.15f; // the missile's free, 0x0061CD70 const Game::Live kAimHeight{Offsets::VAR_THREE_QUARTERS}; constexpr uint32_t kFallbackAttachments[] = {15, 19}; constexpr char kErrorCube[] = "Spells\\ErrorCube.mdx"; @@ -188,15 +187,6 @@ bool ChainLoaded(void *model) { return true; } -// Whether a kit's sound loops with a lasting kit (FUN_SOUND_DEFINITION_KIT_LOOP). -bool KitSoundLoops(int soundID) { - using Flag_t = bool(__fastcall *)(uint32_t id, char *out); - char loops = 0; - return soundID > 0 && - reinterpret_cast(Offsets::FUN_SOUND_DEFINITION_KIT_LOOP)(static_cast(soundID), &loops) && - loops != 0; -} - // The world's kit player on a unit, for a model: the effects (looping into // `effects`, or once and owned by the model), the animation and the sound. // A lasting kit (`loop`) records the animation it made the caster's loop, @@ -213,7 +203,7 @@ void PlayKit(Actor &actor, const uint8_t *kit, std::vector *effects, Spe loop->animation = anim; } const int sound = Game::Read(kit, Offsets::OFF_SPELLVISUALKIT_SOUND); - if (lasting && KitSoundLoops(sound)) { + if (lasting && Sounds::KitLoops(sound)) { loop->soundID = sound; loop->sound = Sounds::Loop(actor.SceneFrame(), sound, actor.position); } else { @@ -411,7 +401,7 @@ void FreeStuck(StuckMissile &stuck) { // over it (a wound) plays on. void EndKitLoop(Actor &caster, std::vector &effects, bool &tinted, SpellCast::KitLoop &loop) { if (loop.sound != nullptr) { - Sound::Play::Stop(loop.sound, kSoundFadeSec); + Sound::Play::Stop(loop.sound, Sounds::kStopFadeSec); loop.sound = nullptr; } loop.soundID = 0; @@ -451,7 +441,7 @@ void EndChannel(Actor &caster, SpellCast &cast) { void StopMissileSound(SpellCast &cast) { if (cast.missileSound != nullptr) { - Sound::Play::Stop(cast.missileSound, kSoundFadeSec); + Sound::Play::Stop(cast.missileSound, Sounds::kStopFadeSec); cast.missileSound = nullptr; } }