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

Optimize item checking code for throwing into trash can #19

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Emojigit
Copy link
Member

@Emojigit Emojigit commented Mar 3, 2024

This PR optimizes the codes handling throwing items into wooden trash cans.

  • Before: ALL __builtin:item entities will be checked on EACH global step, regardless of whether they are inside a trash can
  • After: All loaded wooden trash cans will be checked for entities inside them on every 0.5 seconds (i.e. 5 global steps), and process __builtin:item if any.

Under normal circumstances, the number of entities inside trash cans (even after counting non-items) would be less than the number of dropped items coexisting in the world (unless a group of fools decided to stand inside trash cans forever). Therefore, this mod optimizes the runtime load.

This PR is optimized in commit 3322a30 using node timers (set up when placing a trash can or loading an old one for the first time) instead of ABM (scanning all nodes every run).

This PR is tested and ready for review. Here is the footage of the testing:

Video_2024-03-04_07-22-05.mp4

@Emojigit Emojigit mentioned this pull request Mar 3, 2024
@SmallJoker
Copy link
Member

Node timers might be even more efficient because Minetest doesn't need to scan the mapblock for trash_can nodes.

@Emojigit
Copy link
Member Author

Emojigit commented Mar 5, 2024

Node timers might be even more efficient

Done in commit 3322a30

@SmallJoker
Copy link
Member

The change works.. but only partially.
It turns out the on_step override also allowed the item to fall into the trash can for proper position detection. With this PR the items usually get teleported back to the last collision point when falling into the node - which is generally the top corner of the trash can.

@SmallJoker
Copy link
Member

@Emojigit Did you yet have a chance to have a look at the issue mentioned above? Thank you.

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