(WORLD_SZ): New.

(isok, ef_init, bmaps_intersect, bp_init, player_accept)
(finish_sects, main): Use it.

(bp_neighbors, bp_lbcost, pathcost): Use XYOFFSET().  No
functional change.
This commit is contained in:
Markus Armbruster 2007-07-28 12:12:17 +00:00
parent e24b608dc6
commit 56de7a2151
8 changed files with 18 additions and 16 deletions

View file

@ -36,7 +36,10 @@
#include "types.h" #include "types.h"
/* Fast version of sctoff() for normalized arguments: */ /* Return the number of sectors in the world */
#define WORLD_SZ() (WORLD_X * WORLD_Y / 2)
/* Fast version of sctoff() for normalized arguments */
#define XYOFFSET(x, y) (((y) * WORLD_X + (x)) / 2) #define XYOFFSET(x, y) (((y) * WORLD_X + (x)) / 2)
#define XNORM(x) \ #define XNORM(x) \

View file

@ -203,12 +203,12 @@ isok(int x, int y)
nmin = ngold = noil = nur = 0; nmin = ngold = noil = nur = 0;
navail = nfree = nowned = 0; navail = nfree = nowned = 0;
if ((map = malloc((WORLD_X * WORLD_Y) / 2)) == 0) { if (!(map = malloc(WORLD_SZ()))) {
logerror("malloc failed in isok\n"); logerror("malloc failed in isok\n");
pr("Memory error. Tell the deity.\n"); pr("Memory error. Tell the deity.\n");
return 0; return 0;
} }
memset(map, 0, (WORLD_X * WORLD_Y) / 2); memset(map, 0, WORLD_SZ());
ok(map, x, y); ok(map, x, y);
free(map); free(map);
if (nfree < 5) if (nfree < 5)

View file

@ -559,7 +559,7 @@ ef_init(void)
struct symbol *lup; struct symbol *lup;
int i; int i;
empfile[EF_MAP].size = empfile[EF_BMAP].size = (WORLD_X * WORLD_Y) / 2; empfile[EF_MAP].size = empfile[EF_BMAP].size = WORLD_SZ();
ca = (struct castr *)empfile[EF_META].cache; ca = (struct castr *)empfile[EF_META].cache;
for (i = 0; ca[i].ca_name; i++) ; for (i = 0; ca[i].ca_name; i++) ;

View file

@ -403,7 +403,7 @@ bmaps_intersect(natid a, natid b)
char *mapb = ef_ptr(EF_MAP, b); char *mapb = ef_ptr(EF_MAP, b);
int i; int i;
for (i = 0; i < WORLD_X * WORLD_Y / 2; ++i, ++mapa, ++mapb) for (i = 0; i < WORLD_SZ(); ++i, ++mapa, ++mapb)
if (*mapa && *mapa != ' ' && *mapb && *mapb != ' ') if (*mapa && *mapa != ' ' && *mapb && *mapb != ' ')
return 1; return 1;
return 0; return 0;

View file

