Multithreading Bullet Physics in jme3

Introduction

Since bullet is not (yet) multithreaded or GPU accelerated the jME3 implementation allows to run each physics space on a separate thread that is executed in parallel to rendering.

How is it handled in jme3 and bullet?

A SimpleApplication with a BulletAppState allows setting the threading type via

setThreadingType(ThreadingType type);

where ThreadingType can be either SEQUENTIAL or PARALLEL.

In the simpleInitApp() method:

bulletAppState = new BulletAppState();
bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
stateManager.attach(bulletAppState);

The physics update happens in parallel to rendering, after the users changes have been made in the update() call. This way the loop logic is still maintained: the user can set and change values in physics and scenegraph objects before render() and physicsUpdate() are called in parallel. More physics spaces can simply be added by using multiple bulletAppStates.

documentation, physics, threading

view online version