jaipack17 / Nature2D

A 2D physics engine for Roblox. Create versatile physics simulations and mechanics with GUIs!
https://jaipack17.github.io/Nature2D/
MIT License
147 stars 8 forks source link

Avoid pointless work on non-collidable bodies #23

Closed boatbomber closed 2 years ago

boatbomber commented 2 years ago

I realized that we were wasting work on non-collidable bodies every step. We were adding them to the quadtree, then ignoring them when we looped over the tree search results. We also filtered and searched on non-collidable bodies, then ignored everything because the if statement was always false.

To fix this, I check body.collidable before inserting it into the quadtree. I also check body.collidable before we search for collisions on it. We still have to check other.collidable in case self.quadtrees is set falsy, but we can drop the body.collidable part since that's checked before the loop runs.

(There's a lot of whitespace changes because your file had a ton of hidden whitespace that my editor removes. You should probably enable that setting as well, it's best practice to avoid trailing whitespace.)

jaipack17 commented 2 years ago

These are some great changes! I failed to realize how many resources were being wasted even though the work wasn't required to be ran for non-collidable bodies. I'll review this and merge it soon! Thank you for fixing the trailing whitespaces and conflicts as well!

boatbomber commented 2 years ago

FYI, StyLua will fix your whitespace issues! Your current GitHub Action is actually not helping you- you're making StyLua run instead of check. What this means is that it's actually altering and formatting the files that are in the cloud machine, without telling you about your issues.

You're doing stylua src when you need to be doing stylua src --check