ParticleMesh optimization?

### Eclipse Workspace Patch 1.0
#P jME2
Index: src/com/jmex/effects/particles/ParticleMesh.java
===================================================================
--- src/com/jmex/effects/particles/ParticleMesh.java   (revision 4105)
+++ src/com/jmex/effects/particles/ParticleMesh.java   (working copy)
@@ -205,6 +205,9 @@
     }
 
     public void draw(Renderer r) {
+       if(!controller.isActive())
+          return;
+       
         Camera camera = r.getCamera();
         for (int i = 0; i < particles.length; i++) {
             Particle particle = particles[i];



This gave me a nice speedup because dead particles now don't get rendered. Is there a reason why not to do this? I also added similiar things for the update methods..

Probably because we'd usually use the ParticleControllerListener callback to remove your dead particles from the scene entirely (then it doesn't need special code to circumvent the scenegraph routines).  The change is not bad though, particularly if you have a reason to keep a dead particle in the scene graph (which is also reasonable.)



edit: though I suppose you could have a reason to freeze your particles (using setActive on the controller) and still want to see them…

OK, I understand. Since I reuse the particles like in the particlefactory example, I don't want to remove them and instead just restart them. But I understand that it might be useful sometimes to render inactive (or paused?) particles too (maybe a freeze time spell effect?). So maybe I should have posted this under user code instead. For those interested.

Or maybe make it so that it can be enabled / disabled.

I would think that rendering inactive particles is more often unneeded.



     public void draw(Renderer r) {
        if(controller.isActive() == false && renderInactiveParticles == false) {
            // do not render inactive particles
            return;
        }
    }

Good idea. I'm not a developer so maybe someone else can fix it?

but you can provide a patch  :wink:

Sure, I will try to make one.

I think this optimization can be enabled by default.



If someone wants to freeze particles by calling ParticleMesh.setActive(false) and still render them, he can set the new variables to true.



jmetest.TutorialGuide.TestPongCool is a good example to test it, as it uses a ParticleFactory where multiple ParticleMeshes are created in a pool.


Core-Dump said:

jmetest.TutorialGuide.TestPongCool is a good example to test it, as it uses a ParticleFactory where multiple ParticleMeshes are created in a pool.


It works fine.