schteppe / p2.js

JavaScript 2D physics library
Other
2.64k stars 330 forks source link

There is an repo for testing some js physics engines. #286

Open finscn opened 7 years ago

finscn commented 7 years ago

https://github.com/cmann1/Javascript-Physics-Library-Tests

In the test Stress , the p2.js has some bugs.

And the result of p2.js is not as good as box2d. Are there some bugs ? or the test case 's fault ?

Scharnvirk commented 7 years ago

Wow, and this is not a little difference... this is like 20fps for box2dweb on stress test vs 1-2 fps on p2.js. It is even worse on firefox and Edge shows steady 0.0 fps.

I tried profiling the p2-based stress test but my machine just can't handle both the test and the profiler at once :|

finscn commented 7 years ago

in theory , p2.js & @liabru 's matter-js should faster than box2d.js.

Because box2d.js is converted from other version Box2D by machine . I think there is no enough optimization. I don’t trust optimizations of the code that generated by machine.

Maybe there are some parameters/properties/config/options not be set with correct value, I think.

Scharnvirk commented 7 years ago

It all depends on implementation. If Box2D is just written using faster algorithms, machine optimization won't hurt it too much.

I am pretty sure, however, that about a year ago, when I was picking a physics engine for my game (in search for fastest one involving multiple collisions of simple bodies), I found a comparision where p2.js was by far the fastest one. I am quiiite sure something in this demo is plain wrong, especially considering how easy it is to mess up with implementation of ANY physics engine.

For example I got about 50% more performance on the physics layer of my game just by switching map chunks from being one body with multiple shapes to multiple bodies with one shape - which is pretty logical, as now it is properly using broad collision phase first then narrow phase, and before it was, for these few bodies, doing constantly narrow phase calculation. It might have had more sense earlier on when I had MUCH more bodies (about a thousand) and adding ~100 more from the map was bad, but now the game uses about 100-200 so having 100 more from map itself is actually better.

But then I don't see anything particularly bad on that demo code, hm.

finscn commented 7 years ago

@Scharnvirk , in your test the performance of p2.js is better than matter.js ?

And @cmann1 , what do you think about the @Scharnvirk 's words ?

cmann1 commented 7 years ago

It might be possible that there's something wrong with the demo causing performance issues, but they're all fairly straightforward so I doubt it.

I think someone more familiar with p2js would have to have a look to say for sure though.

Scharnvirk commented 7 years ago

I did not test my app with other physics engines. I am not sure if it is worth it, this is quite a job to rewire it even if methods stay roughly the same (because constants won't).