Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement: first shot at serialization / deserialization #27

Open
davidedc opened this issue Mar 17, 2015 · 0 comments
Open

improvement: first shot at serialization / deserialization #27

davidedc opened this issue Mar 17, 2015 · 0 comments

Comments

@davidedc
Copy link

Implemented a first draft of serialization / deserialization. It works on a morph. The morph can be complex (e.g. be a frame with multiple inspectors inside), but for the time being it needs to be self-contained to be functional (e.g. no references to morphs outside the hierarchy of the selected morph).

Since JSON doesn't handle closures, quite a lot of refactoring was needed of the callback system here davidedc/Fizzygum@c33275e and here davidedc/Fizzygum@da0d3d2 . (Closures in callbacks can be just transformed into "normal" method and accompanying parameters to be passed at call time).

Serialisation now hinges on a more generic deepCopy mechanism which replaces the previous "fullCopy" implementation here davidedc/Fizzygum@3e7dfee .

JSON doesn't handle cyclic data structures, or preserve the identity of shared references (i.e. two references to a single object will be restored as references to two equal, but not identical copies), so some work was done to cater for both here davidedc/Fizzygum@6a63643

Improvements will follow to a) allow for "notable" references to Morphs outside the hierarchy of the selected morph (e.g. references to the world morph) b) letting Morphs to pre-process and post/process their state before/after serialisation as they see fit (e.g. to discard transient data that can/should be recalculated, etc.)

Little example animation of one of the tests is attached, note that serialisation / deserialisation at the moment can only be triggered via the console - proper menus and export to file will follow. A frame here is created containing a rectangle and its inspector. The frame is serialized, the world is cleaned, then the frame is deserialized and lastly it's added to the world. All buffers and references work fine.

Note a little glitch: in the deserialised frame, the inspector still has the label containing the ID of the original rectangle (#1), even though it's correctly pointing to a second, new, independent rectangle (#2). In the next iterations the Inspector will have to be given a chance to update its contents based on the state of the new world it appears in...

serialisationdeserialisation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant