Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor EffPlaySound to be more readable and resistant to versioning issues. #7022

Merged
merged 10 commits into from
Sep 1, 2024

Conversation

sovdeeth
Copy link
Member

@sovdeeth sovdeeth commented Sep 1, 2024

Description

The current state of EffPlaySound relies on a lot of nested FunctionalInterfaces with static methods that makes it quite hard to follow, read, and debug. Issues with differing version support has resulted in two bugs so far, one that has caused an inability to use entity emitters on 1.18 despite the API existing, since the current impl isn't flexible enough to allow it.

This PR re-introduces that feature by refactoring EffPlaySound to use an adapter pattern to unify Player and World playSound methods. It also moves sound validation, among other things, outside of the player loop which should both improve performance and fix an issue where the sound expression was being evaluated once for each player.

I have done manual testing on 1.17, 1.18, and 1.21, though I think junit tests should be implemented via mocking, if feasible. I have not yet looked into that. I would also appreciate any users with existing sound-heavy code to test this PR's nightly out if they can (click Checks -> Java 21 CI -> download from Artifacts).


Target Minecraft Versions: any
Requirements: none
Related Issues: #7016, #6907, #6910

@sovdeeth sovdeeth added bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. enhancement Feature request, an issue about something that could be improved, or a PR improving something. 2.9 Targeting a 2.9.X version release labels Sep 1, 2024
Copy link
Member

@Moderocky Moderocky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good.

@Moderocky Moderocky added the patch-ready A PR/issue that has been approved and is ready to be merged/closed for the next patch version. label Sep 1, 2024
Copy link
Contributor

@TheLimeGlass TheLimeGlass left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still find kiip's FunctionalInterface usage here easier to read.

Performance was the same for execution. Initialization of the EffPlaySound class was 50-90ms better than existing.

@Moderocky Moderocky merged commit e0862a8 into SkriptLang:dev/patch Sep 1, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.9 Targeting a 2.9.X version release bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. enhancement Feature request, an issue about something that could be improved, or a PR improving something. patch-ready A PR/issue that has been approved and is ready to be merged/closed for the next patch version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants