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

on_deactivate: distinguish removal and unloading #11931

Merged
merged 2 commits into from
Jun 11, 2022

Conversation

appgurueu
Copy link
Contributor

@appgurueu appgurueu commented Jan 5, 2022

  • Goal of the PR: What it says on the tin.
  • How does the PR work? Just propagates a boolean parameter.

Sometimes you need to be able to do removal-related cleanup, such as removing files from disk, or entries from a database. staticdata obviously isn't suitable for large data. The data shouldn't be removed if the entity is unloaded, only if it is removed.

Ready for Review.

How to test

Execute /spawnentity testentities:callback, then:

  • Kill the entity.
  • Execute /clearobjects.
  • Go away and wait for the entity to be unloaded.

@sfan5 sfan5 added @ Script API Feature ✨ PRs that add or enhance a feature labels Jan 6, 2022
@Andrey2470T
Copy link
Contributor

I wonder why on_deactivate is called also on removal at all. There's already on_death callback that is called when an object gets removed. So shouldn't it be called only on deactivation based on its name?

@appgurueu
Copy link
Contributor Author

I wonder why on_deactivate is called also on removal at all. There's already on_death callback that is called when an object gets removed. So shouldn't it be called only on deactivation based on its name?

The docs say something different and the docs are correct (I tested this). Removal != death; death is only one specific case of removal that occurs when the HP is set to 0. clear_objects or a direct call to object:remove() may also remove an object without calling on_death, but calling on_deactivate. on_deactivate must still be called in these cases for backwards compatibility, even if calling on_remove instead might seem cleaner. So I opted for the boolean param.

@rubenwardy rubenwardy assigned rubenwardy and unassigned rubenwardy Jan 24, 2022
@rubenwardy rubenwardy added the Roadmap The change matches an item on the current roadmap. label Jan 24, 2022
doc/lua_api.txt Outdated Show resolved Hide resolved
@Wuzzy2
Copy link
Contributor

Wuzzy2 commented Jun 10, 2022

👍 I support this. This PR is required for me to fix a bug in Repixture because I need a way to properly clean up state, and no amount Lua hackery can work around the fact my mods currently doesn't know whether the entity is removed.

@sfan5 sfan5 added the Action / change needed Code still needs changes (PR) / more information requested (Issues) label Jun 10, 2022
@appgurueu appgurueu requested a review from sfan5 June 11, 2022 13:08
@sfan5 sfan5 removed the Action / change needed Code still needs changes (PR) / more information requested (Issues) label Jun 11, 2022
Copy link
Member

@sfan5 sfan5 left a comment

Choose a reason for hiding this comment

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

Looks all correct.

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.

LGTM

@SmallJoker SmallJoker merged commit e7d4ec6 into minetest:master Jun 11, 2022
@appgurueu appgurueu deleted the on-removed branch March 31, 2024 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature ✨ PRs that add or enhance a feature Roadmap The change matches an item on the current roadmap. @ Script API >= Two approvals ✅ ✅
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants