Nimbin[12]?Games / Entropie / entropie/src/game/save.h

Entropie git · main

Entropie festival game; first steps

sdl c game entropie cmake · first commit 2026-10-10 · last commit 2026-11-02 (18 hours ago) · synced 10 hours ago

C 88.5% Markdown 9.1% GLSL 2.3%
git clone https://git.christianimmanuel.de/games/Entropie.gitwget https://git.christianimmanuel.de/games/Entropie/archive/Entropie.tar.gz
entropie/src/game/save.h 1.8 KB · 44 lines raw
#ifndef GAME_SAVE_H
#define GAME_SAVE_H

/*
 * Saving and loading a game: a text file (<name>.sav, "key value" lines: the
 * game, then every object) and a binary one (<name>.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 <stdbool.h>
#include <stddef.h>

#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 <dir>/<name>.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 <dir>/<name>.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 */