Thread, enqueue, multithreading, Callable mesh

[java]

public void onAction(String name, boolean keyPressed, float tpf) {

if (name.equals("Shoot") && !keyPressed){

final CollisionResults results = new CollisionResults();

Ray ray = new Ray(cam.getLocation(), cam.getDirection());

rootNode.collideWith(ray, results);



_app.enqueue(new Callable() {

public Object call() throws Exception {

UpdateChunk uc = new UpdateChunk(results, mapGenerator, chunkMap, assetManager, rootNode);

return null;

}

});

}

[/java]



BUT when I use UpdateChunk - camera, movement and other are freezing… Seems I need real enqueue sample. Can someone upload full code snippet ? :slight_smile:





Can someone provide real sample enqueue ?

Thats normal. Enqueueing means you still do the stuff on the update loop, just next frame. The idea is to do work on another thread and then only do the things that are necessary on the update loop, like attaching etc. Read the rest of the multithreading document in the wiki, it explains how you can offload work.

yeh, just enqueue the stuff which requires enqueuing (anything which modifies the scene graph), you want other logic outside to be handled by the new thread, else everything is still called on the Render Thread and you will have freezes.



A nice example is here:

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:loading_screen#using_multithreading

something like that ?





[java]

// Frame synchronization

_app.enqueue(

new Callable() {

public Object call() throws Exception {



// Multithreading

executor.submit(new Runnable() {

public void run() {

UpdateChunk uc = new UpdateChunk(results, mapGenerator, chunkMap, assetManager, rootNode);

}

});

return null;

}

});

[/java]

nono other way round

[java]

// Multithreading

executor.submit(new Runnable() {

public void run() {

UpdateChunk uc = new UpdateChunk(results, mapGenerator, chunkMap, assetManager, rootNode);



// Frame synchronization

_app.enqueue(

new Callable() {

public Object call() throws Exception {



node.move (new Vector3f(1, 0, 0)); // Scene graph stuff here



return null;

}

});







}

});[/java]