(EF_IS_GAME_STATE): New.

(xdump, main): Use it.

(EF_MAX): Change to largest table ID + 1.  This is now possible
because the changes above get rid of the assumption that
empfile[0..EF_MAX-1] is only game state.  Code can now work on any
table using the advertized empfile interface, not just on game state.
(my_ef_byname): Remove, use ef_byname().
This commit is contained in:
Markus Armbruster 2005-10-28 07:03:31 +00:00
parent 0f6c4296b1
commit 01c248cb59
3 changed files with 26 additions and 33 deletions

View file

@ -58,6 +58,7 @@ struct empfile {
/* /*
* struct empfile flags * struct empfile flags
*/ */
/* Immutable flags */
/* /*
* EFF_XY / EFF_OWNER / EFF_GROUP assert that coordinates / owner / * EFF_XY / EFF_OWNER / EFF_GROUP assert that coordinates / owner /
* group of such a table's entries can be safely obtained by * group of such a table's entries can be safely obtained by
@ -66,14 +67,16 @@ struct empfile {
#define EFF_XY bit(0) #define EFF_XY bit(0)
#define EFF_OWNER bit(1) #define EFF_OWNER bit(1)
#define EFF_GROUP bit(2) #define EFF_GROUP bit(2)
/* Table is entirely in memory */
#define EFF_MEM bit(3)
/* Table is read-only */
#define EFF_RDONLY bit(4)
/* Create table file, clobbering any existing file */
#define EFF_CREATE bit(5)
/* Table is allocated statically */ /* Table is allocated statically */
#define EFF_STATIC bit(6) #define EFF_STATIC bit(3)
/* Flags set when table contents is mapped */
/* Table is entirely in memory */
#define EFF_MEM bit(4)
/* Table is read-only */
#define EFF_RDONLY bit(5)
/* Transient flags, just to control ef_open() */
/* Create table file, clobbering any existing file */
#define EFF_CREATE bit(6)
/* Flags that may be passed to ef_open() */ /* Flags that may be passed to ef_open() */
#define EFF_OPEN (EFF_MEM | EFF_RDONLY | EFF_CREATE) #define EFF_OPEN (EFF_MEM | EFF_RDONLY | EFF_CREATE)
@ -82,14 +85,10 @@ struct empfile {
* Empire `file types' * Empire `file types'
* These are really table IDs. Some tables are backed by files, some * These are really table IDs. Some tables are backed by files, some
* are compiled into the server. * are compiled into the server.
* Historically, only table IDs 0..EF_MAX-1 existed. All the
* functions operating on table IDs still reject the new indexes >=
* EF_MAX. This needs to be rectified, carefully checking existing
* code, which could rely on unspoken assumptions about these tables.
*/ */
/* Error value */ /* Error value */
#define EF_BAD -1 #define EF_BAD -1
/* Dynamic game data tables: 0..EF_MAX-1 */ /* Dynamic game data tables */
#define EF_SECTOR 0 #define EF_SECTOR 0
#define EF_SHIP 1 #define EF_SHIP 1
#define EF_PLANE 2 #define EF_PLANE 2
@ -105,8 +104,7 @@ struct empfile {
#define EF_BMAP 12 #define EF_BMAP 12
#define EF_COMM 13 #define EF_COMM 13
#define EF_LOST 14 #define EF_LOST 14
#define EF_MAX 15 /* Static game data (configuration) */
/* Static game data (configuration): EF_MAX.. */
#define EF_SECTOR_CHR 15 #define EF_SECTOR_CHR 15
#define EF_SHIP_CHR 16 #define EF_SHIP_CHR 16
#define EF_PLANE_CHR 17 #define EF_PLANE_CHR 17
@ -127,6 +125,9 @@ struct empfile {
#define EF_META 29 #define EF_META 29
#define EF_META_TYPE 30 #define EF_META_TYPE 30
#define EF_META_FLAGS 31 #define EF_META_FLAGS 31
#define EF_MAX 32
#define EF_IS_GAME_STATE(type) (EF_SECTOR <= (type) && (type) <= EF_LOST)
struct fileinit { struct fileinit {
int ef_type; int ef_type;
@ -152,6 +153,6 @@ extern int ef_flags(int);
extern int ef_byname(char *); extern int ef_byname(char *);
extern int ef_byname_from(char *, int *); extern int ef_byname_from(char *, int *);
extern struct empfile empfile[]; extern struct empfile empfile[EF_MAX];
#endif /* _FILE_H_ */ #endif /* _FILE_H_ */

View file

@ -80,19 +80,6 @@
/* FIXME document dump format */ /* FIXME document dump format */
/* FIXME don't dump stuff that's useless due to options */ /* FIXME don't dump stuff that's useless due to options */
/*
* Search empfile[] for element named NAME, return its index.
* Return M_NOTFOUND if there are no matches, M_NOTUNIQUE if there are
* several.
* FIXME Merge into ef_byname(). ef_byname() stops at EF_MAX!
*/
static int
my_ef_byname(char *name)
{
return stmtch(name, empfile, offsetof(struct empfile, name),
sizeof(empfile[0]));
}
/* /*
* Evaluate a attribute of an object into VAL, return VAL. * Evaluate a attribute of an object into VAL, return VAL.
* TYPE is the attribute's type. * TYPE is the attribute's type.
@ -379,10 +366,11 @@ xdump(void)
if (!p) if (!p)
return RET_SYN; return RET_SYN;
type = my_ef_byname(p); type = ef_byname(p);
if (type >= EF_MAX || (meta && type >=0)) if (type >= 0) {
if (meta || !EF_IS_GAME_STATE(type))
return xdchr(type, meta); return xdchr(type, meta);
else if (type >= 0) { else
return xditem(type, player->argp[2]); return xditem(type, player->argp[2]);
} else if (!strncmp(p, "opt", strlen(p))) { } else if (!strncmp(p, "opt", strlen(p))) {
return xdopt(); return xdopt();

View file

@ -123,6 +123,8 @@ main(int argc, char *argv[])
exit(1); exit(1);
} }
for (i = 0; i < EF_MAX; i++) { for (i = 0; i < EF_MAX; i++) {
if (!EF_IS_GAME_STATE(i))
continue;
if (!ef_open(i, EFF_CREATE)) { if (!ef_open(i, EFF_CREATE)) {
perror("ef_open"); perror("ef_open");
exit(1); exit(1);
@ -180,6 +182,8 @@ main(int argc, char *argv[])
ef_write(EF_BMAP, i, map); ef_write(EF_BMAP, i, map);
} }
for (i = 0; i < EF_MAX; i++) { for (i = 0; i < EF_MAX; i++) {
if (!EF_IS_GAME_STATE(i))
continue;
ef_close(i); ef_close(i);
} }