Force re-clustering when the user changes the distance threshold value #3
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.
Description
This PR introduces the ability to force a re-cluster of all audio objects when the distance threshold RTPC is changed in real-time.
Previously for a new threshold value to take effect, either the game-scene would have to change completely, or the plugin should be manually re-initialized to the bus. This means that the user would have to wait for all existing clusters to die so new ones are formed with the new assigned threshold value. Of course this is not optimal and can create the impression that the UI slider is not functional.
To solve this, we clear existing structures that hold cluster information and mark them as non-clustered, so they are forced to be re-clustered in the next frame. Keep in mind though, that the existing output objects will not be deleted with a slider change, as this would introduce potential crashes or sounds to disappear.
Technical Details
resetmethod that resets the internal state of the KMeans algorithm.ObjectClusterFXwe are checking for changes in the threshold RTPC, we force re-clustering.ForceReclustering()which clears the member variablem_clusterstheAkMixerInputMapstructure (which is the most important for the re-clustering to happen) and finallyreset()the internal state of KMeans.Testing:
To test these changes, I recommend the following steps:
You should see the audio object consumption being reduced drastically.
The GIF below shows a scene with 40 spawned enemies, initially the audio object consumption is 70-80 objects, when the threshold increases it drops to 38-40 depending on the events, which is the expected value.
and on another example with 20 enemies:
slider.change.mp4