convert managedSoundSlots to u16 bitset

This commit is contained in:
Demur Rumed 2025-04-21 11:20:39 +00:00
commit a80a95ff6e
4 changed files with 20 additions and 25 deletions

View file

@ -55,7 +55,10 @@ typedef struct {
void accessible_en_ishi(AccessibleActor* actor) { void accessible_en_ishi(AccessibleActor* actor) {
ActorAccessibility_PlaySoundForActor(actor, 0, NA_SE_EN_OCTAROCK_ROCK, false); 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) { void accessible_en_NPC_Gen(AccessibleActor* actor) {
@ -814,10 +817,10 @@ void ActorAccessibility_InitActors() {
policy.n = Npc_Frames; policy.n = Npc_Frames;
policy.pitch = 1.1; policy.pitch = 1.1;
ActorAccessibility_AddSupportedActor(ACTOR_EN_GE1, policy); 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.n = 30;
policy.pitch = 0.7; 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); ActorAccessibility_InitPolicy(&policy, "Grotto Door", accessible_grotto, 0);
policy.n = 30; policy.n = 30;
policy.pitch = 1.0; policy.pitch = 1.0;

View file

@ -10,7 +10,7 @@
#include <unordered_map> #include <unordered_map>
#include <array> #include <array>
#define AAE_SOUND_ACTION_BATCH_SIZE 64 #define AAE_SOUND_ACTION_BATCH_SIZE 64
#define AAE_SLOTS_PER_HANDLE 10 #define AAE_SLOTS_PER_HANDLE 16
class IResource; class IResource;
struct DecodedSample { struct DecodedSample {
void* data; // A wav file. void* data; // A wav file.

View file

@ -202,8 +202,7 @@ void ActorAccessibility_TrackNewActor(Actor* actor) {
accessibleActor.baseVolume = accessibleActor.policy.volume; accessibleActor.baseVolume = accessibleActor.policy.volume;
accessibleActor.currentVolume = accessibleActor.policy.volume; accessibleActor.currentVolume = accessibleActor.policy.volume;
accessibleActor.sceneIndex = 0; accessibleActor.sceneIndex = 0;
for (int i = 0; i < NUM_MANAGED_SOUND_SLOTS; i++) accessibleActor.managedSoundSlots = 0;
accessibleActor.managedSoundSlots[i] = false;
accessibleActor.aimAssist.framesSinceAimAssist = 32768; accessibleActor.aimAssist.framesSinceAimAssist = 32768;
accessibleActor.aimAssist.frequency = 10; accessibleActor.aimAssist.frequency = 10;
accessibleActor.aimAssist.pitch = 1.0; accessibleActor.aimAssist.pitch = 1.0;
@ -296,32 +295,30 @@ void ActorAccessibility_ConfigureSoundForActor(AccessibleActor* actor, int slot)
ActorAccessibility_SetPitchBehindModifier(actor, slot, actor->policy.pitchModifier); ActorAccessibility_SetPitchBehindModifier(actor, slot, actor->policy.pitchModifier);
ActorAccessibility_SetSoundPos(actor, slot, &actor->projectedPos, actor->xyzDistToPlayer, actor->policy.distance); ActorAccessibility_SetSoundPos(actor, slot, &actor->projectedPos, actor->xyzDistToPlayer, actor->policy.distance);
ActorAccessibility_SetSoundVolume(actor, slot, actor->policy.volume); 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) { 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; return;
ActorAccessibility_PlaySound(actor, slot, sfxId, looping); ActorAccessibility_PlaySound(actor, slot, sfxId, looping);
ActorAccessibility_ConfigureSoundForActor(actor, slot); ActorAccessibility_ConfigureSoundForActor(actor, slot);
} }
void ActorAccessibility_PlaySampleForActor(AccessibleActor* actor, int slot, const char* name, bool looping) { 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; return;
ActorAccessibility_PlayRawSample(actor, slot, name, looping); ActorAccessibility_PlayRawSample(actor, slot, name, looping);
ActorAccessibility_ConfigureSoundForActor(actor, slot); ActorAccessibility_ConfigureSoundForActor(actor, slot);
} }
void ActorAccessibility_StopSoundForActor(AccessibleActor* actor, int 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; return;
ActorAccessibility_StopSound(actor, slot); 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); ActorAccessibility_StopAllSounds(actor);
for (int i = 0; i < NUM_MANAGED_SOUND_SLOTS; i++) actor->managedSoundSlots = 0;
actor->managedSoundSlots[i] = false;
} }
bool ActorAccessibility_IsRealActor(AccessibleActor* actor) { bool ActorAccessibility_IsRealActor(AccessibleActor* actor) {
@ -367,8 +364,8 @@ void ActorAccessibility_RunAccessibilityForActor(PlayState* play, AccessibleActo
return; return;
} }
// Send sound parameters to the new audio engine. Eventually remove the old stuff once all actors are carried over. // 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++) { for (int i = 0; i < AAE_SLOTS_PER_HANDLE; i++) {
if (actor->managedSoundSlots[i]) { if (actor->managedSoundSlots & (1 << i)) {
ActorAccessibility_SetSoundPos(actor, i, &actor->projectedPos, actor->xyzDistToPlayer, ActorAccessibility_SetSoundPos(actor, i, &actor->projectedPos, actor->xyzDistToPlayer,
actor->policy.distance); actor->policy.distance);
// Judgement call: pitch changes are rare enough that it doesn't make sense to pay the cost of updating it // 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.play = NULL;
actor.world = where; actor.world = where;
actor.sceneIndex = 0; actor.sceneIndex = 0;
for (int i = 0; i < NUM_MANAGED_SOUND_SLOTS; i++) actor.managedSoundSlots = 0;
actor.managedSoundSlots[i] = 0;
actor.aimAssist.framesSinceAimAssist = 0; actor.aimAssist.framesSinceAimAssist = 0;
actor.aimAssist.frequency = 10; actor.aimAssist.frequency = 10;
actor.aimAssist.pitch = 1.0; actor.aimAssist.pitch = 1.0;

View file

@ -4,9 +4,6 @@
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #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; struct AccessibleActor;
typedef struct AccessibleActor AccessibleActor; typedef struct AccessibleActor AccessibleActor;
// A callback that is run regularely as the game progresses in order to provide accessibility services for an actor. // 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; f32 currentPitch;
s16 sceneIndex; // If this actor represents a scene transition, then this will contain the destination scene index. s16 sceneIndex; // If this actor represents a scene transition, then this will contain the destination scene index.
// Zero otherwise. // Zero otherwise.
bool managedSoundSlots[NUM_MANAGED_SOUND_SLOTS]; // These have their attenuation and panning parameters updated u16 managedSoundSlots; // These have their attenuation and panning parameters updated every frame automatically.
// every frame automatically.
struct { struct {
u16 framesSinceAimAssist; // Allows rate-based vertical aim assist. Incremented every frame for aim assist u16 framesSinceAimAssist; // Allows rate-based vertical aim assist. Incremented every frame for aim assist
// actors. Manually reset by aim assist provider. // actors. Manually reset by aim assist provider.
f32 pitch; // Used to report whether Link is aiming higher or lower than the actor. 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 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; } aimAssist;
// Add more state as needed. // Add more state as needed.