]> git.pond.sub.org Git - empserver/blobdiff - include/file.h
Update copyright notice
[empserver] / include / file.h
index d73ee6cd84b913bf42e1066f47dd71c7a9cb097d..fd7eda5f8de9a6872f524df6df6d164d1d22083e 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1986-2013, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                Ken Stevens, Steve McClure, Markus Armbruster
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  Empire is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
@@ -14,8 +14,7 @@
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  *  ---
  *
@@ -26,9 +25,9 @@
  *  ---
  *
  *  file.h: Describes Empire tables (`files' for historical reasons)
- * 
+ *
  *  Known contributors to this file:
- *     Markus Armbruster, 2005-2008
+ *     Markus Armbruster, 2005-2012
  */
 
 #ifndef FILE_H
@@ -40,10 +39,13 @@ struct empfile {
     /* Members with immutable values */
     int uid;                   /* Table ID */
     char *name;                        /* Empire name (e.g., "treaty") */
+    char *pretty_name;         /* prettier name, e.g. "land unit" */
     char *file;                        /* file name, relative to gamedir for
                                   game state, to builtindir for config */
     struct castr *cadef;       /* table column selectors (column meta-data) */
+    int base;                  /* view's base table, else EF_BAD */
     int size;                  /* size of a table entry */
+    int nent;                  /* #table entries, -1 if variable */
     int flags;                 /* only EFF_IMMUTABLE immutable, see below
                                   for use of remaining bits */
 
@@ -60,6 +62,11 @@ struct empfile {
     /* flags bit EFF_CUSTOM also varies */
 
     /* User callbacks, may all be null */
+    /*
+     * Called after element initialization.  ELT is the element.
+     * May modify the element.
+     */
+    void (*oninit)(void *elt);
     /*
      * Called after read.  ID is the element id, and ELT is the
      * element read.  May modify the element.  Modifications are
@@ -67,18 +74,23 @@ struct empfile {
      */
     void (*postread)(int id, void *elt);
     /*
-     * Called before write.  ID is the element id, and ELT is the
-     * element being written.  May modify the element.  Modifications
-     * will be visible to caller of ef_write() and are written to the
-     * file.
+     * Called before write.  ID is the element id, OLD is the element
+     * being updated (null unless it is cached) and ELT is the element
+     * being written.  May modify the element.  Modifications will be
+     * visible to caller of ef_write() and are written to the file.
+     */
+    void (*prewrite)(int id, void *old, void *elt);
+    /*
+     * Called after table size changed, with file type as argument.
      */
-    void (*prewrite)(int id, void *elt);
+    void (*onresize)(int type);
 };
 
 struct emptypedstr {
-    short ef_type;
-    short uid;
-    unsigned seqno;
+    signed ef_type: 8;
+    unsigned seqno: 12;
+    unsigned generation: 12;
+    int uid;
     time_t timestamp;
 };
 
@@ -89,7 +101,7 @@ struct emptypedstr {
  */
 /* Immutable flags, fixed at compile-time */
 /* Dereferencing entry address cast to struct emptypedstr * is safe */
-#define EFF_TYPED      bit(0)
+#define EFF_TYPED      bit(0)
 /*
  * EFF_XY / EFF_OWNER / EFF_GROUP assert that coordinates / owner /
  * group of such a table's entries can be safely obtained by
@@ -98,13 +110,13 @@ struct emptypedstr {
 #define EFF_XY         bit(1)
 #define EFF_OWNER      bit(2)
 #define EFF_GROUP      bit(3)
-/* Table is allocated statically */
+/* Table cache is allocated statically */
 #define EFF_STATIC     bit(4)
 /* Table has a sentinel (all zero, not counted as elt), implies EFF_MEM */
 #define EFF_SENTINEL   bit(5)
 /* All the immutable flags */
 #define EFF_IMMUTABLE \
-    (EFF_TYPED | EFF_XY | EFF_OWNER | EFF_GROUP | EFF_STATIC)
+    (EFF_TYPED | EFF_XY | EFF_OWNER | EFF_GROUP | EFF_STATIC | EFF_SENTINEL)
 /* Flags set when table contents is mapped */
 /* Table is entirely in memory */
 #define EFF_MEM                bit(8)
@@ -190,15 +202,18 @@ enum {
 };
 
 #define EF_IS_GAME_STATE(type) (EF_SECTOR <= (type) && (type) <= EF_DYNMAX)
-#define EF_IS_VIEW(type) (EF_COUNTRY <= (type) && (type) < EF_MAX)
+#define EF_IS_VIEW(type) (empfile[(type)].base != EF_BAD)
 
 extern struct castr *ef_cadef(int);
 extern int ef_read(int, int, void *);
+extern void ef_make_stale(void);
+extern void ef_mark_fresh(int, void *);
 extern void *ef_ptr(int, int);
 extern char *ef_nameof(int);
+extern char *ef_nameof_pretty(int);
 extern time_t ef_mtime(int);
-extern int ef_open(int, int, int);
-extern int ef_open_view(int, int);
+extern int ef_open(int, int);
+extern int ef_open_view(int);
 extern int ef_close(int);
 extern int ef_flush(int);
 extern void ef_blank(int, int, void *);
@@ -206,12 +221,14 @@ extern int ef_write(int, int, void *);
 extern void ef_set_uid(int, void *, int);
 extern int ef_extend(int, int);
 extern int ef_ensure_space(int, int, int);
+extern int ef_id_limit(int);
 extern int ef_truncate(int, int);
 extern int ef_nelem(int);
 extern int ef_flags(int);
 extern int ef_byname(char *);
 extern int ef_byname_from(char *, int *);
-extern int ef_verify(void);
+extern int ef_verify_config(void);
+extern int ef_verify_state(int);
 extern int ef_elt_byname(int, char *);
 
 extern struct empfile empfile[EF_MAX + 1];