Managing Node Loading Efficiently

How many poly's are your bullets?

I have no idea - the bullets are just spheres about 0.5 in radius!

Plus the particle effect - which is just a switchNode for a trail effect.

Ah, I didn't see that part of the code.


Sphere sphere = new Sphere("bullet",new Vector3f(0,0,0), 50,50,2f);



is alot of polys!!

try

Sphere sphere = new Sphere("bullet",new Vector3f(0,0,0), 6,6,2f);



or less

You could also use shared meshes.

Since they are so small they dont even need spherical shape, you can even try

Sphere sphere = new Sphere("bullet",new Vector3f(0,0,0), 3,3,2f);


Nobody will notice difference with small shapes anyway!

Cheers!

Haladria said:

Ah, I didn't see that part of the code.

Sphere sphere = new Sphere("bullet",new Vector3f(0,0,0), 50,50,2f);



is alot of polys!!

try

Sphere sphere = new Sphere("bullet",new Vector3f(0,0,0), 6,6,2f);



or less

That cannot be the problem because there is still an awful jolt whenever the getCompletedBullet method is called.



Maybe its when it is attached to the rootnode - could this possibly be done before hand and just have the positions of the objects off screen in some distant location - then simply move them into view - that would maybe stop the horrible lag when each bullet is fired.



The sphere doesnt even need to be visible - its only there so that i can do some collisions detecting on the bullets - so if you can tell me how to make them invisble ill do it.

$20 its your particle effect. Try removing that and see how it works.

removed - still juddering…how the heck do i solve this :open_mouth:

I actually tried changing my code in the getCompletedBullet method to use a new thread each time - to stop the blocking call and that removes the halt altogether - but I am unsure if this is good practice…



public void getCompletedBullet(Enemy target, Vector3f position){
      
      this.target = target;
      this.position = position;
      
      new Thread(){
         
         public void run(){
            
            Bullet b = completedBullets.poll();
            if(b == null){
               System.out.println("outa bullets - wait");
            }
            b.setLocalTranslation(EntityManager.position);
            b.setTarget(EntityManager.target);
            world.getRootNode().attachChild(b);
            
         }
      }.start();
   
      
   }



Please advise!

Andy

You should use pooling. When loading your game create several bullet objects and warmup the particles but just keep them in a pool. When you need, grab one and use it then return it to the pool. There are many examples and discussions on the forum about this approach.

Well thats exactly what my class above does mate - take a look at it.




Heh, sorry about that. I'm still a little hung over from the CommunityOne/JavaOne party last night.

In my game (Xenogeddon) I create all the bullets for shooting on the fly, and there's no lag, so I don't think it's that that's causing the problems.



Having a look at your code, I see that when a bullet is called from the pool, the setTarget() method is called, which in turn creates a new gunShotController(), which then creates a new ExplosionFactory (and calls warmup() on it), which I think is the problem.  You don't need to create an instance of ExplosionFactory.  Just call ExplosionFactory.warmup() at the start of your game (not each time you launch a bullet).

Thats it!



Thanks mate!



It was the explosionFactory warmup code which was nailing it! => Now it runs nicely without evening doing the multithreaded approach. nice!



Thanks very much,



I presume my pooling approach is correct then?

Well, like I said, I don't bother pooling my bullets and it seems fast enough in my game, but it probably is better to do it your way.