FAST_CONNECT: regionen speichern ihre nachbarn, das beschleunigt hoffentlich das verfluchte pathfinding.

This commit is contained in:
Enno Rehling 2004-01-12 15:49:34 +00:00
parent c64f49d98d
commit 9fef5c651f
3 changed files with 20 additions and 3 deletions

View File

@ -1065,7 +1065,6 @@ const char * findorder(const struct unit * u, const char * cmd);
#define attacked(u) (fval(u, UFL_LONGACTION)) #define attacked(u) (fval(u, UFL_LONGACTION))
boolean idle(struct faction * f); boolean idle(struct faction * f);
boolean unit_has_cursed_item(struct unit *u); boolean unit_has_cursed_item(struct unit *u);
struct region * rconnect(const struct region *, direction_t dir);
/* simple garbage collection: */ /* simple garbage collection: */
void * gc_add(void * p); void * gc_add(void * p);

View File

@ -279,11 +279,16 @@ runhash(region * r)
} }
region * region *
rconnect(const region * r, direction_t dir) { r_connect(const region * r, direction_t dir)
{
static int set = 0; static int set = 0;
static region * buffer[MAXDIRECTIONS]; static region * buffer[MAXDIRECTIONS];
static const region * last = NULL; static const region * last = NULL;
assert(dir<MAXDIRECTIONS); assert(dir<MAXDIRECTIONS);
#ifdef FAST_CONNECT
if (r->connect[dir]) return r->connect[dir];
#endif
if (r != last) { if (r != last) {
set = 0; set = 0;
last = r; last = r;
@ -292,6 +297,9 @@ rconnect(const region * r, direction_t dir) {
if (set & (1 << dir)) return buffer[dir]; if (set & (1 << dir)) return buffer[dir];
buffer[dir] = rfindhash(r->x + delta_x[dir], r->y + delta_y[dir]); buffer[dir] = rfindhash(r->x + delta_x[dir], r->y + delta_y[dir]);
set |= (1<<dir); set |= (1<<dir);
#ifdef FAST_CONNECT
r->connect[dir] = buffer[dir];
#endif
return buffer[dir]; return buffer[dir];
} }

View File

@ -21,6 +21,7 @@ extern "C" {
#include "language.h" #include "language.h"
#include <assert.h> #include <assert.h>
#define FAST_CONNECT
#define RF_CHAOTIC (1<<0) #define RF_CHAOTIC (1<<0)
#define RF_MALLORN (1<<1) #define RF_MALLORN (1<<1)
@ -96,6 +97,9 @@ typedef struct region {
#if NEW_RESOURCEGROWTH #if NEW_RESOURCEGROWTH
struct rawmaterial * resources; struct rawmaterial * resources;
#endif #endif
#ifdef FAST_CONNECT
struct region * connect[MAXDIRECTIONS];
#endif
} region; } region;
typedef struct region_list { typedef struct region_list {
@ -227,6 +231,12 @@ extern int read_region_reference(struct region ** r, FILE * F);
extern void write_region_reference(const struct region * r, FILE * F); extern void write_region_reference(const struct region * r, FILE * F);
extern struct unit * region_owner(const struct region * r); extern struct unit * region_owner(const struct region * r);
extern struct region * r_connect(const struct region *, direction_t dir);
#ifdef FAST_CONNECT
# define rconnect(r, dir) ((r)->connect[dir]?(r)->connect[dir]:r_connect(r, dir))
#else
# define rconnect(r, dir) r_connect(r, dir)
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }