Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (736)
Games in Android Showcase (224)
games submitted by our members
Games in WIP (813)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Backwards-Forewords Compatible Save Game Data  (Read 1304 times)
0 Members and 1 Guest are viewing this topic.
Offline simulatoralive

Senior Newbie





« Posted 2017-05-15 10:28:37 »

I've got an idea on storing saved games that I think is generally useful and helpful, so I felt I should share it somewhere.

Several months ago I was wracking my brain, looking for a strategy for storing a potentially large set of data for a given 2D game world made up of blocks and a friend sparked a fascinating piece of inspiration for me.  I was debating an XML format vs. some kind of custom-designed binary format and zip files came up in the discussion (he was just throwing out odd-ball ideas, trying to help me out).

That's when the thought hit me full force: zip files are the perfect solution (and Java supports them out of the box, woo!), allowing both backwards and forwards compatibility in my game world format.  My thinking (and what I've been working on) is that the zip archive holds each distinct type of data as a separate file in the archive.  When you need a new type of data, just slap a new file into the archive under a new name.  If an older version needs to load the file, it simply ignores data files it knows nothing about.  When a newer version loads the file, it can supply reasonable defaults for the data it considers to be missing or otherwise extrapolate from existing data (what we'd have to do on old files opened in a new version, anyhow).

The beauty of this is that as your needs change and evolve over time, your method for storing new data does not interfere with or even change the way you store old data, unless you're brave/foolish enough to re-arrange the archive's structure later on.  Another nice bonus is that you get compression for free, if you want it (one can always set the ZIPOutputStream to simply store files instead of compressing them).  Even setting the compression level to it's minimum setting gets you some rather good run-length encoding for only minimal processor usage.

As a more concrete example: the game engine I'm working on uses a number of run-time defined variables in game worlds that are specified mostly by XML files from game mods.  Each block in the world gets it's own little chunk of data for each variable.  From one run to the next, as mods are added and removed from the game, some of these variables may no longer be required.

Since each variable is a primitive type (byte, short, int, long, float or double), all I have to do when storing or loading them is read/write a bunch of raw data to/from the stream, without dealing with all the data being mixed together.  Each variable has it's own file and an extension matching it's primitive type, so anyone poking around in the files in the archive can be assured of the exact type of data based on it's name alone, though discovering it's exact purpose may require looking it up in the meta-data (see next paragraph).

For textual data, like Strings, I'm storing them in XML files.  I'm also storing some minimal meta-data as XML, like the dimensions of the world and a listing of the block types by name, so the world can be reconstructed from the raw numbers from other files.

Now, one hiccup I can see is that sometimes you're going to end up with data you don't know how to parse, because it's either no longer supported, or the mod that needs it was removed.  I currently haven't decided on how to handle that.  It's possible to preserve the old data and hold it in memory until the world is written to disk again, but this would not always be desired.  I think discarding it is probably the way I'll go.  It can always be manually retrieved from an old copy and re-inserted just by manipulating the zip archive a bit.

Another hiccup I see is that once you decide where in the archive a file goes, you can't ever move it without breaking compatibility with older versions.  So, if you make an ugly choice on placement of a file, you're stuck with it.

Anyway, that's my idea.  I hope others find in helpful.

You can find information on my current project here:
http://plus.google.com/collection/Ar-MaB
Offline SteveSmith
« Reply #1 - Posted 2017-05-15 12:11:23 »

Interesting.  I posted a question so Gamedev on Stack Overflow asking about a problem that your solution seems to solve ( https://gamedev.stackexchange.com/questions/120064/simple-way-to-serialize-save-game-data-whilst-allowing-for-future-features ) and a solution on there was to store it as Json.

Offline simulatoralive

Senior Newbie





« Reply #2 - Posted 2017-05-15 12:18:07 »

I've been poking around the internet trying to see if anyone has ever tried this before.  I've seen no evidence of it, so I felt I should share.

This could easily be used with other archive formats and other programming languages, but this is an old forum I used to visit...so, seemed the logical first place.

You can find information on my current project here:
http://plus.google.com/collection/Ar-MaB
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline SteveSmith
« Reply #3 - Posted 2017-05-15 17:31:57 »

It sounds good.  I wasn't criticising at all; your post just reminded me of something I'd briefly looked into before. Smiley  I think my low attention span meant that I'd got bored of my project I was working on at the time long before I implemented anything.

Offline ddyer
« Reply #4 - Posted 2017-05-15 17:51:26 »

Zip files are just a box to store things in.  Sure, it's useful to have a standard box,
but over time the nature of what gets stored will change so much that having a
box won't help much. 

It takes careful planning to remain compatible, and sometimes it's not possible.
The very first step is to embed a version descriptor in the saved format, so
future versions can have a chance to know what they're dealing with.
Offline 65K
« Reply #5 - Posted 2017-05-16 05:10:51 »

My thoughts:

When finding a solution for versionising data, these are two different things:
The concept itself and the way to store data. Using text, binary, json or xml is not part of the design at first place.

One main part of a data version concept is about processing the data.

Your approach is actually not using zip files, but a file system (thats what you get with zip files). Nothing fundamentelly wrong with that of course.

Always favor simple solutions. Not clearly separating versioned data lets complexity explode.

Lethal Running - a RPG about a deadly game show held in a futuristic dysoptian society.
Pages: [1]
  ignore  |  Print  
 
 

 
cybrmynd (125 views)
2017-08-02 12:28:51

cybrmynd (151 views)
2017-08-02 12:19:43

cybrmynd (144 views)
2017-08-02 12:18:09

Sralse (160 views)
2017-07-25 17:13:48

Archive (632 views)
2017-04-27 17:45:51

buddyBro (754 views)
2017-04-05 03:38:00

CopyableCougar4 (1285 views)
2017-03-24 15:39:42

theagentd (1250 views)
2017-03-24 15:32:08

Rule (1225 views)
2017-03-19 12:43:22

Rule (1302 views)
2017-03-19 12:42:17
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!