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

[no squash] Optimizations and code quality improvements #83

Conversation

Emojigit
Copy link
Member

@Emojigit Emojigit commented Oct 25, 2024

This PR optimizes some parts and improves code quality by following lua_api.md recommendations.

Check individual commits for what this PR does and why the changes are made.

For "Prevent saving entities": Due to how static_save = false works, old entities may linger but disappear after punching them or restarting the server again.

This PR is ready for review.

internal.lua Outdated Show resolved Hide resolved
internal.lua Outdated Show resolved Hide resolved
async.lua Outdated Show resolved Hide resolved
async.lua Outdated Show resolved Hide resolved
async.lua Outdated Show resolved Hide resolved
pos.lua Show resolved Hide resolved
@Emojigit
Copy link
Member Author

Other than what I've commented on, I will apply those suggestions later.

This eliminates the need of iterating the whole list for every protection operations. Note that the highest index isn't cached, i.e. the first or few (if there are many holes) operations would still suffer from the lag.
Copy link
Member

@SmallJoker SmallJoker left a comment

Choose a reason for hiding this comment

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

Looks good in general; only a few minor remarks.

async.lua Outdated Show resolved Hide resolved
pos.lua Outdated Show resolved Hide resolved
pos.lua Show resolved Hide resolved
Copy link
Member

@SmallJoker SmallJoker left a comment

Choose a reason for hiding this comment

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

✔ Area protection works
✔ ID counter works (gaps are filled after a server restart)
✔ Markers do spawn and are removed correctly
✔ Async area saving works
✘ Backwards compatibility does not work (see comment)

async.lua Outdated Show resolved Hide resolved
internal.lua Outdated Show resolved Hide resolved
On newer Minetest servers, handles saving jobs in async environment. To prevent conflicts, the save file is locked whie saving, and if a code requests saving while the file is locked, data is saved again immediately after finishing the current save.
startTime is not used anywhere else, so localizing it makes sense and saves memory.
This may add lag, but stops saving entities (which lua_api.md discourages). This also eliminates areas.markPos{1,2} (which seemed to be internal) and integrates areas:setPos{1,2} with such function.
Merges "pos1" and "pos1only" into the same code.
Copy link
Member

@SmallJoker SmallJoker left a comment

Choose a reason for hiding this comment

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

Works. Will merge in a few days unless there are objections.

@SmallJoker SmallJoker merged commit 733e263 into minetest-mods:master Nov 5, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants