Search in sources :

Example 1 with InternalTickCallback

use of com.bulletphysics.dynamics.InternalTickCallback in project jmonkeyengine by jMonkeyEngine.

the class PhysicsSpace method setTickCallback.

private void setTickCallback() {
    final PhysicsSpace space = this;
    InternalTickCallback callback2 = new InternalTickCallback() {

        @Override
        public void internalTick(DynamicsWorld dw, float f) {
            //execute task list
            AppTask task = pQueue.poll();
            task = pQueue.poll();
            while (task != null) {
                while (task.isCancelled()) {
                    task = pQueue.poll();
                }
                try {
                    task.invoke();
                } catch (Exception ex) {
                    logger.log(Level.SEVERE, null, ex);
                }
                task = pQueue.poll();
            }
            for (Iterator<PhysicsTickListener> it = tickListeners.iterator(); it.hasNext(); ) {
                PhysicsTickListener physicsTickCallback = it.next();
                physicsTickCallback.prePhysicsTick(space, f);
            }
        }
    };
    dynamicsWorld.setPreTickCallback(callback2);
    InternalTickCallback callback = new InternalTickCallback() {

        @Override
        public void internalTick(DynamicsWorld dw, float f) {
            for (Iterator<PhysicsTickListener> it = tickListeners.iterator(); it.hasNext(); ) {
                PhysicsTickListener physicsTickCallback = it.next();
                physicsTickCallback.physicsTick(space, f);
            }
        }
    };
    dynamicsWorld.setInternalTickCallback(callback, this);
}
Also used : AppTask(com.jme3.app.AppTask) InternalTickCallback(com.bulletphysics.dynamics.InternalTickCallback) DiscreteDynamicsWorld(com.bulletphysics.dynamics.DiscreteDynamicsWorld) DynamicsWorld(com.bulletphysics.dynamics.DynamicsWorld)

Aggregations

DiscreteDynamicsWorld (com.bulletphysics.dynamics.DiscreteDynamicsWorld)1 DynamicsWorld (com.bulletphysics.dynamics.DynamicsWorld)1 InternalTickCallback (com.bulletphysics.dynamics.InternalTickCallback)1 AppTask (com.jme3.app.AppTask)1