Hi all, I’m currently working the save game feature on a 2D space RTS game for desktop and Android systems. However, I’m having a hard time finding an approach that works well on Android.
The game state is contained in a single object (“galaxy” of class Galaxy). I write the galaxy object to a file using serialization. For this I both tried vanilla Java serialization and by using the Kryo library. The serialization code is pretty simple and standard, e.g.:
private static void writeFile(FileHandle fileHandle, Object object) throws Exception {
ObjectOutputStream out = new ObjectOutputStream(fileHandle.write(false));
out.writeObject(object);
out.close();
}
This is all very elegant and works fast & smooth as butter on my desktop computer. However, testing this on my Galaxy S2 Android smartphone results consistently in a StackOverflow exception >:(
I kind of know what is causing this: the stack size on Android is smaller than on my desktop computer. Also, the galaxy state object is somewhat nested, e,.g. something like:
Galaxy.stars.get(0).fleets.get(0).get(0).velocity.x
Is a valid call (though somewhat silly) in my code base. However, the save game on my desktop is quite small (beteen 30k and 500k), so its not really a huge amount of data to handle.
There must be a better way to go at this. Do you guys have any ideas on how I could implement a save game feature which does not have this issue? Thanks.