minetest-mods / trash_can

A mod that adds trash cans to minetest.
MIT License
7 stars 10 forks source link

Optimize item checking code for throwing into trash can #19

Open Emojigit opened 7 months ago

Emojigit commented 7 months ago

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

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:

https://github.com/minetest-mods/trash_can/assets/55009343/1897f274-daa5-43fb-b755-81cb840b1051

SmallJoker commented 7 months ago

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

Emojigit commented 7 months ago

Node timers might be even more efficient

Done in commit 3322a30

SmallJoker commented 7 months ago

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 commented 5 months ago

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