Author Topic: Physics example  (Read 13386 times)

Offline AeroShark333

  • float
  • ****
  • Posts: 259
    • View Profile
Re: Physics example
« Reply #15 on: April 25, 2021, 08:56:16 pm »
Sources in first post was updated. Zip contains optimized jBullet lib (thanks EgonOlsen for tips! ;)), adjusted vecmath lib and sources of PhysicsTest app. On my SGS3 physics calculations of 9 boxes take about 37ms with original libs and 29ms with optimized ones. It is almost 30% speed up, it is not much for my app, but maybe it can help to someone.
Hello Thomas,give please link of source code jpct-ae+jbullet,link in top not work.

I believe the Dropbox links have died since the post is from years ago.
I once experimented with jBullet too... but the performance was too poor for my likings I believe.
Though, I might still have the jBullet version that was originally posted here somewhere on my computer.
I can try to look for it if you're really interested...

Otherwise, maybe this will help:
https://www.jpct.net/forum2/index.php?topic=1509.0


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12187
    • View Profile
    • http://www.jpct.net
Re: Physics example
« Reply #16 on: April 26, 2021, 01:57:47 pm »
This should be the code Thomas. released back then: https://jpct.de/download/example/PhysicsTest.zip

Please note: I've just zipped my project directory. It might contain a lot of unneeded stuff and was created for an Android-SDK from ages ago. That said, it still compiled, uploaded and worked fine for me.

Offline aleks1283

  • byte
  • *
  • Posts: 17
    • View Profile
Re: Physics example
« Reply #17 on: April 28, 2021, 12:26:45 am »
Thanks. Is there an alternative to jbullet but not slow?

Offline AeroShark333

  • float
  • ****
  • Posts: 259
    • View Profile
Re: Physics example
« Reply #18 on: April 28, 2021, 12:36:57 am »
Thanks. Is there an alternative to jbullet but not slow?
I believe there's jMonkeyEngine... (which can work without jPCT as well..)
But I'm not sure how well it works together with jPCT.

An alternative is probably to decompile jBullet and optimize it somehow... (making it multithreaded or something..?)

Offline aleks1283

  • byte
  • *
  • Posts: 17
    • View Profile
Re: Physics example
« Reply #19 on: April 28, 2021, 08:25:23 am »
Well, if I understand correctly, threads do not add speed on devices, but only transfer work to the background.

Offline AeroShark333

  • float
  • ****
  • Posts: 259
    • View Profile
Re: Physics example
« Reply #20 on: April 30, 2021, 06:27:54 am »
Well, if I understand correctly, threads do not add speed on devices, but only transfer work to the background.
I'm not entirely sure about this...
I believe you could off-load some heavy physics calculations on a seperate thread than the GL-thread.
When heavy calculations are done in the GL-thread, you might suffer from lower FPS due to reduced draw(...) call rates.
I think this might especially give speed boosts on multi-core processor devices (nearly all devices nowadays) which would handle multithreading better.
Though, making sure the threads are synced and working well together might be more complex...
jPCT(-AE)/OpenGL(ES) isn't entirely multi-thread friendly as far as I know.

Maybe @EgonOlsen knows more about this...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12187
    • View Profile
    • http://www.jpct.net
Re: Physics example
« Reply #21 on: May 01, 2021, 01:08:13 pm »
The "old" purpose of multiple threads is indeed to do slow IO operations in the background. But nowadays, given that all processors have multiple cores/threads (the machine I'm writing this on can handle 24 threads in parallel, for example), it also very common to use multiple threads for calculations.
That said, it's not easy to use multiple threads for physics, because the result of one thread's calculation can have an impact on the other. Imagine 8 boxes colliding with each other. If you calculate each box in it's own thread, the outcome of one would depend on the collisions of all the others, which is almost impossible to synchronize properly.
jPCT(-AE) itself isn't thread safe (but you could do calculations on independant objects or tasks in multiple threads) and neither is OpenGL(ES). If you want to use multi-threading in one way or the other, you have to make sure that the tasks that are processed by the different threads are independant (for example: One thread for physics, one for sound, one for path finding...).

Offline aleks1283

  • byte
  • *
  • Posts: 17
    • View Profile
Re: Physics example
« Reply #22 on: Today at 06:39:08 am »
Thanks Egon :)