Does someone has experiences using the SyncObjectManager?

Hi @ all,



i have to program a game for my university. I successfully created a lot of game states and I want to synchronize all objects between one server and multiple clients using JGN. It works fine for adding Objects, but removing them seems to be a bit tricky.

I register the objects using the register-method of the SynchronizationManager.

I thought, that I could just unregister these objects using the unregister(Object obj) method.

But this is not working…



I tried to save a reference of the object in the SyncObjectManager, allowing me to remove this object when receiving the according remove message…

But here the problems begin, everything is working when I'm not saving any objects in the  SynchronizationManager, but when I add one line of code in the create-method, which save references to the added objects in a vector nothing works anymore and I get an exception.



Has someone an idea what might be the reason? Or can I remove objects from the server without saving the references?



Here my code:




public class BasicSyncManager implements SyncObjectManager
{
   //synchronized objects
   private ArrayList<VehicleNode> vehicles;
   private Vector<Weapon> weapons;

   public Object create(SynchronizeCreateMessage scm)
   {
      if(scm instanceof SynchronizeCreatePlayerMessage){
         System.out.println("Create Player Message");
         VehicleNode vehicle = new VehicleNode(1,1,1);
         vehicle.setModelBound(new BoundingBox());
         vehicle.updateModelBound();
         scene.attachChild(vehicle);   
         vehicle.updateGeometricState(0, true);
         vehicle.updateRenderState();
         return vehicle;
      }
      
      if(scm instanceof SynchronizeCreateWeaponMessage){
         System.out.println("Create Weapon Message");
         
         SynchronizeCreateWeaponMessage message = (SynchronizeCreateWeaponMessage)scm;
         
         
            Weapon weapon = new Weapon();
//line causing the prob--->   weapons.add(weapon);
            weapon.setModelBound(new BoundingSphere());
            weapon.updateModelBound();
            scene.attachChild(weapon);   
            weapon.updateGeometricState(0, true);
            weapon.updateRenderState();
         
         return weapon;
      }
      
      return null;
   }

   public boolean remove(SynchronizeRemoveMessage srm, Object obj)
   {
      System.out.println("Remove Message");
      System.out.println(obj.getClass());
      System.out.println(obj.toString());
//      if(obj instanceof Weapon){
//         return weapons.firstElement().removeFromParent();
//      }
      
      return false;
   }

}



Thx a lot for helping

Hi,



I don't know to unregister objects either. Nevertheless which exception do you get exactly?

A NullPointerException may reslut from changing the refenrece within a method.

A little unsure what you're asking or what really seems to be the problem.  Take a look at the FlagRush example in jME-Networking, it should give a good example of adding and removing clients from a game.