forked from github/server
FAST_CONNECT: regionen speichern ihre nachbarn, das beschleunigt hoffentlich das verfluchte pathfinding.
This commit is contained in:
parent
c64f49d98d
commit
9fef5c651f
|
@ -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);
|
||||
|
|
|
@ -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(dir<MAXDIRECTIONS);
|
||||
|
||||
assert(dir<MAXDIRECTIONS);
|
||||
#ifdef FAST_CONNECT
|
||||
if (r->connect[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<<dir);
|
||||
#ifdef FAST_CONNECT
|
||||
r->connect[dir] = buffer[dir];
|
||||
#endif
|
||||
return buffer[dir];
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ extern "C" {
|
|||
#include "language.h"
|
||||
#include <assert.h>
|
||||
|
||||
#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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue