You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
xezon
added
Audio
Is audio related
Minor
Severity: Minor < Major < Critical < Blocker
Gen
Relates to Generals
ZH
Relates to Zero Hour
Refactor
Edits the code with insignificant behavior changes, is never user facing
labels
Jun 7, 2026
This PR removes the manual counter-based tracking of playing audio samples (m_numPlaying2DSamples, m_numPlaying3DSamples and their notify callbacks) in favour of directly reading the size of the m_availableSamples / m_available3DSamples handle pools. The std::list containers are also replaced with std::vector for better cache performance.
Counter removal: notifyOf2DSampleStart/Completion and their 3D counterparts are deleted; canPlayNow now calls TheAudio->getAvailable2DSamples() > 0 and getAvailable3DSamples() > 0, which correctly mirrors the old m_numPlaying < m_num comparison because handles are already pushed back into the vector by releaseMilesHandles on completion.
std::list → std::vector: Both available-handle pools switch to std::vector, using push_back/pop_back for O(1) acquisition and return; freeAllMilesHandles now iterates then clears rather than erasing in-loop, fixing the infinite-loop bug mentioned in a prior review thread.
getAvailable2DSamples / getAvailable3DSamples: New virtual methods on AudioManager delegate to m_availableSamples.size() / m_available3DSamples.size(), giving an always-accurate available count without extra bookkeeping.
Confidence Score: 5/5
The change is safe to merge; it replaces a manual counter system with direct vector-size tracking, and the handle lifecycle is consistent throughout.
Handle acquisition and return paths are both correct: getFirst2DSample/getFirst3DSample pop from the vector, and releaseMilesHandles pushes back on completion or failure. The canPlayNow semantics are preserved exactly. The freeAllMilesHandles infinite-loop regression flagged earlier is addressed by iterating with ++it then clearing. No new bugs are introduced.
Core implementation of the refactor: list→vector, notify calls removed, new getAvailable*Samples() implementations, and corrected freeAllMilesHandles loop. Handle lifecycle (pop_back on acquire, push_back on release) is correctly maintained throughout.
canPlayNow updated to query getAvailable*Samples() instead of comparing counters; lazy-init of sample counts removed. Logic is equivalent to prior behavior.
Declares new getAvailable2DSamples/getAvailable3DSamples overrides and changes member containers from std::list to std::vector.
Core/GameEngine/Include/Common/GameAudio.h
Adds pure virtual getAvailable2DSamples() and getAvailable3DSamples() to the AudioManager interface.
Core/GameEngine/Include/Common/GameSounds.h
Removes notify callbacks, available-sample helpers, and the two counter member variables from SoundManager.
Sequence Diagram
sequenceDiagram
participant SM as SoundManager
participant AM as AudioManager
participant MAM as MilesAudioManager
participant Pool as AvailablePool
Note over SM,Pool: canPlayNow check
SM->>AM: getAvailable2DSamples()
AM->>MAM: getAvailable2DSamples()
MAM->>Pool: size()
Pool-->>SM: N handles available
Note over MAM,Pool: Audio starts playing
MAM->>Pool: pop_back via getFirst2DSample
Pool-->>MAM: HSAMPLE handle
MAM->>MAM: playSample(event, handle)
Note over MAM,Pool: Audio stops
MAM->>Pool: push_back via releaseMilesHandles
Pool-->>MAM: handle returned, size increases
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AudioIs audio relatedGenRelates to GeneralsMinorSeverity: Minor < Major < Critical < BlockerRefactorEdits the code with insignificant behavior changes, is never user facingZHRelates to Zero Hour
1 participant
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.