Fix Vaccinator charge sounds playing multiple times per tick #22
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.
Due to prediction, the PrimaryAttack() function runs multiple times every tick. Every time the function runs on a tick where the player gains a charge, it will stack a copy of the sound that plays, which quickly becomes extremely loud. Commonly this will play 2 or 3, but in testing I've seen upwards of 7 or 8 playing at the same time.
This PR partially relies on #21, as prediction errors also can cause the charge to revert back to below the threshold for playing the sound, so this isn't a full fix unfortunately. I'm not sure how you would fix that to not cause issues when poor connection causes prediction errors.
Related Issue
Source-1-Games Issue 4479
Implementation
Add a
IsFirstTimePredicted()
check to the Vaccinator specific sound code, preventing it from playing on extra function calls used for prediction. Valve uses this function themselves twice in the medigun code alone to try and prevent some sound code from being run more than once.Screenshots
Checklist
tc2-mod
branch.Testing Checklist
Caveats
Its possible that in an attempt to mitigate the issue Valve may have made the vaccinator charge noises quieter than they otherwise would've been, causing them to be pretty quiet in the instance that the bug was fixed. I have not tested if I think this is an issue, and I feel like it partially would be subjective anyway
Alternatives
In the past I implemented a very poor bandaid fix involving a variable which was incremented when a new charge was gotten and decremented when one was used, preventing the sound from playing more than once for each charge. Comparatively it was over-complicated and did not fix the heart of the issue