]> git.pond.sub.org Git - empserver/commitdiff
Initialize ef_type and uid automatically in ef_extend()
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 24 Feb 2008 10:07:18 +0000 (11:07 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Wed, 5 Mar 2008 21:48:23 +0000 (22:48 +0100)
New struct emptypedstr to avoid depending on empobj.h there.

Remove now superfluous manual initializations elsewhere.

This doesn't fix any missing initializations.

include/empobj.h
include/file.h
include/lost.h
include/news.h
src/lib/common/file.c
src/lib/subs/land.c
src/lib/subs/nuke.c
src/lib/subs/plane.c
src/lib/subs/ship.c

index 8300211fe514eb65b31215e6e6a0f97e8d06b2c8..514154a959fbcaf2636aff1812be15aacb34fb3c 100644 (file)
 #include "types.h"
 
 struct empobj {
-    short ef_type;     /* is always valid */
+    /*
+     * initial part must match struct emptypedstr
+     * valid if EFF_TYPED is set in table's flags
+     */
+    short ef_type;
     short uid;
-    natid own;         /* is valid if EFF_OWNER   is set in table def. */
-    coord x;           /* is valid if EFF_XY      is set in table def. */
-    coord y;           /* is valid if EFF_XY      is set in table def. */
-    signed char type;  /* is valid for sectors and units */
+    /* end of part matching struct emptypedstr */
+    natid own;         /* valid if EFF_OWNER is in table's flags */
+    coord x;           /* valid if EFF_XY    is in table's flags */
+    coord y;           /* valid if EFF_XY    is in table's flags */
+    signed char type;  /* valid for sectors and units */
     /* remaining are valid for units */
     signed char effic;
     signed char mobil;
     unsigned char off;
     short tech;        
-    char group;                /* is valid if EFF_GROUP   is set in table def. */
+    char group;                /* valid if EFF_GROUP is in table's flags */
     coord opx, opy;
     short mission;
     short radius;
index 640adbc9e46351f28923d6c1b5af9d9719feae56..43a67f73315a3c6d406113c26062e284ced6b09a 100644 (file)
@@ -65,13 +65,18 @@ struct empfile {
     int (*prewrite)(int, void *); /* called before write, unless null */
 };
 
+struct emptypedstr {
+    short ef_type;
+    short uid;
+};
+
 /*
  * Flag bits for struct empfile member flags
  * Immutable flags are properties of the table and thus cannot change.
  * The remaining flags record how the table is being used.
  */
 /* Immutable flags, fixed at compile-time */
-/* Table entries' addresses can't be safely cast to struct emptyped *.  */
+/* Dereferencing entry address cast to struct emptypedstr * is safe */
 #define EFF_TYPED      bit(0)
 /*
  * EFF_XY / EFF_OWNER / EFF_GROUP assert that coordinates / owner /
index a377c6ec19c52743389d3df9057412161dbdaf4d..179c7b9d37702b9e7cc8e133063c345f12c4aa9f 100644 (file)
@@ -40,7 +40,7 @@
 struct loststr {
     /* initial part must match struct empobj */
     short ef_type;
-    int lost_uid;              /* lost ID (assigned, otherwise unused) */
+    int lost_uid;
     natid lost_owner;          /* Who lost it */
     /* end of part matching struct empobj */
     short lost_type;           /* Type of thing (ship, plane, nuke, land, sector) */
index cc182a9109a14a72f7be77cc93d326b7f346166d..5985d26a1ee2fc3a6b02b572f6b6c71ec8367b11 100644 (file)
@@ -47,7 +47,7 @@
 struct nwsstr {
     /* initial part must match struct empobj */
     short ef_type;
-    short nws_uid;             /* unused */
+    short nws_uid;
     /* end of part matching struct empobj */
     natid nws_ano;             /* "actor" country # */
     signed char nws_vrb;       /* action (verb) */
index 090b60622d5d16cc6e8b2df99ec6f7cd3874a643..2a3f26896632783f145c2020f28ce2c3964af5e5 100644 (file)
@@ -475,11 +475,17 @@ static void
 do_blank(struct empfile *ep, void *buf, int id, int count)
 {
     int i;
+    struct emptypedstr *elt;
 
     memset(buf, 0, count * ep->size);
-    if (ep->init) {
-       for (i = 0; i < count; i++)
-           ep->init(id + i, (char *)buf + i * ep->size);
+    for (i = 0; i < count; i++) {
+       elt = (struct emptypedstr *)((char *)buf + i * ep->size);
+       if (ep->flags & EFF_TYPED) {
+           elt->ef_type = ep->uid;
+           elt->uid = id + i;
+       }
+       if (ep->init)
+           ep->init(id + i, (void *)elt);
     }
 }
 
index 5a2414777ca1354d9274cb76ba06ade5583b35db..2f5d68700da95e2cb5947cf2d536e839bbb2cc51 100644 (file)
@@ -165,11 +165,6 @@ lnd_prewrite(int n, void *ptr)
 void
 lnd_init(int n, void *ptr)
 {
-    struct lndstr *lp = ptr;
-
-    lp->ef_type = EF_LAND;
-    lp->lnd_uid = n;
-    lp->lnd_own = 0;
 }
 
 char *
index c895e69c1142014e7475a147ee715fec4aa5f0d0..8d8c44f02ed29cf6c98cfef5ee31d4f2f4276e80 100644 (file)
@@ -101,11 +101,6 @@ nuk_prewrite(int n, void *ptr)
 void
 nuk_init(int n, void *ptr)
 {
-    struct nukstr *np = ptr;
-
-    np->ef_type = EF_NUKE;
-    np->nuk_uid = n;
-    np->nuk_own = 0;
 }
 
 int
index 0cddce20b271894f16614e4ae6990a4137e89928..a5b5e0e7b2d8b55179985cf54a36c0073ee9431f 100644 (file)
@@ -144,11 +144,6 @@ pln_prewrite(int n, void *ptr)
 void
 pln_init(int n, void *ptr)
 {
-    struct plnstr *pp = ptr;
-
-    pp->ef_type = EF_PLANE;
-    pp->pln_uid = n;
-    pp->pln_own = 0;
 }
 
 char *
index dcdf68143871de76a7f75fbcd626bc5f24fe7f90..3653663ccafaa53c1fee513a4999c30fb017337f 100644 (file)
@@ -112,11 +112,6 @@ shp_prewrite(int n, void *ptr)
 void
 shp_init(int n, void *ptr)
 {
-    struct shpstr *sp = ptr;
-
-    sp->ef_type = EF_SHIP;
-    sp->shp_uid = n;
-    sp->shp_own = 0;
 }
 
 char *