#ifndef GAME_SAVE_H #define GAME_SAVE_H /* * Saving and loading a game: a text file (.sav, "key value" lines: the * game, then every object) and a binary one (.ground: worn paths and * the wet ground). Loading builds the world as at the start (no drive in), * finds the scene's things again by where they were made, makes the rest * anew, and puts everything back as it was. * * Keeping old saves working (see ARCHITECTURE.md "Saves"): * - A new field: just add it to a table below. Old saves don't have it: it * keeps what the fresh world (or Object_create) gives it. * - A field renamed, or its meaning changed: raise SAVE_FORMAT and add a step * to migrate() in save.c that rewrites the old keys / values. * - Saves from a newer format are refused (not guessed at). */ #include #include #include "game/game.h" #define SAVE_FORMAT 1 #define SAVE_NAME_MAX 48 #define SAVE_LIST_MAX 32 #define SAVE_AUTO "autosave" typedef struct { char name[SAVE_NAME_MAX]; /* file name without .sav */ char label[96]; /* "Day 1, 14:05 - 2.18.0" */ long long when; /* written (seconds since 1970): newest first */ } SaveInfo; /* Writes the game as /.sav (and .ground). False: why, in err. */ bool Save_write(const Game *game, const char *dir, const char *name, char *err, size_t err_size); /* Loads /.sav into game: it is shut down and built again first. */ bool Save_read(Game *game, const char *dir, const char *name, char *err, size_t err_size); /* The saves in dir, newest first; how many. */ int Save_list(const char *dir, SaveInfo *out, int max); /* Saving isn't possible right now (driving in): why, or NULL. */ const char *Save_blocked(const Game *game); #endif /* GAME_SAVE_H */