Runtime Vector Serialization

Forum for plugin, effect and behavior programmers. Please use the Help & Support forum for help using Construct.

Post » Mon Aug 17, 2009 11:58 pm

I have a vector and I don't know how to set it up for runtime serialization. I need this so that quicksave and quickload can be used without emptying the vector in the process. Any way to do this?
Moderator
B
99
S
38
G
19
Posts: 1,584
Reputation: 17,942

Post » Tue Aug 18, 2009 12:12 am

Normally you'd just save the size then iterate each element saving them. When loading do the reverse - load the number of elements then for that number of times, load an element and add it to the vector.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,630

Post » Tue Aug 18, 2009 12:41 am

Well, I attempted something like that, but I really don't know how it would work. What's really complicating this is the fact that it's a vector that contains different instances of a struct I created. It's something like this:

[code:q8e6qass]
struct c_T
{
crapload of variables...
};

vector<c_T> cV;
[/code:q8e6qass]
Whenever I need another instance of this struct, I increase the size of the vector, so I'm not really adding an object to it. Is there some way to serialize everything inside the struct and then put it all back in again?
Moderator
B
99
S
38
G
19
Posts: 1,584
Reputation: 17,942

Post » Tue Aug 18, 2009 8:34 am

Yeah, add a serialize() to the struct that does ar << a << b << c etc, and the same for loading (ar >> a >> b >> c). Then to save the whole vector, save the size, then for each element, call its serialize(). To load it, load the size, clear the vector, then for each element serialize() it in to a temporary struct and push it back to the vector.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,630

Post » Tue Aug 18, 2009 6:51 pm

Any more information on how the Serialize() function works? For example, how do I set it up in the struct. Something like this?

[code:yuo7j083]
struct c_T
{
float a;
float b;
float c;

void Serialize(bin& ar);
};
[/code:yuo7j083]
Or is it different?

Also, how do I use the function in the actual serialization file? It takes an argument, but I don't know what said argument should be. :?
Moderator
B
99
S
38
G
19
Posts: 1,584
Reputation: 17,942


Return to Construct engineering

Who is online

Users browsing this forum: No registered users and 0 guests