Proper threading when loading/attaching geometries

Hey guys a couple days ago I posted about dynamic terrain and I am proud to say I have made a lot of progress with a simplified dynamic marching cubes setup. I am now working on threading the process so it can be updated in parallel with a game loop.

I understand the idea of threading and I have used it before in much… Simpler applications (multiple displays, graphs, etc) but never with Jmonkey. I was curious what the proper way to attach geometries that are generated in a different thread would be.

I haven’t even tried to just attach children from this different thried because I know the out come will simply be errors about updating my scene from outside the opengl loop.

The thread simply runs the MC algorithm and at its end point will generate a quad. I am unsure of the proper way to now attatch this to my root while avoiding errors. I have searched the forums and read the JME tutorial on multi threading but it was more about logic, I am looking for how to modify my scene. Just a point in the right direction should do, perhaps some sudo code, or a real code example if you have it on hand, that would be amazing. Thanks for your guys’ continued awesomness and support. I am really proud of this and I am looking forward to releasing it for you all to use. Cheers!

Just attach the spatial while you are on the render thread. ie. in the game update loop or a Control’s update method. The multithreading tutorial does give a real example: the mainapp.enqueue() call is done on the render thread.

There is a handy UpdateControl in jme that you can use; attach it to some spatial and pass a reference to it around. Then just enqueue Callables to it.

1 Like

Ahh I see, perhaps I need to do some more research on the callables queue system. Thanks for the nudge ill look at the tutorial once more.

Oh that makes so much more sense, now that I went back and did some cross referencing and payed close attention. Thanks for pushing me back to the tutorial so I didn’t waste anyones time. Cheers!

1 Like

No problem, glad it helped. :slight_smile:

1 Like