From a80a95ff6ee6ecea05df2b8bcfaea6c653e0cc4f Mon Sep 17 00:00:00 2001 From: Demur Rumed Date: Mon, 21 Apr 2025 11:20:39 +0000 Subject: [PATCH] convert managedSoundSlots to u16 bitset --- .../accessible-actors/AccessibleActorList.cpp | 9 ++++--- .../accessible-actors/AccessibleAudioEngine.h | 2 +- .../accessible-actors/ActorAccessibility.cpp | 26 ++++++++----------- .../accessible-actors/ActorAccessibility.h | 8 ++---- 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/soh/soh/Enhancements/accessible-actors/AccessibleActorList.cpp b/soh/soh/Enhancements/accessible-actors/AccessibleActorList.cpp index 6553dcbb4..f6437a694 100644 --- a/soh/soh/Enhancements/accessible-actors/AccessibleActorList.cpp +++ b/soh/soh/Enhancements/accessible-actors/AccessibleActorList.cpp @@ -55,7 +55,10 @@ typedef struct { void accessible_en_ishi(AccessibleActor* actor) { ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EN_OCTAROCK_ROCK, false); - // ActorAccessibility_PlaySpecialSound(actor, NA_SE_EN_OCTAROCK_ROCK); +} + +void accessible_en_bombiwa(AccessibleActor* actor) { + ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EN_ROCK_BROKEN, false); } void accessible_en_NPC_Gen(AccessibleActor* actor) { @@ -814,10 +817,10 @@ void ActorAccessibility_InitActors() { policy.n = Npc_Frames; policy.pitch = 1.1; ActorAccessibility_AddSupportedActor(ACTOR_EN_GE1, policy); - ActorAccessibility_InitPolicy(&policy, "Brown Bombable Rock", accessible_en_ishi, 0); + ActorAccessibility_InitPolicy(&policy, "Brown Bombable Rock", accessible_en_bombiwa, 0); policy.n = 30; policy.pitch = 0.7; - ActorAccessibility_AddSupportedActor(ACTOR_OBJ_BOMBIWA, policy); // Improve? + ActorAccessibility_AddSupportedActor(ACTOR_OBJ_BOMBIWA, policy); ActorAccessibility_InitPolicy(&policy, "Grotto Door", accessible_grotto, 0); policy.n = 30; policy.pitch = 1.0; diff --git a/soh/soh/Enhancements/accessible-actors/AccessibleAudioEngine.h b/soh/soh/Enhancements/accessible-actors/AccessibleAudioEngine.h index cf3d05dc9..559b18f37 100644 --- a/soh/soh/Enhancements/accessible-actors/AccessibleAudioEngine.h +++ b/soh/soh/Enhancements/accessible-actors/AccessibleAudioEngine.h @@ -10,7 +10,7 @@ #include #include #define AAE_SOUND_ACTION_BATCH_SIZE 64 -#define AAE_SLOTS_PER_HANDLE 10 +#define AAE_SLOTS_PER_HANDLE 16 class IResource; struct DecodedSample { void* data; // A wav file. diff --git a/soh/soh/Enhancements/accessible-actors/ActorAccessibility.cpp b/soh/soh/Enhancements/accessible-actors/ActorAccessibility.cpp index 7d6f9cdfd..b9e623ef6 100644 --- a/soh/soh/Enhancements/accessible-actors/ActorAccessibility.cpp +++ b/soh/soh/Enhancements/accessible-actors/ActorAccessibility.cpp @@ -202,8 +202,7 @@ void ActorAccessibility_TrackNewActor(Actor* actor) { accessibleActor.baseVolume = accessibleActor.policy.volume; accessibleActor.currentVolume = accessibleActor.policy.volume; accessibleActor.sceneIndex = 0; - for (int i = 0; i < NUM_MANAGED_SOUND_SLOTS; i++) - accessibleActor.managedSoundSlots[i] = false; + accessibleActor.managedSoundSlots = 0; accessibleActor.aimAssist.framesSinceAimAssist = 32768; accessibleActor.aimAssist.frequency = 10; accessibleActor.aimAssist.pitch = 1.0; @@ -296,32 +295,30 @@ void ActorAccessibility_ConfigureSoundForActor(AccessibleActor* actor, int slot) ActorAccessibility_SetPitchBehindModifier(actor, slot, actor->policy.pitchModifier); ActorAccessibility_SetSoundPos(actor, slot, &actor->projectedPos, actor->xyzDistToPlayer, actor->policy.distance); ActorAccessibility_SetSoundVolume(actor, slot, actor->policy.volume); - actor->managedSoundSlots[slot] = true; + actor->managedSoundSlots |= 1 << slot; } void ActorAccessibility_PlaySoundForActor(AccessibleActor* actor, int slot, s16 sfxId, bool looping) { - if (slot < 0 || slot > NUM_MANAGED_SOUND_SLOTS) + if (slot < 0 || slot > AAE_SLOTS_PER_HANDLE) return; ActorAccessibility_PlaySound(actor, slot, sfxId, looping); ActorAccessibility_ConfigureSoundForActor(actor, slot); } void ActorAccessibility_PlaySampleForActor(AccessibleActor* actor, int slot, const char* name, bool looping) { - if (slot < 0 || slot > NUM_MANAGED_SOUND_SLOTS) + if (slot < 0 || slot > AAE_SLOTS_PER_HANDLE) return; ActorAccessibility_PlayRawSample(actor, slot, name, looping); ActorAccessibility_ConfigureSoundForActor(actor, slot); } void ActorAccessibility_StopSoundForActor(AccessibleActor* actor, int slot) { - if (slot < 0 || slot >= NUM_MANAGED_SOUND_SLOTS) + if (slot < 0 || slot >= AAE_SLOTS_PER_HANDLE) return; ActorAccessibility_StopSound(actor, slot); - actor->managedSoundSlots[slot] = false; + actor->managedSoundSlots &= ~(1 << slot); } -void ActorAccessibility_StopAllSoundsForActor(AccessibleActor* actor) -{ +void ActorAccessibility_StopAllSoundsForActor(AccessibleActor* actor) { ActorAccessibility_StopAllSounds(actor); - for (int i = 0; i < NUM_MANAGED_SOUND_SLOTS; i++) - actor->managedSoundSlots[i] = false; + actor->managedSoundSlots = 0; } bool ActorAccessibility_IsRealActor(AccessibleActor* actor) { @@ -367,8 +364,8 @@ void ActorAccessibility_RunAccessibilityForActor(PlayState* play, AccessibleActo return; } // Send sound parameters to the new audio engine. Eventually remove the old stuff once all actors are carried over. - for (int i = 0; i < NUM_MANAGED_SOUND_SLOTS; i++) { - if (actor->managedSoundSlots[i]) { + for (int i = 0; i < AAE_SLOTS_PER_HANDLE; i++) { + if (actor->managedSoundSlots & (1 << i)) { ActorAccessibility_SetSoundPos(actor, i, &actor->projectedPos, actor->xyzDistToPlayer, actor->policy.distance); // Judgement call: pitch changes are rare enough that it doesn't make sense to pay the cost of updating it @@ -553,8 +550,7 @@ AccessibleActor* ActorAccessibility_AddVirtualActor(VirtualActorList* list, VIRT actor.play = NULL; actor.world = where; actor.sceneIndex = 0; - for (int i = 0; i < NUM_MANAGED_SOUND_SLOTS; i++) - actor.managedSoundSlots[i] = 0; + actor.managedSoundSlots = 0; actor.aimAssist.framesSinceAimAssist = 0; actor.aimAssist.frequency = 10; actor.aimAssist.pitch = 1.0; diff --git a/soh/soh/Enhancements/accessible-actors/ActorAccessibility.h b/soh/soh/Enhancements/accessible-actors/ActorAccessibility.h index fda9b1034..301f0c96b 100644 --- a/soh/soh/Enhancements/accessible-actors/ActorAccessibility.h +++ b/soh/soh/Enhancements/accessible-actors/ActorAccessibility.h @@ -4,9 +4,6 @@ #ifdef __cplusplus extern "C" { #endif -#define NUM_MANAGED_SOUND_SLOTS \ - 10 // How many auto-managed sound slots can any given actor have? this can differ from AAE_SLOTS_PER_HANDLE, but - // cannot be greater. struct AccessibleActor; typedef struct AccessibleActor AccessibleActor; // A callback that is run regularely as the game progresses in order to provide accessibility services for an actor. @@ -75,14 +72,13 @@ struct AccessibleActor { f32 currentPitch; s16 sceneIndex; // If this actor represents a scene transition, then this will contain the destination scene index. // Zero otherwise. - bool managedSoundSlots[NUM_MANAGED_SOUND_SLOTS]; // These have their attenuation and panning parameters updated - // every frame automatically. + u16 managedSoundSlots; // These have their attenuation and panning parameters updated every frame automatically. struct { u16 framesSinceAimAssist; // Allows rate-based vertical aim assist. Incremented every frame for aim assist // actors. Manually reset by aim assist provider. f32 pitch; // Used to report whether Link is aiming higher or lower than the actor. u8 frequency; // How often the sound will be played. Lower frequencies indicate that Link's vertical aim is - // closer to the actor. } aimAssist; + // closer to the actor. } aimAssist; // Add more state as needed.