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:
parent
d628679a24
commit
6cd3d55c4e
9 changed files with 28 additions and 32 deletions
|
@ -51,18 +51,23 @@
|
|||
#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;
|
||||
|
|
|
@ -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 /
|
||||
|
|
|
@ -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) */
|
||||
|
|
|
@ -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) */
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 *
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 *
|
||||
|
|
|
@ -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 *
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue