bsergent / overmorrow

Typescript canvas game engine
http://challengercity.com/v4/projects/overmorrow/
0 stars 1 forks source link

Serialization engine #23

Open bsergent opened 6 years ago

bsergent commented 6 years ago

Probably just have a flat class where everything is accessible. No methods except maybe save and load (probably handle those elsewhere though), so really more of a struct. This should then be serialized and exported, saved to local storage, or saved on a server.

bsergent commented 5 years ago

It would be really nice to have the same serialization system support network transfer and saving. Saving would just use the main serialization that fully describes the object, but the network transfer would need some delta packets such PacketEntityMove.

I'm thinking a good way to do this might be how I did it in Altros with each class having a static deserialize() function that returns an instance of that class. So loading from a save file or spawning in a new entity would just require one to call that deserialize() function to create the new instance. Extending upon that, I'd like all classes to keep a static reference of ids and instances so that calling EntityPlayer.deserialize(new PacketEntityMovement) for example would deserialize the PacketEntityMovement, look up the player instance for the given id, apply the movement to that player, and return that player for consistency. In parallel, there'd be a static serialize() function that saves all the metadata for the instance. I'm not sure how movement packets could be generating using this method though.