From 9fef5c651f39264eaca911759193455cb3963314 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 12 Jan 2004 15:49:34 +0000 Subject: [PATCH] FAST_CONNECT: regionen speichern ihre nachbarn, das beschleunigt hoffentlich das verfluchte pathfinding. --- src/common/kernel/eressea.h | 1 - src/common/kernel/region.c | 12 ++++++++++-- src/common/kernel/region.h | 10 ++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/common/kernel/eressea.h b/src/common/kernel/eressea.h index eb57f7a36..cdc4cf10e 100644 --- a/src/common/kernel/eressea.h +++ b/src/common/kernel/eressea.h @@ -1065,7 +1065,6 @@ const char * findorder(const struct unit * u, const char * cmd); #define attacked(u) (fval(u, UFL_LONGACTION)) boolean idle(struct faction * f); boolean unit_has_cursed_item(struct unit *u); -struct region * rconnect(const struct region *, direction_t dir); /* simple garbage collection: */ void * gc_add(void * p); diff --git a/src/common/kernel/region.c b/src/common/kernel/region.c index 0e8264cd0..48ea8e9ec 100644 --- a/src/common/kernel/region.c +++ b/src/common/kernel/region.c @@ -279,11 +279,16 @@ runhash(region * r) } region * -rconnect(const region * r, direction_t dir) { +r_connect(const region * r, direction_t dir) +{ static int set = 0; static region * buffer[MAXDIRECTIONS]; static const region * last = NULL; - assert(dirconnect[dir]) return r->connect[dir]; +#endif if (r != last) { set = 0; last = r; @@ -292,6 +297,9 @@ rconnect(const region * r, direction_t dir) { if (set & (1 << dir)) return buffer[dir]; buffer[dir] = rfindhash(r->x + delta_x[dir], r->y + delta_y[dir]); set |= (1<connect[dir] = buffer[dir]; +#endif return buffer[dir]; } diff --git a/src/common/kernel/region.h b/src/common/kernel/region.h index e23dec4bc..4086e7f0a 100644 --- a/src/common/kernel/region.h +++ b/src/common/kernel/region.h @@ -21,6 +21,7 @@ extern "C" { #include "language.h" #include +#define FAST_CONNECT #define RF_CHAOTIC (1<<0) #define RF_MALLORN (1<<1) @@ -96,6 +97,9 @@ typedef struct region { #if NEW_RESOURCEGROWTH struct rawmaterial * resources; #endif +#ifdef FAST_CONNECT + struct region * connect[MAXDIRECTIONS]; +#endif } region; 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 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 }