Sound Physics Remastered

Sound Physics Remastered

38M Downloads

Avoidable stuttering when using updateMovingSounds=true

briansemrau opened this issue ยท 6 comments

commented

Bug description
When playing with update_moving_sounds=true, I get significant stuttering (~60ms frame time vs 16ms median)

Versions

  • Minecraft version: 1.19.2
  • Mod version: 1.0.16
  • Fabric

I was wondering why this was happening, so I glanced at the source code:

private void tickNonPaused(CallbackInfo ci, Iterator<?> iterator, Map.Entry<SoundInstance, ChannelAccess.ChannelHandle> map, ChannelAccess.ChannelHandle channelHandle, SoundInstance sound) {
if (!SoundPhysicsMod.CONFIG.updateMovingSounds.get()) {
return;
}
if (minecraft.level != null && minecraft.level.getGameTime() % 5 == 0) {
channelHandle.execute(channel -> {
SoundPhysics.processSound(((ChannelAccessor) channel).getSource(), sound.getX(), sound.getY(), sound.getZ(), sound.getSource(), sound.getLocation().getPath());
});
}
}

Yeah, that'll do it. This should be reworked to stagger sound updates across every tick.

Suggested fix:

- if (minecraft.level != null && minecraft.level.getGameTime() % 5 == 0) {
+ if (minecraft.level != null && (minecraft.level.getGameTime() + sound.getId().hashCode()) % 5 == 0) {
commented

Ah, I quickly assumed that getId would return a UUID, not a name. My bad. I suppose a randomized int could be added to SoundInstance as a mixin.

I don't have the built tools set up to test any solution locally, so feel free to make the PR if you like.

commented

No worries. Thank you for investigating the issue :)

commented

Yes, we are aware of that issue but we haven't investigated that yet. Your solution looks good! I personally wouldn't use the ID of the sound as it might be the same for sounds that get played multiple times.
Do you want to make a PR or should I do it?

commented

It's now up on curse and modrinth. I also added a config value for the actual interval (5 by default).

commented

That was fast! I'll give it a whirl.

commented

Ah, I quickly assumed that getId would return a UUID, not a name. My bad. I suppose a randomized int could be added to SoundInstance as a mixin.

Turns out the hashcode of the sound instance itself is the best fit, since it stays the same for every individual sound.