(Hope I posted in the right section).
I am developing a project in which several geometries are placed at the scene in simpleInit. Those geometries are movable by pressing the KEY_LEFT or KEY_RIGHT and when such a key is pressed, a different object moves them around (call this object “Mover”).
The movement is done “bits by bits” using the updateLoop (I imagine this is standard). With each iteration, he updateLoop checks for a field in Mover which says whether to move the geometries or not, and if that field says “move them”, a method in Mover is called, moving all geometries. When the movement is finalized, the field is set to “don’t move them”, and the updateLoop therefore doesn’t call the moving method.
(I hope I was clear )
I have a somewhat bizzare need to create multiple other geometries in the background and attach those to the rootNode when they are done. I create many of those almost all the time. These geometries are seperate from the ones we move.
After the scene has been initialized, all updates must be done from the update loop. But making the update loop go over creation of multiple geometries at every iteration seems inefficient, so I have created a “Geometry Factory” which creates geometries via threadding, i.e., it keeps creating geometries, each with a different thread in order to not “interfere” with the updateLoop’s operation.
This “Factory” is set and run from the simpleInit method and therefore runs in parallel with the update loop.
I used Future object (from java’s Cuncurrent) to tell when a geometry is done, inside this Factory. At each iteration, the update loop checks a fixed size array in that Factory for “ready” objects. If the geomery is ready, it is then attached to the rootNode.
However, this seems to kill the update loop anyways. The Fps drops tremendously from about 350 to 20 or even less. I am running about 10 threads in parallel.
The Fps seems to increase again if I use Thread.sleep(1000) for each geometry creation thread.
The entire thread creating process was done similarly to the advanced tutorials, using an Executor.
It seems plausible that creating many threads somehow impacts the performance, but is it that extreme? for constant creation of geometries “in the background”, the Fps drops sometimes to 0.
Is it possible to create things in the background (perhaps many things), but somehow telling jmonkey that the Fps must be kept high? even at the cost of the other threads getting “hurt”?
I would attach the code but it is quite long and I think the question is more “idea-based” than “code-based”.
If I’m wrong I would be happy to post the code.
Thanks so much in advance,