Fix argon volume-aware hitsounds not correctly playing immediately after object placement #29970
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.
Closes #29832.
The underlying reason for the incorrect sample playback was an equality comparer failure.
Samples are contained in several pools which are managed by the playfield. In particular, the pools are keyed by
ISampleInfo
instances:osu/osu.Game/Rulesets/UI/Playfield.cs
Lines 457 to 464 in ccf1acc
This means that for correct operation,
ISampleInfo
has to implementIEquatable<ISampleInfo>
and also provide an appropriately correctGetHashCode()
implementation. Different audible samples must not compare equal to each other when represented byISampleInfo
.As it turns out,
VolumeAwareHitSampleInfo
failed on this, due to not overriding equality members. Therefore, anew HitSampleInfo(HitSampleInfo.HIT_NORMAL, HitSampleInfo.BANK_NORMAL, volume: 70)
was allowed to compare equal to aVolumeAwareHitSampleInfo
wrapping it, even though they correspond to completely different sounds and go through entirely different lookup path sequences.Therefore, to fix, provide more proper equality implementations for
VolumeAwareHitSampleInfo
.When testing note that this issue only occurs immediately after placing an object. Saving and re-entering editor makes this issue go away. I haven't looked too long into why, but the general gist of it is ordering; it appears that a
normal-hitnormal
pool exists at point of query of a new object placement, but does not seem to exist when entering editor afresh. That said I'm not sure that ordering aspect of this bug matters much if at all, since the twoIHitSampleInfo
s should never be allowed to alias with each other at all wrt equality.