forked from github/server
speedup for is_guarded(), which is more important with new combat code.
This commit is contained in:
parent
523f47eb58
commit
f1a2a355d0
|
@ -2494,6 +2494,7 @@ setguard(unit * u, unsigned int flags)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fset(u, UFL_GUARD);
|
fset(u, UFL_GUARD);
|
||||||
|
fset(u->region, RF_GUARDED);
|
||||||
if (!a) a = a_add(&u->attribs, a_new(&at_guard));
|
if (!a) a = a_add(&u->attribs, a_new(&at_guard));
|
||||||
a->data.i = (int)flags;
|
a->data.i = (int)flags;
|
||||||
}
|
}
|
||||||
|
|
|
@ -867,9 +867,22 @@ unit *
|
||||||
is_guarded(region * r, unit * u, unsigned int mask)
|
is_guarded(region * r, unit * u, unsigned int mask)
|
||||||
{
|
{
|
||||||
unit *u2;
|
unit *u2;
|
||||||
|
static unit * guardcache;
|
||||||
|
|
||||||
for (u2 = r->units; u2; u2 = u2->next)
|
if (!fval(r, RF_GUARDED)) {
|
||||||
if (is_guardian(u2, u, mask)) return u2;
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@ extern "C" {
|
||||||
|
|
||||||
/* flags that speed up attribute access: */
|
/* flags that speed up attribute access: */
|
||||||
#define RF_TRAVELUNIT (1<<19)
|
#define RF_TRAVELUNIT (1<<19)
|
||||||
|
#define RF_GUARDED (1<<20)
|
||||||
|
|
||||||
#define RF_ALL 0xFFFFFF
|
#define RF_ALL 0xFFFFFF
|
||||||
|
|
||||||
|
|
|
@ -947,31 +947,31 @@ fwriteorder(FILE * F, const order * ord, const struct locale * lang)
|
||||||
unit *
|
unit *
|
||||||
readunit(FILE * F)
|
readunit(FILE * F)
|
||||||
{
|
{
|
||||||
skill_t sk;
|
skill_t sk;
|
||||||
unit * u;
|
unit * u;
|
||||||
int number, n, p;
|
int number, n, p;
|
||||||
order ** orderp;
|
order ** orderp;
|
||||||
|
|
||||||
n = rid(F);
|
n = rid(F);
|
||||||
u = findunit(n);
|
u = findunit(n);
|
||||||
if (u==NULL) {
|
if (u==NULL) {
|
||||||
u = calloc(sizeof(unit), 1);
|
u = calloc(sizeof(unit), 1);
|
||||||
u->no = n;
|
u->no = n;
|
||||||
uhash(u);
|
uhash(u);
|
||||||
} else {
|
} else {
|
||||||
while (u->attribs) a_remove(&u->attribs, u->attribs);
|
while (u->attribs) a_remove(&u->attribs, u->attribs);
|
||||||
while (u->items) i_free(i_remove(&u->items, u->items));
|
while (u->items) i_free(i_remove(&u->items, u->items));
|
||||||
free(u->skills);
|
free(u->skills);
|
||||||
u->skills = 0;
|
u->skills = 0;
|
||||||
u->skill_size = 0;
|
u->skill_size = 0;
|
||||||
u_setfaction(u, NULL);
|
u_setfaction(u, NULL);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
int n = rid(F);
|
int n = rid(F);
|
||||||
faction * f = findfaction(n);
|
faction * f = findfaction(n);
|
||||||
if (f!=u->faction) u_setfaction(u, f);
|
if (f!=u->faction) u_setfaction(u, f);
|
||||||
}
|
}
|
||||||
rds(F, &u->name);
|
rds(F, &u->name);
|
||||||
if (lomem) rds(F, 0);
|
if (lomem) rds(F, 0);
|
||||||
else rds(F, &u->display);
|
else rds(F, &u->display);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
@ -1006,11 +1006,11 @@ readunit(FILE * F)
|
||||||
if (strlen(buf)) u->irace = rc_find(buf);
|
if (strlen(buf)) u->irace = rc_find(buf);
|
||||||
else u->irace = u->race;
|
else u->irace = u->race;
|
||||||
}
|
}
|
||||||
if (u->faction == NULL) {
|
if (u->faction == NULL) {
|
||||||
log_error(("unit %s has faction == NULL\n", unitname(u)));
|
log_error(("unit %s has faction == NULL\n", unitname(u)));
|
||||||
u_setfaction(u, findfaction(MONSTER_FACTION));
|
u_setfaction(u, findfaction(MONSTER_FACTION));
|
||||||
set_number(u, 0);
|
set_number(u, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count_unit(u)) u->faction->no_units++;
|
if (count_unit(u)) u->faction->no_units++;
|
||||||
|
|
||||||
|
@ -1053,12 +1053,13 @@ readunit(FILE * F)
|
||||||
u->flags = ri(F) & ~UFL_DEBUG;
|
u->flags = ri(F) & ~UFL_DEBUG;
|
||||||
u->flags &= UFL_SAVEMASK;
|
u->flags &= UFL_SAVEMASK;
|
||||||
}
|
}
|
||||||
/* Persistente Befehle einlesen */
|
if (u->flags&UFL_GUARD) fset(u->region, UFL_GUARD);
|
||||||
free_orders(&u->orders);
|
/* Persistente Befehle einlesen */
|
||||||
freadstr(F, buf, sizeof(buf));
|
free_orders(&u->orders);
|
||||||
|
freadstr(F, buf, sizeof(buf));
|
||||||
p = n = 0;
|
p = n = 0;
|
||||||
orderp = &u->orders;
|
orderp = &u->orders;
|
||||||
while (*buf != 0) {
|
while (*buf != 0) {
|
||||||
order * ord = parse_order(buf, u->faction->locale);
|
order * ord = parse_order(buf, u->faction->locale);
|
||||||
if (ord!=NULL) {
|
if (ord!=NULL) {
|
||||||
if (++n<MAXORDERS) {
|
if (++n<MAXORDERS) {
|
||||||
|
@ -1074,8 +1075,8 @@ readunit(FILE * F)
|
||||||
}
|
}
|
||||||
if (ord!=NULL) free_order(ord);
|
if (ord!=NULL) free_order(ord);
|
||||||
}
|
}
|
||||||
freadstr(F, buf, sizeof(buf));
|
freadstr(F, buf, sizeof(buf));
|
||||||
}
|
}
|
||||||
if (global.data_version<NOLASTORDER_VERSION) {
|
if (global.data_version<NOLASTORDER_VERSION) {
|
||||||
order * ord;
|
order * ord;
|
||||||
freadstr(F, buf, sizeof(buf));
|
freadstr(F, buf, sizeof(buf));
|
||||||
|
|
|
@ -892,6 +892,7 @@ fix_attribflags(void)
|
||||||
while (a) {
|
while (a) {
|
||||||
if (a->type==&at_guard) {
|
if (a->type==&at_guard) {
|
||||||
fset(u, UFL_GUARD);
|
fset(u, UFL_GUARD);
|
||||||
|
fset(u->region, RF_GUARDED);
|
||||||
}
|
}
|
||||||
else if (a->type==&at_group) {
|
else if (a->type==&at_group) {
|
||||||
fset(u, UFL_GROUP);
|
fset(u, UFL_GROUP);
|
||||||
|
|
Loading…
Reference in New Issue