Does dyn4j use multithreading?

Posts that don't fit into other categories.
soylomass
Posts: 22
Joined: Fri Nov 18, 2016 3:40 pm

Does dyn4j use multithreading?

Postby soylomass » Tue Nov 21, 2017 12:41 pm

I'm planning to use dyn4j for a multiplayer game, that needs to be scalable, so I wanted to know whether or not dyn4j makes use of multiple threads to do the physics calculation.

I've searched and the only related thing I've found is a test on the sandbox called Parallel which says does use multithreading, but I'm not sure exactly for what.

Thanks in advance.

TMNCorp
Posts: 6
Joined: Thu Aug 04, 2016 1:31 pm

Re: Does dyn4j use multithreading?

Postby TMNCorp » Tue Nov 21, 2017 8:28 pm

No it doesn't.
You are going to have a hard time finding a multithreaded physics engine at all because of a variety of problems that are coming with it.
Although, Keen Software House is currently working on multithreading Intel's "Havok" engine, you can look up their codebase on GitHub if you are interested.

Apart from that, "scaling" in regard of physics calculations is comparable with rendering. You do the detailed stuff only in the vicinity of players. Like with an LOD system.

soylomass
Posts: 22
Joined: Fri Nov 18, 2016 3:40 pm

Re: Does dyn4j use multithreading?

Postby soylomass » Wed Nov 22, 2017 2:53 pm

TMNCorp wrote:No it doesn't.
You are going to have a hard time finding a multithreaded physics engine at all because of a variety of problems that are coming with it.
Although, Keen Software House is currently working on multithreading Intel's "Havok" engine, you can look up their codebase on GitHub if you are interested.

Apart from that, "scaling" in regard of physics calculations is comparable with rendering. You do the detailed stuff only in the vicinity of players. Like with an LOD system.


Thanks. It's not my first multiplayer game actually, I'm evaluating dyn4j in this one after using Libgdx-box2d in the first one.

The problem with physics engine being single threaded, is that you have a technical limit that can't be increased by adding cpu cores (which is the only option you have in a VPS), so you can only optimize as much as possible and that's it.

Libgdx-box2d is fast, but the uncatchable c++ exceptions are a huge headache.

Is there any benchmark or do you know how dyn4j compares with box2d, performance wise? JBox2d was pretty slower than it's C++ counterpart, in my experience.

TMNCorp
Posts: 6
Joined: Thu Aug 04, 2016 1:31 pm

Re: Does dyn4j use multithreading?

Postby TMNCorp » Wed Nov 22, 2017 7:14 pm

I have evaluated multiple 2d engines about two years ago, including but not limited to chipmunk2d (C) or some exotic ones like Nape written in Haxe.
They all come with pros and cons regarding their functionalities and performance but for most it already starts with their source code, API and interoperability with other languages like Java.

+ Without going much into detail, LiquidFun is the most advanced and best performing 2d engine out there. Based on Box2D it was further developed by Google and supports liquids and bouncy/bendable materials.
It also comes with a set of SWIG instructions to "easily" create Java JNI bindings.
- Speaking of "easily" - it is not. Maintaining and extending the JNI bindings, SWIG bindings and the C++ codebase is a discipline on its own. In fact I could write multiple pages about this topic. I don't even need to start to talk about debugging at this point (which you mentioned).

+ Dyn4j is a good tad faster then JBox2D while having a clean and easily maintainable source code with a nearly identical set of functionalities. This is because it was designed and written in java for the JVM from the beginning on.
It is also actively maintained by its creator.
- However, dyn4j does not have a liquid simulation (which is an exclusive to LiquidFun) and lacks some niche Box2D shapes.
Performance wise it is behind LiquidFun which was specifically optimised for some CPU architectures.

There are a lot more 2d physics engines but their performance, number of functionalities or maintenance does not justify the lack of the others in regard to LiquidFun and Dyn4j (besides them being maybe written in the project language you are using and used to!).

All in all, Dyn4j is a good alternative to LiquidFun, trading in some performance for much cleaner code.
To my surprise, because dyn4j was pretty hard to find when searching for 2d engines back then.

William
Site Admin
Posts: 377
Joined: Sat Feb 06, 2010 10:23 pm

Re: Does dyn4j use multithreading?

Postby William » Wed Nov 22, 2017 10:21 pm

I'm not aware of any benchmarks, but generally agree with TMNCorp's assessment. dyn4j, while no slouch, made some design choices which reduces performance slightly, but yielded a more structured, clearly defined, codebase and API.

TMNCorp wrote:I've searched and the only related thing I've found is a test on the sandbox called Parallel which says does use multithreading, but I'm not sure exactly for what.

The Parallel test was actually an attempt to multi-thread some parts of the engine. The experiment failed - it always yielded worse performance. The number of bodies needed to be so high for a performance difference to be seen vs. single threaded that you'd be out of the realm of realtime simulation anyway. This is not a general statement about multi-threaded physics, rather, it's the experience I had with dyn4j and the constraints on API and maintenance that I set for myself.

The best attempt at "multi-threaded" physics I've seen so far is with Bullet and it's full GPU implementation. But there are limitations there as well.
However, I do think they have the right approach - the whole physics pipeline needs to be re-tooled with parallel algorithms to get any benefit. This is non-trivial. So from that, you have to ask the question, is it really necessary? Can we achieve the same thing another way? Hence TMNCorp's LOD reference and the ecosystem that is currently available.

A simple, but not always obvious, approach might be to have a physics "World" per thread, that simulates a specific region of a larger world. Naturally, this adds complexity (swapping bodies from one world to another across boundries, what happens when a body is in more than one, etc) but would scale as you say. However, it may prove easy depending on your application, thereby removing the need for the extra complexity of a multi-threaded physics engine.

The only thing I would disagree with is
TMNCorp wrote:and lacks some niche Box2D shapes

dyn4j offers all the primitives that Box2d offers, plus more. dyn4j is missing the GearJoint from Box2d though.

William

soylomass
Posts: 22
Joined: Fri Nov 18, 2016 3:40 pm

Re: Does dyn4j use multithreading?

Postby soylomass » Wed Nov 22, 2017 10:48 pm

Thanks to both of you for your answers.

I'll start developing the game using dyn4j, and will report back when I have a working product to make you know how it went.

Dividing the game world if many physic worlds is a good idea, I'll just have to trick players into thinking they are "traveling" while the swapping happens.

I actually have no complaints about libgdx-box2d itselft, it has a great performance (well, it's the c++ box2d which does the work), but not being native java becomes tiring after a while.

Also I appreciate the quick responses. The other Java 2d physics engines I've seen don't seem to be as actively maintained.

TonyCe
Posts: 1
Joined: Sat Dec 09, 2017 5:06 am

Re: Does dyn4j use multithreading?

Postby TonyCe » Tue Dec 19, 2017 11:16 am

Hi Soylo, what kind of game are you developing? How do you plan to trick the players to think they're traveling, with a loading screen?


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests