Saving Game Progress To Nand


u9i

Call me Uni
Joined
Jun 27, 2008
Messages
761
Age
48
Location
Faroe Islands
Website
riotdigital.com
Hi,

I am planning to make my game power-loss save, or whatever i should call it. Basically i want the game to pick up where it left off, should the user turn off the device, or should it run out of power. This poses a few questions that i would like to hear comments and suggestions on.

I will need to save game data continuously, or at least at a reasonably high frequency, maybe once every 10-15 seconds. I plan to do this on the NAND, because i feel the filesystem might be more robust then the FAT formated SD card. Ghostpix once ran out of batteries while saving, and the file got fubar. I hat almost completed it, so you can imagine i was pissed :)

So the questions:

- Will this strain the flash too much, and wear it to an early death?
- Is it better to use the SD card? Is it equally safe/unsafe?
- What filesystem does the Caanoo/Wiz run?
- Where on the system should i save the game data? Is there a /home/???/ folder to put my stuff?

What are the advantages and drawbacks of doing this? Please share your thoughts on this. As a developer or user.

/Uni
 
u9i,

Answering your last two questions:
- The filesystem, according to /etc/mtab is FAT for /mnt/nand and rootfs for /. The fstab says / should be EXT2.
- Since there is no user account but root on Wiz, files should be saved to /root, the "home" for root login. However, it's a limited space (less then 100MB).
Maybe you should /mnt/nand/game/your_app folder (as you would do with normal save games)?
 
i personally dont like the idea of writing to the nand. for me the nand is somewhat holy, because once killed, there's no way to get your wiz back and running again, right? i have no idea how many read/write cycles the wiz actually takes, but i dont want to try it out :)

i managed to kill the filesystem on the 2nd day after i got the wiz - all what i was doing, was putting lots of stuff on the nand to try because i didn't have an SD card at that moment.

also, there must be some reason for GPH why they stopped giving you direct access to it on the caanoo.
 
Yeah, I'd steer clear of the nand if I were you. A bunch of users have had corruptions and had to reflash just from putting things there. Doesn't seem to be all that stable to me.
 
Please don't touch the nand from your application. Save your data on the SD card, somewhere inside the folder where your *.gpe is located, like everyone else :) I would NOT want to have to clean up my NAND after every other game I played. Also there are possible corruption issues already mentioned.

IMO the biggest helper against data loss is a battery low warning. What I do is poll the battery device every minute or so and then display a warning once the lowest level is reached (in my experience this means ~5 minutes until shutdown).
 
Ok fair enough... But isn't this what the iphone does all the time? That is why i am thinking it shouldn't be a problem.

Say i stick to the SD card. Does any of you have suggestions no how i can do this safely? If you read my first post with the Ghostpix problem. I don't want a game that gets interrupted during saving to fuck up the savefile and the player is left with nothing. Also, don't i need to call Sync for my actual save data to get written to the card?

Maybe the Wiz and Caanoo are smarter in that they shut down nicely? Has anyone made experiments with that? Does SDL receive a QUIT event just before the Wiz/Caanoo shuts down?

/Uni
 
I didn't make any experiments with shutdown commands. I really doubt that you'll get any messages from the system. But anyone with more knowledge might prove me wrong.

my 2cent:
The easiest way to go for it is IMO, just backup the old savestate before writing the new one, or move it aside. Thats really simple. Of course, some progress might still get lost because you wrote corrupted data, but at least the old file still exists and might be loadable?
 
u9i said:
Ok fair enough... But isn't this what the iphone does all the time? That is why i am thinking it shouldn't be a problem.

I don't think that's NAND but flash and battery-backed RAM in a standby mode (the iphone doesn't really "poweroff" unless you tell it to, like the old Palm's - they look off but it's a very deep sleep that keeps RAM active and can last for months).

If you're going to save to anything, and you don't know if it'll finish writing, don't write to the savefile that holds a "known good" copy, use a journalling/transaction based method (don't need a journalling FS, just write in blocks and each block you should be able to verify, say by writing a checksum after each block has been written, before you accept it as "good" data).

Or you could use the really simple method of copying the savegames before writing a new one, then removing the "old" save only after checking the new one definitely made it to disk (e.g. a fsync() completes - you might want to push that out to a seperate thread because your game constantly fsync()ing in the main thread may well introduce noticeable pauses). If your game sees TWO save files on startup, verify the "newest" one is valid and complete. If it is, use it. If it's not, remove it and use the "old" one.

And you could also, I don't know, give people an option with "THIS WILL POTENTIALLY WEAR OUT YOUR NAND" as a warning so they can choose which they want to use (checking for existence of a file on the NAND, and falling back to SD if not, won't wear it out). Don't forget - NOTHING guarantees that your data has hit the disk until fsync() returns, and even then it can lie, so you will have exactly the same problems on writing saves to NAND and with SD. Just with SD, your users won't care too much if you "wear it out".

I very much doubt that the Wiz or Canoo do any "safe shutdown", but I can't vouch for that for certain. Even if they do, you still have the same problem that when the battery goes, such things rarely complete as you would like them.

Be safe, save to sensible areas (I think keeping things on SD is much more sensible, personally) introduce checks instead of trying to load half-written saves, and keep a backup if you're worried about losing the user's save. Pretty much sane advice for all scenarios.
 
Last edited by a moderator:
Thanks. I will do some test on the shutdown thingy. There does appear some kind of splash when the wiz turns off. I'm thinking it might just be closing the apps nicely. If that is the case, i only need to save on exit, which would be great. I will let you know what i find out.

The reason for saving to the NAND was that i thought it would be safer. I.e. anything non-FAT must be good for you (no pun intended ;) )
 
u9i said:
There does appear some kind of splash when the wiz turns off. I'm thinking it might just be closing the apps nicely. If that is the case, i only need to save on exit

Yeah, no such luck. Your game is just killed right there and then :(
 
Last edited by a moderator:
According to wikipedia, "when sent to a program, SIGKILL causes it to terminate immediately. In contrast to SIGTERM and SIGINT, this signal cannot be caught or ignored, and the receiving process cannot perform any clean-up upon receiving this signal.

I also looked through the OS (i think it was on the Caanoo) and found the shutdown script, and it does send SIGKILL, and not SIGTERM. In fact, SIGTERM, which can be caught, was commented out. They had an entire block of code dedicated to it, but apparently they decided against it. That is probably why the wiz/caanoo shut down so quickly. An ugly hack. And i still don't know how to change that script since we don't know how to write to the filesystem yet.

/Uni
 
Back
Top