public sealed class VariantSelectorPicks the next variant, without allocating and without asking a clock.
No guide page documents this yet — the page shows what the code says about itself.
Remarks
Split out from AudioEvent because "which one plays next" is the part with the interesting behaviour and no dependencies — it is a function of a mode, some weights and a seed, so it can be tested by calling Next a thousand times and counting, with no mixer, no device and no clip anywhere near it.
Seeded, so a run is reproducible. The same selector built the same way produces the same sequence on every machine and every platform, which is what lets a test assert the order rather than assert a histogram — and what would let a replay or a lockstep simulation keep two machines' audio in step, if one ever wanted that.
Game thread only. Nothing here is synchronised: an event is played from gameplay code, and the audio thread never sees a selector.
Fields and properties (3)
public VariantSelection ModeHow it chooses.
public int CountHow many variants there are to choose between.
public int LastWhat Next returned last, or −1 before the first call.
Methods (3)
public VariantSelector(ReadOnlySpan<float> weights, VariantSelection mode, uint seed = 0)A selector over some weighted variants.
public int Next()Chooses the next variant.
public void Reset()Forgets everything: the bag, the cursor, and what played last.
Used by (4)
- AudioEventVixen.Audio
- AudioEventAssetTestsVixen.Audio.Tests
- AudioEventTestsVixen.Audio.Tests
- VariantSelectionTestsVixen.Audio.Tests