Captive Imagination
September 10, 2010, 03:46:29 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: jSeamless 1.0 Beta 7 is Available http://www.jseamless.org
 
   Home   Help Search Calendar Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Shared objects same as Sync'ed objects?  (Read 754 times)
0 Members and 1 Guest are viewing this topic.
wolfgang
Newbie
*
Offline Offline

Posts: 14


View Profile
« on: November 18, 2008, 04:31:08 PM »

Hi, just a quick question. Are shared objects the same thing as synchronized objects?
Thanks.
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #1 on: November 19, 2008, 07:37:13 AM »

No, they are very different.  A SharedObject defines an interface that dynamically generates a concrete class that exists in multiple locations and a change at one location synchronizes the changes over the network so the object is identical on all connections.  A RemoteObject is an object that has been instantiated in one location and all remote connections can make calls to its methods via an interface and invocations will be sent over the network and get a response back remotely but the object only exists in one place.  Synchronization (in the JGN methodology) is specifically for keep visual game objects positional (and other information) information in sync across multiple systems.  There are examples in the tests of all three of these systems.
Logged
wolfgang
Newbie
*
Offline Offline

Posts: 14


View Profile
« Reply #2 on: November 19, 2008, 08:09:50 PM »

Hmm not sure I fully understood you. If a synchronized object is moved then all the clients get that change and update their scene-graph? But isn't that the same for a shared object?

Sorry if I'm being a bit slow, I understand normal messages (I built a simple chat server) but I just don't get how JGN works with JME yet Tongue I've been looking through the flag rush tutorial code but I can't figure out how the Vehicle gets sync'd. I get that the server creates a Vehicle and then adds it to the SynchronizationManager. And I understand that when the client connects to the server, the servers SynchronizationManager calls the clients create() method, is that right so far? The thing that confuses me is how the client knows what to make? In the flag rush tutorial the client just grabs the Vehicle in the same way the server does, they use the same code. But what if my server creates and registers 100 different objects (some Box's, some Sphere's and some custom models for example) how does the client know which object to create when its create() method is invoked? I hope my question make any sense and its not too stupid  Embarrassed

Thanks.
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #3 on: November 20, 2008, 07:36:58 AM »

Synchronization is primarily different in the plumbing. Synchronization is made to synchronize at a regular interval specific to a scenegraph so it's constantly sending updates across.  However, in the shared object scenario it does synchronize the content of objects, but on demand rather than at an interval.  You can't really use something like shared objects for a scenegraph because it would send across way too much information.

It is the SynchronizeCreateMessage that defines the information needed to create what is necessary on the scenegraph. There are particular fields to specify additional information, and you can always extend SynchronizeCreateMessage if you need to send more information.
Logged
wolfgang
Newbie
*
Offline Offline

Posts: 14


View Profile
« Reply #4 on: November 20, 2008, 08:15:08 PM »

Thanks, that makes it a lot clearer.

You can't really use something like shared objects for a scenegraph because it would send across way too much information.

What would I use a shared object for then?

It is the SynchronizeCreateMessage that defines the information needed to create what is necessary on the scenegraph. There are particular fields to specify additional information, and you can always extend SynchronizeCreateMessage if you need to send more information.

I was being stupid Cheesy should have figured that one out myself! I've hit a bit of trouble however, I created my own message which extended SynchronizeCreateMessage but for some reason I keep getting this error when I run my code:

Code:
com.captiveimagination.jgn.convert.ConversionException: Error deserializing instance of class: com.virtualplasticity.gaia.jgn.SyncMessage
at com.captiveimagination.jgn.convert.Converter.readClassAndObject(Converter.java:201)
at com.captiveimagination.jgn.NIOMessageServer.readMessage(NIOMessageServer.java:190)
at com.captiveimagination.jgn.TCPMessageServer.read(TCPMessageServer.java:134)
at com.captiveimagination.jgn.NIOMessageServer.updateTraffic(NIOMessageServer.java:143)
at com.captiveimagination.jgn.clientserver.JGNClient.updateTraffic(JGNClient.java:246)
at com.captiveimagination.jgn.clientserver.JGNClient.update(JGNClient.java:235)
at com.captiveimagination.jgn.UpdatableRunnable.run(JGN.java:437)
at java.lang.Thread.run(Thread.java:636)
Caused by: com.captiveimagination.jgn.convert.ConversionException: Error constructing instance of class (check constructors): com.virtualplasticity.gaia.jgn.SyncMessage
at com.captiveimagination.jgn.convert.Converter.newInstance(Converter.java:267)
at com.captiveimagination.jgn.convert.FieldConverter.readObjectData(FieldConverter.java:99)
at com.captiveimagination.jgn.convert.Converter.readClassAndObject(Converter.java:199)
... 7 more
Caused by: java.lang.InstantiationException: com.virtualplasticity.gaia.jgn.SyncMessage
at java.lang.Class.newInstance0(Class.java:357)
at java.lang.Class.newInstance(Class.java:325)
at com.captiveimagination.jgn.convert.Converter.newInstance(Converter.java:265)

Here is my extension of SynchronizeCreateMessage:

Code:
public class SyncMessage extends SynchronizeCreateMessage {
    public String name;
    public String modelURL;
    public float posX, posY, posZ;
    public float angle, rotX, rotY, rotZ;
    public float scaleX, scaleY, scaleZ;
   
    public SyncMessage(String name, String modelURL, Vector3f pos, Vector3f scale, Quaternion rot) {
        this.name = name;
        this.modelURL = modelURL;
        posX=pos.x; posY=pos.y; posZ=pos.z;
        scaleX=scale.x; scaleY=scale.y; scaleZ=scale.z;
        angle=rot.w; rotX=rot.x; rotY=rot.y; rotZ=rot.z;
    }
   
    public Node createNode() {
        Box box = new Box(name, new Vector3f(posX, posY, posZ), new Vector3f(scaleX, scaleY, scaleZ));
        box.setModelBound(new BoundingBox());
        box.updateModelBound();
       
        Node boxNode = new Node(name + "Node");
        boxNode.attachChild(box);
       
        return boxNode;
    }
}
Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #5 on: November 21, 2008, 07:28:25 AM »

All custom Messages must have a default constructor (no-args constructor) for reflection-based instantiation.

Shared Objects are often beneficial for information that may be changed by any of the clients or by one specifically.  For example, in a game where the clients are playing on a specific map there may be a shared object that references information about that map.  When the game ends and they are moving to a new map the shared object would be updated by the server to contain the new map information.  This makes it very easy to get that information to all clients since on the server you would simply modify the values of the shared object and it would be synchronized directly to the clients.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.233 seconds with 22 queries.