speedup for is_guarded(), which is more important with new combat code.

This commit is contained in:
Enno Rehling 2007-02-25 13:35:52 +00:00
parent 523f47eb58
commit f1a2a355d0
5 changed files with 52 additions and 35 deletions

View File

@ -2494,6 +2494,7 @@ setguard(unit * u, unsigned int flags)
return;
}
fset(u, UFL_GUARD);
fset(u->region, RF_GUARDED);
if (!a) a = a_add(&u->attribs, a_new(&at_guard));
a->data.i = (int)flags;
}

View File

@ -867,9 +867,22 @@ unit *
is_guarded(region * r, unit * u, unsigned int mask)
{
unit *u2;
static unit * guardcache;
for (u2 = r->units; u2; u2 = u2->next)
if (is_guardian(u2, u, mask)) return u2;
if (!fval(r, RF_GUARDED)) {
return NULL;
}
if (guardcache && guardcache->region==r) {
if (is_guardian(guardcache, u, mask)) {
return guardcache;
}
}
for (u2 = r->units; u2; u2 = u2->next) {
if (is_guardian(u2, u, mask)) {
guardcache = u2;
return u2;
}
}
return NULL;
}

View File

@ -50,6 +50,7 @@ extern "C" {
/* flags that speed up attribute access: */
#define RF_TRAVELUNIT (1<<19)
#define RF_GUARDED (1<<20)
#define RF_ALL 0xFFFFFF

View File

@ -1053,6 +1053,7 @@ readunit(FILE * F)
u->flags = ri(F) & ~UFL_DEBUG;
u->flags &= UFL_SAVEMASK;
}
if (u->flags&UFL_GUARD) fset(u->region, UFL_GUARD);
/* Persistente Befehle einlesen */
free_orders(&u->orders);
freadstr(F, buf, sizeof(buf));

View File

@ -892,6 +892,7 @@ fix_attribflags(void)
while (a) {
if (a->type==&at_guard) {
fset(u, UFL_GUARD);
fset(u->region, RF_GUARDED);
}
else if (a->type==&at_group) {
fset(u, UFL_GROUP);