@ -83,8 +83,7 @@ bp_init(void)
return NULL; return NULL;
if (neighsects == NULL) if (neighsects == NULL)
neighsects = calloc(((WORLD_X * WORLD_Y) / 2) * 6, neighsects = calloc(WORLD_SZ() * 6, sizeof(struct sctstr *));
sizeof(struct sctstr *));
return bp; return bp;
} }
@ -193,7 +192,7 @@ bp_neighbors(struct as_coord c, struct as_coord *cp, void *pp)
y = c.y; y = c.y;
sx = XNORM(x); sx = XNORM(x);
sy = YNORM(y); sy = YNORM(y);
offset = (sy * WORLD_X + sx) / 2; offset = XYOFFSET(sx, sy);
from = &sectp[offset]; from = &sectp[offset];
if (neighsects == NULL) if (neighsects == NULL)
@ -207,7 +206,7 @@ bp_neighbors(struct as_coord c, struct as_coord *cp, void *pp)
ny = y + diroff[q][1]; ny = y + diroff[q][1];
sx = XNORM(nx); sx = XNORM(nx);
sy = YNORM(ny); sy = YNORM(ny);
offset = (sy * WORLD_X + sx) / 2; offset = XYOFFSET(sx, sy);
sp = &sectp[offset]; sp = &sectp[offset];
*ssp = sp; *ssp = sp;
} else { } else {
@ -246,7 +245,7 @@ bp_lbcost(struct as_coord from, struct as_coord to, void *pp)
y = to.y; y = to.y;
sx = XNORM(x); sx = XNORM(x);
sy = YNORM(y); sy = YNORM(y);
offset = (sy * WORLD_X + sx) / 2; offset = XYOFFSET(sx, sy);
return sector_mcost(&sectp[offset], bp->bp_mobtype); return sector_mcost(&sectp[offset], bp->bp_mobtype);
} }
@ -327,7 +326,7 @@ pathcost(struct sctstr *start, char *path, int mob_type)
cy += diroff[o][1]; cy += diroff[o][1];
sx = XNORM(cx); sx = XNORM(cx);
sy = YNORM(cy); sy = YNORM(cy);
offset = (sy * WORLD_X + sx) / 2; offset = XYOFFSET(sx, sy);
sp = &sectp[offset]; sp = &sectp[offset];
cost += sector_mcost(sp, mob_type); cost += sector_mcost(sp, mob_type);
path++; path++;

View file

@ -219,9 +219,9 @@ player_accept(void *unused)
if (NULL != hostp) if (NULL != hostp)
strcpy(np->hostname, hostp->h_name); strcpy(np->hostname, hostp->h_name);
#endif /* RESOLVE_IPADDRESS */ #endif /* RESOLVE_IPADDRESS */
/* XXX may not be big enough */ /* FIXME ancient black magic; figure out true stack need */
stacksize = 100000 stacksize = 100000
/* budget */ + MAX(WORLD_X * WORLD_Y / 2 * sizeof(int) * 7, /* budget */ + MAX(WORLD_SZ() * sizeof(int) * 7,
/* power */ MAXNOC * sizeof(struct powstr)); /* power */ MAXNOC * sizeof(struct powstr));
sprintf(buf, "Player (fd #%d)", ns); sprintf(buf, "Player (fd #%d)", ns);
empth_create(player_login, stacksize, 0, buf, np); empth_create(player_login, stacksize, 0, buf, np);

View file

@ -77,7 +77,7 @@ finish_sects(int etu)
if (g_distptrs == NULL) { if (g_distptrs == NULL) {
logerror("First update since reboot, allocating buffer\n"); logerror("First update since reboot, allocating buffer\n");
/* Allocate the information buffer */ /* Allocate the information buffer */
g_distptrs = malloc((WORLD_X * WORLD_Y / 2) * sizeof(*g_distptrs)); g_distptrs = malloc(WORLD_SZ() * sizeof(*g_distptrs));
if (g_distptrs == NULL) { if (g_distptrs == NULL) {
logerror("malloc failed in finish_sects.\n"); logerror("malloc failed in finish_sects.\n");
return; return;
@ -85,7 +85,7 @@ finish_sects(int etu)
} }
/* Wipe it clean */ /* Wipe it clean */
memset(g_distptrs, 0, (WORLD_X * WORLD_Y / 2) * sizeof(*g_distptrs)); memset(g_distptrs, 0, WORLD_SZ() * sizeof(*g_distptrs));
logerror("delivering...\n"); logerror("delivering...\n");
/* Do deliveries */ /* Do deliveries */

View file

@ -196,7 +196,7 @@ main(int argc, char *argv[])
putsect(&sct); putsect(&sct);
} }
} }
map = calloc(WORLD_X * WORLD_Y / 2, sizeof(*map)); map = calloc(WORLD_SZ(), sizeof(*map));
for (i = 0; i < MAXNOC; i++) { for (i = 0; i < MAXNOC; i++) {
ef_write(EF_MAP, i, map); ef_write(EF_MAP, i, map);
} }