freeserf / freeserf

Settlers 1 (Serf City) clone.
http://jonls.dk/freeserf/
GNU General Public License v3.0
314 stars 51 forks source link

Allow saving the game #40

Closed jonls closed 11 years ago

jonls commented 11 years ago

Some questions: What type of save game format would be best? A binary memory dump (like the original save game format) is easy to implement but it is not very flexible and it is hard to keep compatability when the format changes. A text based format allows easier inspection/debugging/etc. but is a bit more difficult to parse and is larger in size. A simple compression of the output could probably solve the latter issue. Should compatability with the original game be kept for saving games as well as loading? Probably this is too much work in the long run.

wdigger commented 11 years ago

I think backward compatibility is not required. Best format will certainly XML, but probably should think about optimizing storage of homogeneous data (map, etc.).

wdigger commented 11 years ago

libxml2 the best choose for XML processing, it fact it's a standard for most platforms (linux, mac, ios, android...).

jonls commented 11 years ago

Yes, I'm thinking that a structured text format like XML will be the best solution. I will agree that XML may be the best format, but this is because it is so widespread and well-known, not because it is the optimal format. XML is good for document markup with a lot of complications that are useless in this scenario (text nodes, character sets, schemas, validation, ...). Even json would be a better format for it's simplicity, but probably is not as commonly available. I will take a look at the libxml2 API.

jonls commented 11 years ago

Here's a format in ini-style. This is easily readable by humans, and fairly simple to parse (parser is ~100 lines of code). The Largest part is actually unpacking all the values and putting them in the right place. The settings are modelled on the original save game format, so lots of things are redundant, and could be left out of the same file. I think the map tile data could probably also be saved in a more sensible way.

wdigger commented 11 years ago

It is likely that sooner or later will have to save some text. INI file have a significant problem - saving textual values ​​(how to interpret the end of line? Which code page to use?). I have a lot of experience working with ini files, and it's not the most pleasant experience. Time and again, had to solve the problems with portability and parsing :(

jonls commented 11 years ago

Yes, the problem is only with multiline text though, and currently we don't even need single line text. I'm still not convinced that bringing the XML library in as a dependency is worth it at this point. The obvious solution for the encoding problem is just to specify a reasonable encoding from the beginning (utf-8).