Custom Serialization

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
thatcosmonaut
Prole
Posts: 9
Joined: Sun Nov 06, 2016 6:04 pm

Custom Serialization

Post 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?
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Custom Serialization

Post 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.
User avatar
thatcosmonaut
Prole
Posts: 9
Joined: Sun Nov 06, 2016 6:04 pm

Re: Custom Serialization

Post 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.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Custom Serialization

Post 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.
Post Reply

Who is online

Users browsing this forum: snibo and 4 guests