Initialize ef_type and uid automatically in ef_extend()

New struct emptypedstr to avoid depending on empobj.h there.

Remove now superfluous manual initializations elsewhere.

This doesn't fix any missing initializations.
This commit is contained in:
Markus Armbruster 2008-02-24 11:07:18 +01:00
parent d628679a24
commit 6cd3d55c4e
9 changed files with 28 additions and 32 deletions

View file

@ -51,18 +51,23 @@
#include "types.h" #include "types.h"
struct empobj { 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; short uid;
natid own; /* is valid if EFF_OWNER is set in table def. */ /* end of part matching struct emptypedstr */
coord x; /* is valid if EFF_XY is set in table def. */ natid own; /* valid if EFF_OWNER is in table's flags */
coord y; /* is valid if EFF_XY is set in table def. */ coord x; /* valid if EFF_XY is in table's flags */
signed char type; /* is valid for sectors and units */ coord y; /* valid if EFF_XY is in table's flags */
signed char type; /* valid for sectors and units */
/* remaining are valid for units */ /* remaining are valid for units */
signed char effic; signed char effic;
signed char mobil; signed char mobil;
unsigned char off; unsigned char off;
short tech; 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; coord opx, opy;
short mission; short mission;
short radius; short radius;

View file

@ -65,13 +65,18 @@ struct empfile {
int (*prewrite)(int, void *); /* called before write, unless null */ int (*prewrite)(int, void *); /* called before write, unless null */
}; };
struct emptypedstr {
short ef_type;
short uid;
};
/* /*
* Flag bits for struct empfile member flags * Flag bits for struct empfile member flags
* Immutable flags are properties of the table and thus cannot change. * Immutable flags are properties of the table and thus cannot change.
* The remaining flags record how the table is being used. * The remaining flags record how the table is being used.
*/ */
/* Immutable flags, fixed at compile-time */ /* 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) #define EFF_TYPED bit(0)
/* /*
* EFF_XY / EFF_OWNER / EFF_GROUP assert that coordinates / owner / * EFF_XY / EFF_OWNER / EFF_GROUP assert that coordinates / owner /

View file

@ -40,7 +40,7 @@
struct loststr { struct loststr {
/* initial part must match struct empobj */ /* initial part must match struct empobj */
short ef_type; short ef_type;
int lost_uid; /* lost ID (assigned, otherwise unused) */ int lost_uid;
natid lost_owner; /* Who lost it */ natid lost_owner; /* Who lost it */
/* end of part matching struct empobj */ /* end of part matching struct empobj */
short lost_type; /* Type of thing (ship, plane, nuke, land, sector) */ short lost_type; /* Type of thing (ship, plane, nuke, land, sector) */

View file

@ -47,7 +47,7 @@
struct nwsstr { struct nwsstr {
/* initial part must match struct empobj */ /* initial part must match struct empobj */
short ef_type; short ef_type;
short nws_uid; /* unused */ short nws_uid;
/* end of part matching struct empobj */ /* end of part matching struct empobj */
natid nws_ano; /* "actor" country # */ natid nws_ano; /* "actor" country # */
signed char nws_vrb; /* action (verb) */ signed char nws_vrb; /* action (verb) */

View file

@ -475,11 +475,17 @@ static void
do_blank(struct empfile *ep, void *buf, int id, int count) do_blank(struct empfile *ep, void *buf, int id, int count)
{ {
int i; int i;
struct emptypedstr *elt;
memset(buf, 0, count * ep->size); memset(buf, 0, count * ep->size);
if (ep->init) { for (i = 0; i < count; i++) {
for (i = 0; i < count; i++) elt = (struct emptypedstr *)((char *)buf + i * ep->size);
ep->init(id + i, (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);
} }
} }

View file

@ -165,11 +165,6 @@ lnd_prewrite(int n, void *ptr)
void void
lnd_init(int n, void *ptr) lnd_init(int n, void *ptr)
{ {
struct lndstr *lp = ptr;
lp->ef_type = EF_LAND;
lp->lnd_uid = n;
lp->lnd_own = 0;
} }
char * char *

View file

@ -101,11 +101,6 @@ nuk_prewrite(int n, void *ptr)
void void
nuk_init(int n, void *ptr) nuk_init(int n, void *ptr)
{ {
struct nukstr *np = ptr;
np->ef_type = EF_NUKE;
np->nuk_uid = n;
np->nuk_own = 0;
} }
int int

View file

@ -144,11 +144,6 @@ pln_prewrite(int n, void *ptr)
void void
pln_init(int n, void *ptr) pln_init(int n, void *ptr)
{ {
struct plnstr *pp = ptr;
pp->ef_type = EF_PLANE;
pp->pln_uid = n;
pp->pln_own = 0;
} }
char * char *

View file

@ -112,11 +112,6 @@ shp_prewrite(int n, void *ptr)
void void
shp_init(int n, void *ptr) shp_init(int n, void *ptr)
{ {
struct shpstr *sp = ptr;
sp->ef_type = EF_SHIP;
sp->shp_uid = n;
sp->shp_own = 0;
} }
char * char *