Part Dev Diary, part wonderings and sometimes questions too!

hehe Yeah. Same here. I once realized I had a class O star in my generated galaxy (one chance in .00000003f) and I really wanted to find it and check it out (up to now I’ve never seen one “up close”) but I couldn’t save. I was sad. :frowning:



On a different note. I just read the link on serialization and… bleh. Wikipedia’s usefulness is limited. I also noticed that tutorials for saving/loading is empty in the docs. That makes me even sadder.



If I remember correctly, @normen mentioned we had to use Savable instead of Serializable. I’ll search the forums and see what comes up.

Are you talking about standard Java serialization?

I’m just talking about “How do I ‘dump’ my info to disk”. :slight_smile:

I think he’s just talking about serializing his data for which any serialization system should be fine really. Probably you’ll want to look into something that can be easily written to a database.

Note: Savable is an option though if you only need binaries Java’s serialization may be a better way to go. Similar output size, similar extensibility, but with more default behavior built in.

Java’s built in serialization in a nutshell… depending on your data (which I’d have to know about to comment better)…



Classes that you want to save implement java.io.Serializable (and the classes they contain/reference do as well).



Then use ObjectOutputStream writeObject() to write them and ObjectInputStream readObject() to read them.



That part really couldn’t be simpler. It’s the odd edge cases where you want a custom save/load for a particular object or need to support some backwards compatibility where you have to know a little more.

i dont know if it helps you any, but the developer of Infinity Universe seems to have found a way to overcome this issue, there is a development blog with some details located here

It seems I was half-successful into implementing a serialization but I’m hitting a wall.



When I try to save a leaf I get:



java.io.NotSerializableException: com.jme3.math.Vector3f



This reflects what I was saying above, that we, somehow, have to use Savable instead of Serializable. Right? If so, how do I save my stuff using Savable that would work similar to Serializable?



I’m totally lost here. :confused:

Ah… the JME math classes. Personally, I’d be inclined to make them serializable if the rest of the team would go for it. For these sorts of base data structures that are unchanging and pretty straight-forward, I don’t see a down side. And it would certainly make these cases easier.



However, there are ways to make Java serialization work in this case. You can extend ObjectOutputStream and ObjectInputStream and override certain methods. For example, on write you can use enableReplaceObject() and replaceObject() to swap out something like a Vector3f for your own simple serializable version and then on read the resolveObject() can be used to turn your simple object back into a Vector3f.



I assume that Vector3f and maybe Quaternion are the only JME classes you’d be serializing like this?

I’ve got lots of vector3f, as for Quaternions… I might have one of two, but those could be converted, maybe… I’m not sure if I’m actually storing quats, but I think it’s safe to say yes.

Those were the ones that seemed like common things to want to save from game code.



I’ll see what I can do. Making them serializable is easier than extending ObjectXXXStream classes… though that option is always there when an object can’t be serializable for some reason.

So, I have opted for forgiveness over permission and made most of the jme math classes java.io.Serializable. If you build against SVN then you can get them now or wait for the next nightly build… assuming no one reverts the changes. :slight_smile:

pspeed said:
...I have opted for forgiveness over permission...


hahahaha, I'm stealing that :P
thetoucher said:
hahahaha, I'm stealing that :P


:) To be fair, I'm paraphrasing Adm. Grace Hopper: “It is often easier to ask for forgiveness than to ask for permission.”
thetoucher said:
hahahaha, I'm stealing that :P

Just make sure not to try this with a girlfriend/wife. This might not work at all. I wouldn't risk it. ;)

pspeed said:
So, I have opted for forgiveness over permission and made most of the jme math classes java.io.Serializable. If you build against SVN then you can get them now or wait for the next nightly build... assuming no one reverts the changes. :)

Well, THANKS! :D

IT'S ALIIIIIVE!!! Ok, not quite. :P The leafs are getting saved and that's perfect. Just what I needed. Now, all "I have left to do" *cough* sure *cough* is to load it and have a working game... We'll see how long that'll take. ;) I know how to load it, etc, but I'm sure I'll have forgotten some class to dump somewhere, but let's start with the world, then the rest.

That's a real life saver. When I read the email about overriding the read/load methods I mentally groaned but went back to New Vegas so I wouldn't have to think about it. ;) Now I won't have to jump through loops. :)
madjack said:
When I read the email about overriding the read/load methods I mentally groaned but went back to New Vegas so I wouldn't have to think about it. ;) Now I won't have to jump through loops. :)


I would have walked your through it if it came to that. Anything that's possible to do with Java's serialization, I have probably done it at one point or another. It's quite flexible once you know how to make it sit up and roll over. :)
madjack said:
Just make sure not to try this with a girlfriend/wife.


Challenge accepted

@admins - If my account is inactive after the weekend you may as well remove it

Too kind, but I wouldn’t have needed it. It’s just that I was thinking “Why having to go through hoops when a simple ‘implements Serialization’ was needed.” No extra special code to take care of that was needed to make those math classes serializable so why go through the ordeal of overriding the read/load methods when it was so easy to implement.



Note here I’m not making any judgement call here. :slight_smile:

thetoucher said:
Challenge accepted

@admins - If my account is inactive after the weekend you may as well remove it

Good luck. We'll miss you. ;)

OMG. I created a monster! :o



It seems each leaf takes about 95 MB. cries in a corner When I stopped the game it had dumped over 1.5 GB of data.



I guess I’m too tired to code at this time. I’ll take a look at that tomorrow. lol



Edit (goddamn I hate the edit part and having to reformat paragraphs): I was saving the world but with each and every start system, planet, moons and whathaveyou.



It’s better now but it still take a little while… Right now, it took about 2 mins to save the entire galaxy. That means 131 leafs that contains, in total, 47250 stars and their attributes… Each data file taking 6.275 MB. A lot better, but still too much. I’ll have to revise tomorrow.