Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Use bitwise operators in NaiveBroadphase #15

Closed
timrwood opened this Issue · 3 comments

2 participants

Tim Wood Stefan Hedman
Tim Wood

The big if loop here could be switched to use bitwise operators to save filesize and run faster. See the changed code below.

var IS_SPHERE_BOX_COMPOUND = BOX | SPHERE | COMPOUND;
...
if ((ti & IS_SPHERE_BOX_COMPOUND) &&
    (tj & IS_SPHERE_BOX_COMPOUND) {
    ...
}

Here is a jsfiddle where you can check out the bitwise operators.

Here is a jsperf where you can check out the performance. Note how the performance is the same no matter if the statement is true or false.

Right now, if one of the types is PLANE, the statement won't fail until it checks all 18 comparisons.

Stefan Hedman
Owner

Not a bad idea :)
Are you eager to do this or may I?

Tim Wood

Go for it. I have a couple other optimizations that I have in mind as well and I'll open issues for them when I get time to write them up.

I would have just submitted a pull request, but I guess github only lets me have one pull request open at a time?

Stefan Hedman
Owner

Cool. I dunno how github works with multiple pull requests though. I'll try to sort your first one out now.

Stefan Hedman schteppe closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.