angband-import / angband-trac

Test importing Trac events into Angband
0 stars 0 forks source link

Write/import new savefile code #42

Closed angband-import closed 4 years ago

angband-import commented 4 years ago

Reported by takkaria on 21 Mar 2007 14:48 UTC There are comments at the top of save.c (see #ifdef FUTURE_SAVEFILES), which indicate plans to create a modular and better-versioned savefile format. I used that as a base to create a new format, which has better versioning support, and is probably a whole lot more future-proof than what's currently there. It also unified save/load code as far as possible.

The new savefile is constructed of a header, followed by a number of blocks, followed by a special "end block". For a fuller description, see [http://ajps.mine.nu/angband/wiki/SavefileCode].

It's also possible to compress this savefile in-memory, should the need be felt. sfuerst was working on this for Z, but I can't find a link for it right now.

angband-import commented 4 years ago

Comment by pmac on 22 Mar 2007 04:17 UTC I have a different model of how to write a save file, using generated code. The following is done with the C preprocessor, but you can use perl or m4 to generate C files from a class definition just as well. The methods are equivalent; it's just that the perl input can be cleaner-looking than c preprocessor macros.

Define two sets of macros that have the same names but different actions as follows:

gen_types.h:

#define F(type, var) type var;
#define C(type, var) type var;
#SERIALIZATION(clazz, fields) \
     struct clazz { fields };

gen_serialization.h:

#define F(type, var)  {"type", "var", TRUE},
#define C(type, var) {"type", "var", FALSE},

#define SERIALIZABLE(type, fields) \
    serialization type [] = { \
        fields \
        {0, 0, 0} \
    };

Then when you define a serializable type, you can generate either the struct or the names of the types (and thus offsets) of the fields in that struct. To save the struct, you just read the field values, then go to the appropriated computed offset. This can be recursive for saving equipment in the pack or in the store.

So, unless there is a significant structural change from one release to another, save files are compatible without any effort, so long as you initialize default values in a sane manner. (That can be done programmatically, or by adding another argument to the F() macros.

For example, the following macro header file:

SERIALIZABLE(player_t,
        F(char,name[100])
        F(byte,race)
        C(int,computed)
        F(u8b,inven_count)
        F(object_t,inventory[24])
)

Can generate either of the following, depending on which macros are included:

struct player_t {
    char name[100];
    byte race;
    int computed;
    u8b inven_count;
    object_t inventory[24];
};

OR this, which defines a (mostly) backwards-compatible serialization of the above structure. Just read or write the data structures, as tuples of (name, type, value)

serialization player_t [] = {
    {"char", "name[100]", TRUE},
    {"byte", "race", TRUE},
    {"int", "computed", FALSE},
    {"u8b", "inven_count", TRUE},
    {"object_t", "inventory[24]", TRUE},
    {0, 0, 0}
};
angband-import commented 4 years ago

Modified by takkaria on 3 Jun 2007 12:41 UTC

angband-import commented 4 years ago

Modified by takkaria on 8 Aug 2007 00:19 UTC

angband-import commented 4 years ago

Comment by takkaria on 11 Aug 2007 21:35 UTC [b9ffb12] (SVN r482), [0968c19] (SVN r491), [0b26f49] (SVN r493), [1598a7f] (SVN r496), [ade0b2a] (SVN r497), [e1b318c] (SVN r500) consist of the work done so far.

angband-import commented 4 years ago

Comment by takkaria on 18 Aug 2007 19:06 UTC Given up on trying to make this performant at the moment; it makes far too many allocations and takes up too much disk space. Running into weird issues while trying to get z-blockfile to use compression routines, so abandoning this for a while.

angband-import commented 4 years ago

Comment by konijn_ on 24 Aug 2007 18:20 UTC Replying to [comment:6 takkaria]:

Given up on trying to make this performant at the moment; it makes far too many allocations and takes up too much disk space. Running into weird issues while trying to get z-blockfile to use compression routines, so abandoning this for a while.

Hey, dont give up yet!! I really, no seriously, REALLY like the idea of having 1 routine for 'doing' a savegame with the helperfunctions doing either save or load depending on the context. This could save over a thousand lines of code and makes screw ups ( adding a var to save, but forgetting to load ) impossible ( or really really hard ).

If you cannot do the blocks thing, please do the unified loading thing.

For sure, I will implement this in Hellband anyway since I had this epiphany about that in the bathroom before even reading this ;)

Cheers, T.

angband-import commented 4 years ago

Modified by takkaria on 25 Aug 2007 11:55 UTC

angband-import commented 4 years ago

Comment by takkaria on 24 Dec 2007 02:03 UTC Reassigning to a more realistic 3.1.1 version, though it might end up being later than that.

angband-import commented 4 years ago

Comment by takkaria on 5 Feb 2008 12:06 UTC Elly is currently working on this, but it may be a while in coming.

angband-import commented 4 years ago

Modified by takkaria on 24 Jan 2009 21:29 UTC

angband-import commented 4 years ago

Modified by takkaria on 27 Jan 2009 02:11 UTC

angband-import commented 4 years ago

Modified by takkaria on 31 Jan 2009 21:49 UTC

angband-import commented 4 years ago

Comment by takkaria on 11 Feb 2009 21:49 UTC [e534667] (SVN r1206), [057b8f3] (SVN r1207), [b8b257f] (SVN r1209), [ef1807b] (SVN r1214)-1217, [7ccc209] (SVN r1235)-[3348a47] (SVN r1238), [765542a] (SVN r1241)-[5da2f9a] (SVN r1244) together implement a new block-based format, as noted in description. thus, fixed.