refactor(audio): Simplify available audio samples management#2773
refactor(audio): Simplify available audio samples management#2773xezon wants to merge 6 commits into
Conversation
|
| Filename | Overview |
|---|---|
| Core/GameEngine/Include/Common/GameAudio.h | Adds two pure virtual methods getNumAvailable2DSamples() and getNumAvailable3DSamples() to the AudioManager interface. |
| Core/GameEngine/Include/Common/GameSounds.h | Removes the four notify methods, getAvailableSamples(), getAvailable3DSamples(), and the four counter member variables from SoundManager. |
| Core/GameEngine/Source/Common/Audio/GameSounds.cpp | Removes all counter management and notification method implementations; canPlayNow now delegates to TheAudio->getNumAvailable2/3DSamples() for availability checks. |
| Core/GameEngineDevice/Include/MilesAudioDevice/MilesAudioManager.h | Adds override declarations for the two new virtual methods, renames getFirst2/3DSample to getAvailable2/3DSample, and changes pool containers from std::list to std::vector. |
| Core/GameEngineDevice/Source/MilesAudioDevice/MilesAudioManager.cpp | Implements getNumAvailable2/3DSamples() as m_availableSamples.size(), fixes the freeAllMilesHandles iterator loop, adds reserve in initSamplePools, removes all notifyOf* call sites, and fixes the audioDebugDisplay copy-paste bug. |
Sequence Diagram
%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant SM as SoundManager
participant AM as AudioManager (interface)
participant MAM as MilesAudioManager
Note over SM,MAM: canPlayNow() — availability check
SM->>AM: getNumAvailable3DSamples()
AM->>MAM: (virtual dispatch)
MAM-->>SM: m_available3DSamples.size()
Note over SM,MAM: playAudioEvent() — acquire handle
SM->>MAM: addAudioEvent(event)
MAM->>MAM: getAvailable3DSample() → pop_back()
MAM->>MAM: playSample3D(event, sample)
alt play succeeded
MAM->>MAM: m_playing3DSounds.push_back(audio)
else play failed
MAM->>MAM: stopPlayingAudio(audio)
MAM->>MAM: releaseMilesHandles() → m_available3DSamples.push_back(sample)
end
Note over SM,MAM: stopPlayingAudio() — return handle
MAM->>MAM: releaseMilesHandles(release)
MAM->>MAM: m_available3DSamples.push_back(sample)
Note over MAM: getNumAvailable3DSamples() == m_available3DSamples.size() (ground truth)
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant SM as SoundManager
participant AM as AudioManager (interface)
participant MAM as MilesAudioManager
Note over SM,MAM: canPlayNow() — availability check
SM->>AM: getNumAvailable3DSamples()
AM->>MAM: (virtual dispatch)
MAM-->>SM: m_available3DSamples.size()
Note over SM,MAM: playAudioEvent() — acquire handle
SM->>MAM: addAudioEvent(event)
MAM->>MAM: getAvailable3DSample() → pop_back()
MAM->>MAM: playSample3D(event, sample)
alt play succeeded
MAM->>MAM: m_playing3DSounds.push_back(audio)
else play failed
MAM->>MAM: stopPlayingAudio(audio)
MAM->>MAM: releaseMilesHandles() → m_available3DSamples.push_back(sample)
end
Note over SM,MAM: stopPlayingAudio() — return handle
MAM->>MAM: releaseMilesHandles(release)
MAM->>MAM: m_available3DSamples.push_back(sample)
Note over MAM: getNumAvailable3DSamples() == m_available3DSamples.size() (ground truth)
Reviews (3): Last reviewed commit: "Rename getAvailable3DSample" | Re-trigger Greptile
| HSAMPLE retSample = *m_availableSamples.begin(); | ||
| m_availableSamples.erase(m_availableSamples.begin()); | ||
| return (retSample); | ||
| if (!m_availableSamples.empty()) { |
There was a problem hiding this comment.
This gets the last sample in the vector, but the function name says first. Originally it would also get the first sample in the list.
I presume this is for performance (FILO instead of FIFO), but the naming of function and comments - that talk about 'first' are confusing.
There was a problem hiding this comment.
Good point. Renamed to getAvailableXXSample
| for ( it3D = m_available3DSamples.begin(); it3D != m_available3DSamples.end(); ) { | ||
| std::vector<H3DSAMPLE>::iterator it3D; | ||
| for ( it3D = m_available3DSamples.begin(); it3D != m_available3DSamples.end(); ++it3D ) { | ||
| H3DSAMPLE sample3D = *it3D; |
There was a problem hiding this comment.
Temporary variable not needed I think
AIL_release_3D_sample_handle(*it3D);| std::vector<HSAMPLE>::iterator it; | ||
| for ( it = m_availableSamples.begin(); it != m_availableSamples.end(); ++it ) { | ||
| HSAMPLE sample = *it; | ||
| AIL_release_sample_handle(sample); |
There was a problem hiding this comment.
Temporary variable not needed I think
AIL_release_3D_sample_handle(*it);
This change simplifies the available audio samples management.
Instead of manually counting at various callsites, it now simply calculates the available audio samples from the vectors. The numbers are used mostly for debug purposes, except in
SoundManager::canPlayNow.