Parallelizing Collision Detection?


I'd like to speed up my game by parallizing things. First, I do not use any physics library since the game is a space shooter, so the only physics I use are bouncing back and so on. Basicly I implemented some basic Impulses that throws objects somehow back, nothing fancy and it can certainly be enhanced a lot.

Of course I already tried to use threads to detect collisions, and at least it worked that way that I did not get strange jme exceptions because of scene changes made in other threads than the OpenGL Thread (I'm using StandardGame, btw g). But it was just completely out of sync with the actual gameplay, so most of the time objects flight throw other small enough ones. I guess thats because of the "injections" of Callables into the OpenGL Thread via the GameTaskQueueManager and consequently waiting for them to complete (so every object in the collision checking required at least one frame to complete, which is obviously unacceptable).

To my question: How can you parallelize collision detection sensefully?

I guess you need some more information about my collision detection that is performed at the moment:

The whole scene is a binary tree spliting the whole scene (basicely a cube-shaped space) into smaller blocks. This way collision detection can quickly find the current parent-Block-Node of the object and it only must check the other children of this parent. Of course the re-searching of the current parent-node of an object is only done when the object isn't in the last parent anymore (this is done by the size and positions of the blocks using a BoundingBox). So most of the time it only checks a few near children and only if it leaves its current parent block the new Block is computed (in linear time because of the binary tree structure).

I'm not sure if all this stuff was necessary because jme2 is using some tree stuff for intersection computation, but think my  concept is quite suited for my game.

Maybe someone can help me parallelize this somehow, because I think this slows down my game, especially with 10 bots shooting 30 or more projectiles at each other (and these "projectiles" move too slow in my game, so they stay alive several seconds).

I really wonder how this slows you down?

jbullet is for example capable of around 3k moving and colliding boxes with my cpu (amd 4200+) with only using a singlecore. When I then replace the physic bullets with a ray based pseudo bullet I can go up to several thousands, (where object count decreases framerate more than the actual calculation.

So I really wonder, If you know why you use more than one thread, as it brings several problems. Normally if you have physic calc problems your concept has a flaw.

If I recall correctly, parallelizing collision in jME2 won't work because it uses static temp variables. That means that if two threads do collision calculations at once, they will corrupt each over's state.

The only way of making this work is to edit those classes to create new objects or use a set of temp vars per thread like jme3 does it.