-
Notifications
You must be signed in to change notification settings - Fork 53
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
Make smallest area concept optional #80
Merged
Merged
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
aa14c9d
check interact permission on smallest area at position
SwissalpS 1b86480
expose getSmallestAreaAtPos()
SwissalpS fd6d7e4
also return area id
SwissalpS 56763e1
cleanup as suggested by SmallJoker
SwissalpS 2d15113
Merge branch 'master' of https://github.com/minetest-mods/areas
SwissalpS 68e8237
make smallest area concept optional
SwissalpS e50cc25
revised description of setting
SwissalpS 71ae3c0
de-duplicate code using table
SwissalpS 1f770bc
revised settingtypes.txt thanks SmallJoker
SwissalpS a4a4ff3
whitespace tweak
SwissalpS 2b43015
shorten code and indicate why var is needed
SwissalpS 321b96b
Merge branch 'optionalSmallestAreaUsingTable'
SwissalpS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is duplicated. Please offload it to a function or find out a smarter way.
Hint:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part of code is used a lot, so I took the time to write two variants and benchmark them. The results did not show any clear difference in execution speed on my old laptop in a devtest game with only areas and playerfactions mods.
To keep it simple the test world had no factions or areas defined at all.
Variant A (function):
https://github.com/SwissalpS/minetest_areas/blob/665d308c99bf771d77ef738c17c97d347039800e/api.lua#L118-L171
branch function
Variant B (table):
https://github.com/SwissalpS/minetest_areas/blob/71ae3c0a6ca80698f364142d80342bceb7a48214/api.lua#L118-L159
branch table
Variant B uses 12 lines less, I prefer Variant A by a slim margin for its readability, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whether to pick A (helper func) or B (new table) is entirely subjective. Though, I find it interesting that the local function showed no performance impact. LuaJIT might realize that none of the caller's function stack is needed, thus resulting in a negligible performance difference.
I prefer variant B (L126-128 could be removed too) for having more linear code flow (top to bottom) and smaller branches (as in LoC).
Your preference - variant A - is also OK. It could further be reduced in line count by moving the remaining access checks into the helper function (name would be subject to change).
Implement what you think is easier to understand. I'll be fine with either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe my computer has way to much on its hands to be a good platform for benchmarks. Other processes might influence the results.
I don't think my setup is using LuaJIT. On another repo I was using
table.pack
which the CI of github didn't have and somebody comented that LuaJIT doesn't have that.OK, I did feel it made clearer what was going on, but it works since my other concern has disappeared with these changes.
Instead I added ", _" in line 124 to make clear why the variable
smallest_area
is needed: