x


Object Serialization

I am currently working on saving and loading objects, and right now I am loading and unloading using JsonFX. This works well except I don't want the data to be in plain text and packed as efficiently as possible. I've read that I should be serializing the data, and this field is completely new to me.

I've come across protobuf-net which works well for primitive object serialization, however, there are a few things I haven't been able to get working with it, such as serializing Vector3s, for example.

Ideally, at the end of this, I'd like to be able to take a list of game objects, serialize their positions, rotations, and any custom script variables. These game objects will not all have the same scripts attached and I won't need to save all of the variables in each script. With that in mind, can anybody suggest a general idea of how to solve this? My target platform is iOS so I'd like to have as small of a build as possible (as in, no System.xml). I am using c# and have iOS Pro if that matters.

Thank you, Justin

more ▼

asked Jun 29 '11 at 10:54 PM

opsive gravatar image

opsive
180 7 8 14

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Why can't you just convert your Vector3's or Quaternions into float arrays and use those for serialization? That's what I do anyway.. works for me.

more ▼

answered Jun 30 '11 at 04:05 AM

testure gravatar image

testure
4.2k 20 25 48

I thought about that, except I have a lot of different classes which have a unique set of variables. In order for that to work, I would have to write a custom serializable class that corresponds to each class that I want to serialize. So for every Vector3 that I have in one class, I would have to create another Vector3 float array in a corresponding class. In addition, I need to include some properties that are outside the scope of the class (such as game object position/rotation), so I would need some type of abstraction above the first class.

For example, if I have the following class:

class nonserialClass { int intValue; Vector3 vector3Value; }

I would need to convert nonserialClass to the following:

class serialClass { int intValue; serializableVector3 vector3Value; serializableVector3 position; serializableQuaternion rotation; }

I would need to do this for each class that I have, which seems like it would be a maintenance nightmare... unless there is a different way and I am completely misunderstanding (I hope so!)

Jun 30 '11 at 07:19 PM opsive
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4137
x1952
x175

asked: Jun 29 '11 at 10:54 PM

Seen: 1887 times

Last Updated: Jun 30 '11 at 07:21 PM