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

@ -947,31 +947,31 @@ fwriteorder(FILE * F, const order * ord, const struct locale * lang)
unit *
readunit(FILE * F)
{
skill_t sk;
unit * u;
int number, n, p;
skill_t sk;
unit * u;
int number, n, p;
order ** orderp;
n = rid(F);
u = findunit(n);
if (u==NULL) {
u = calloc(sizeof(unit), 1);
u->no = n;
uhash(u);
} else {
while (u->attribs) a_remove(&u->attribs, u->attribs);
while (u->items) i_free(i_remove(&u->items, u->items));
free(u->skills);
u->skills = 0;
u->skill_size = 0;
u_setfaction(u, NULL);
}
{
n = rid(F);
u = findunit(n);
if (u==NULL) {
u = calloc(sizeof(unit), 1);
u->no = n;
uhash(u);
} else {
while (u->attribs) a_remove(&u->attribs, u->attribs);
while (u->items) i_free(i_remove(&u->items, u->items));
free(u->skills);
u->skills = 0;
u->skill_size = 0;
u_setfaction(u, NULL);
}
{
int n = rid(F);
faction * f = findfaction(n);
if (f!=u->faction) u_setfaction(u, f);
}
rds(F, &u->name);
faction * f = findfaction(n);
if (f!=u->faction) u_setfaction(u, f);
}
rds(F, &u->name);
if (lomem) rds(F, 0);
else rds(F, &u->display);
#ifndef NDEBUG
@ -1006,11 +1006,11 @@ readunit(FILE * F)
if (strlen(buf)) u->irace = rc_find(buf);
else u->irace = u->race;
}
if (u->faction == NULL) {
log_error(("unit %s has faction == NULL\n", unitname(u)));
u_setfaction(u, findfaction(MONSTER_FACTION));
set_number(u, 0);
}
if (u->faction == NULL) {
log_error(("unit %s has faction == NULL\n", unitname(u)));
u_setfaction(u, findfaction(MONSTER_FACTION));
set_number(u, 0);
}
if (count_unit(u)) u->faction->no_units++;
@ -1053,12 +1053,13 @@ readunit(FILE * F)
u->flags = ri(F) & ~UFL_DEBUG;
u->flags &= UFL_SAVEMASK;
}
/* Persistente Befehle einlesen */
free_orders(&u->orders);
freadstr(F, buf, sizeof(buf));
if (u->flags&UFL_GUARD) fset(u->region, UFL_GUARD);
/* Persistente Befehle einlesen */
free_orders(&u->orders);
freadstr(F, buf, sizeof(buf));
p = n = 0;
orderp = &u->orders;
while (*buf != 0) {
while (*buf != 0) {
order * ord = parse_order(buf, u->faction->locale);
if (ord!=NULL) {
if (++n<MAXORDERS) {
@ -1074,8 +1075,8 @@ readunit(FILE * F)
}
if (ord!=NULL) free_order(ord);
}
freadstr(F, buf, sizeof(buf));
}
freadstr(F, buf, sizeof(buf));
}
if (global.data_version<NOLASTORDER_VERSION) {
order * ord;
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);