Multithreading for character controller

user64
Posts: 14
Joined: Fri Jan 28, 2011 9:03 pm

Multithreading for character controller

Post by user64 »

Hello.
I use Bullet only for character physics (btKinematicCharacterController without changes). I need multithreading support for a large number of characters. What can I do for this?

For example:

Code: Select all

void	btDiscreteDynamicsWorld::updateActions(btScalar timeStep)
{
	BT_PROFILE("updateActions");
	
	for ( int i=0;i<m_actions.size();i++)
	{
		m_actions[i]->updateAction( this, timeStep);
	}
}
It seems that I can replace "for" with "parallel_for". Thus, methods btKinematicCharacterController::updateAction() of different characters will be processed in different threads. Is it safe?

UPDATE:
Important condition: characters do not collide with each other (filtering by masks), only with static terrain.
user64
Posts: 14
Joined: Fri Jan 28, 2011 9:03 pm

Re: Multithreading for character controller

Post by user64 »

I've done some research. As a result I need processing btCollisionWorld::convexSweepTest() in parallel. But it is not thread-safe.
I have found this line in btDbvt::rayTestInternal():

Code: Select all

btAlignedObjectArray<const btDbvtNode*>&	stack = m_rayTestStack;
And further this variable is modified. m_rayTestStack is class field. I think it is optimization for dynamic memory usage.
To keep optimization and to make the code thread-safe, I will make m_rayTestStack thread-specific.

Whether there are still bottlenecks which I haven't found out?
And advices about multithreading support for my case are welcome!
Thanks in advance.
Last edited by user64 on Wed Jan 25, 2012 7:46 pm, edited 1 time in total.
dumbo2007
Posts: 66
Joined: Sun Jan 30, 2011 8:46 pm

Re: Multithreading for character controller

Post by dumbo2007 »

Doesnt the multithreaded parallel solver help in this case ?
user64
Posts: 14
Joined: Fri Jan 28, 2011 9:03 pm

Re: Multithreading for character controller

Post by user64 »

I don't think so.
3rd post:
http://bulletphysics.org/Bullet/phpBB3/ ... f=9&t=7300

I thought about SpuGatheringCollisionDispatcher... Is there any other capabilities?

This variant seems to me the most successful: use btKinematicCharacterController only for player, use btCollisionWorld::convexSweepTest() for NPC to determine its Z coordinate (logic determines the trajectory of NPC on XY). NPC or some its part are NOT in the physics world!
So I need to know about the parallelization of btCollisionWorld::convexSweepTest(), execution of this method for different NPCs (ie some shapes like capsule or sphere) parallely.