Is it possible to load a Savable as a supertype of the saved?

Hi.



Is it possible to load a Savable as a supertype of the saved?



If I with the BinaryExporter save, lets say a Box, is it possible to load it as a Spatial?



The result I want is that if I check instanceof Box on it should will return false.



If not, is there a way to Save a Savable as a supertype? (Actually preferrable when I come to think of it).

if i understand you correctly and if you load a Box with the BinaryImporter you have to cast it anyway so instead of



Box b = (Box)BinaryImporter…



do



Spatial b = (Spatial)BinaryImporter…


Thanks!


Rik said:

The result I want is that if I check instanceof Box on it should will return false.


Casting the Box to a Spatial won't make it return false on instanceof Box, will it?
Rik said:

Casting the Box to a Spatial won't make it return false on instanceof Box, will it?



Spatial s = (Spatial)box;

s instanceof Spatial // true

s instanceof Box // true

s instanceof Geometry // true

s instanceof Node // false



note that you get the same results with 'instanceof' when you dont cast the box to spatial

Thanks again but I'm not sure if we understand eachother correctly.



I want instanceof Box to return false.


Rik said:

I want instanceof Box to return false.


if you serialize and then deserialize a Box object this is not possible.
dhdd said:

Rik said:

I want instanceof Box to return false.


if you serialize and then deserialize a Box object this is not possible.

I would not say that. But it at least does not make any sense.

What are you trying to achieve, Rik? It does not sound like it'd be a good solution :P
irrisor said:

I would not say that.


why not?

Serialize a Box, then deserialize it and


spatial instanceof Box


will ALWAYS return true

Well, it depends on what "serialize" and/or "deserialize" means. If you would change the way the object is (de)serialized you can as well change the type of the saved/loaded object… surely not a good thing to do, but it'd be possible.

I’m making a jMonkeyEngine based cluster system called Circus for a multiscreen CAVE. http://www.lundstedt.biz/pmwiki/pmwiki.php?n=PmWiki.Circus



I have a computer on which I run the JME application and listen to changes in the app using AspectJ. I make pointcuts for “primary” calls like attachChild and setLocalTranslation, setVertexBuffer etc.



When a child is attached a ChildAttachedEvent is created, serialized  and sent to the “slave” computers. The ChildAttachedEvent holds the Spatial that was attached in form of a byte array created with BinaryExporter.



When the slave recieves the ChildAttachedEvent it recreates the Spatial with BinaryImporter and attaches it to the scene graph.



I want the slaves to act as passive mirrors doing nothing but displaying the scenegraph. So I want the Spatials to exist on the slaves in it’s simplest forms, being updated with VertexBufferSetEvents over the network rather than acting on them own with controllers.



So If I attach a Door f.ex. (Door has a controller doing collisionchecks and animation) I want to send it as a Trimesh to prevent it from acting on it’s own.



Of course what I should do is create a new simplified instace of the Spatial before sending the event and not try to make BinaryImporter/BinaryExporter do it.

What you should do, imo, is to use a proper data model and sync that instead of (mis)using the scenegraph for it

But that's probably a matter of preference.



What about just skipping the controller, btw? Or deploy different classes on the clients than on the server? Surely easier than hacking the serialization… but if you still want to: have a look into BinaryClassLoader line 125. You can monkey around with the classname/object there.

irrisor said:

What you should do, imo, is to use a proper data model and sync that instead of (mis)using the scenegraph for it

Can you describe that further? I'd love to get suggestions on how to solve it in a more proper way. Do you mean creating my own type instead of sending Trimeshes?

irrisor said:

Or deploy different classes on the clients than on the server?

Yes, thats what I want to do.

irrisor said:

Surely easier than hacking the serialization...

I have definitely moved away from the approach of hacking the serialization.

irrisor said:

What about just skipping the controller, btw?

On which side? Removing the controller on the deserialized Spatial?

Thanks!
Rik said:

irrisor said:

What you should do, imo, is to use a proper data model and sync that instead of (mis)using the scenegraph for it

Can you describe that further? I'd love to get suggestions on how to solve it in a more proper way. Do you mean creating my own type instead of sending Trimeshes?

Well some entities with proper events and synchronize them between the nodes (no scenegraph involved). On each client the entities create the respective visuals. Controllers become transient objects which act on the entities (no jME Controllers). Standard Model-View-Controller design pattern, where the scenegraph is only the view.

Ok, I think I understand and I will certainly consider it.



Thank you!