xpenatan / gdx-teavm

Run Libgdx in a webbrowser with teavm
Apache License 2.0
108 stars 16 forks source link

Improve Box2D performances with TeaVM #53

Closed fgnm closed 1 year ago

fgnm commented 2 years ago

Hi! JBox2D used by libGDX-GWT is commonly known to be a big bottleneck for any 2d physics game made in libGDX for Web, java implementation is just slow compared to the native one, but nowadays there's emscripten and the work you made with Bullet extension for TeaVM shows very great performances! So I was wondering if the same could be made with Box2D to improve performances too.

Thanks :)

xpenatan commented 2 years ago

Hey, sure. Can you create an example where its slow with gwt backend? It will be easier to see if emscripten will give performance boost.

fgnm commented 2 years ago

Currently on my not-so-powerful laptop you're examples already shows interesting scenarios. The Bullet example with 500 3D boxes run at same fps of the Box2DTestCollection here: https://xpenatan.github.io/gdx-html5-tools/teavm/gdx-tests/ (the test with the pyramid of boxes). When boxes are moving fps drops between 20/30fps, while the bullet test runs always between 40/50fps.. On a not-so-powerful phone (OnePlus 6T) the Box2D Pyramid boxes test cannot even run, like 2/3fps before freezing the entire browser, while the Bullet test is at least able to run at 20/30fps and no browser freezing. The only explanation I can give of such behavior is emscripten.. Tell me what do you think!

xpenatan commented 2 years ago

The test collection use ShapeRenderer and not sprites and that also drop FPS.

I got emscripten to compile box2d c++ classes. The next step is to figure out how to bind it to libgdx custom box2d classes and that may take some time.

xpenatan commented 2 years ago

@fgnm Got some c++ box2d to work =D. Need to bind more methods to get pyramid fully working

image

fgnm commented 2 years ago

Cool! Can't wait to try once finished to check performances :)

xpenatan commented 1 year ago

Hi @fgnm https://xpenatan.github.io/gdx-html5-tools/teavm/test-box2d/

Test it and see if there is any fps increase. There is one issue that the mouse joint is not deleting and I'll fix it later.