#include "types.h"
-/* Used to calculate an offset into an array. Used for
- dynamically sizing the world. */
-#define XYOFFSET(x, y) (((y) * WORLD_X) + (x))
+/* Fast version of sctoff() for normalized arguments: */
+#define XYOFFSET(x, y) (((y) * WORLD_X + (x)) / 2)
#define XNORM(x) \
(((x) < 0) ? ((WORLD_X - (-(x) % WORLD_X)) % WORLD_X) : ((x) % WORLD_X))
if (g_distptrs == NULL) {
logerror("First update since reboot, allocating buffer\n");
/* Allocate the information buffer */
- g_distptrs = (struct distinfo *)(malloc((WORLD_X * WORLD_Y) *
- sizeof(struct distinfo)));
+ g_distptrs = malloc((WORLD_X * WORLD_Y / 2) * sizeof(*g_distptrs));
if (g_distptrs == NULL) {
logerror("malloc failed in finish_sects.\n");
return;
}
-
- logerror("Allocated '%lu' bytes '%d' indices\n",
- (unsigned long)(WORLD_X * WORLD_Y * sizeof(struct distinfo)),
- WORLD_X * WORLD_Y);
}
/* Wipe it clean */
- memset(g_distptrs, 0, ((WORLD_X * WORLD_Y) * sizeof(struct distinfo)));
+ memset(g_distptrs, 0, (WORLD_X * WORLD_Y / 2) * sizeof(*g_distptrs));
logerror("delivering...\n");
/* Do deliveries */