HackerN64 / HackerSM64

A Super Mario 64 decompilation repo based on CrashOveride95/ultrasm64 that aims to provide a flexible, easy-to-use base for creating romhacks.
333 stars 150 forks source link

Optimize surface collision checks and `break` when upperY/lowerY is out of bounds #174

Open thecozies opened 2 years ago

thecozies commented 2 years ago

Right now collision checks will continue after finding a floor or ceil to be very certain that a another tri shouldn't have been hit instead.

In find_floor_from_list, it seems that having if (floor && surf->upperY < floor->lowerY) break; at the top of the loop could improve performance. This is a good check because it insures that you have found a floor, and that the current floors highest point is lower than the previously collided floor's lowest point. And because of sort order, there's no reason to continue checking after this point.

The same but reversed could be done for ceilings.

gheskett commented 2 weeks ago

Wouldn't adding this literally reintroduce surface cucking? Closing this for now unless somebody corrects me.

arthurtilly commented 2 weeks ago

if the currently checked floor's highest point is below the current collided tri's lowest point, then no this would not cause surface cucking

arthurtilly commented 2 weeks ago

in fact, i believe the check can actually be more aggressive - checking if the floor's upperY is less than the currently collided height should be enough

gheskett commented 2 weeks ago

Alright, I'll reopen this then. This does need to be tested very diligently though if it is to be merged.