Page 1 of 1

Custom Serialization

Posted: Fri Nov 11, 2016 10:57 pm
by thatcosmonaut
I'm creating an in-game level editor to streamline my development process. I'm running into a wall with serialization though.

I'm using the binser library. I have a Level class made up of a bunch of Tile instances. I want the Tile class to only store a reference to its TileType and its location so that it can generate its graphics stuff on deserialization, but I'm not sure how to write the custom serializer/deserializer functions and I can't find any examples. Has anyone done this before?

Re: Custom Serialization

Posted: Fri Nov 11, 2016 11:32 pm
by raidho36
Serialization is converting a complicated object into linear stream of information, hence the name. It doesn't quite applies to what you're doing.

What you need to do is to iterate over tiles and save their locations and type. When you load them, you generate a tile based off information you read from the file.

Re: Custom Serialization

Posted: Sat Nov 12, 2016 12:01 am
by thatcosmonaut
Yea I guess I just thought serialization would be a useful abstraction of that process. But it might just be easier to handle it manually. Thanks for the advice.

Re: Custom Serialization

Posted: Sat Nov 12, 2016 12:19 am
by raidho36
Complete (i.e. default) serialization would carry a lot of irrelevant information about live object, reducing efficiency greatly. It is only really useful if you only use the object as data storage, rather than a class instance.