Deutliche Beschleunigung von get_unitrow() durch Liste der Feinde pro Heer.

This commit is contained in:
Enno Rehling 2004-05-28 21:04:18 +00:00
parent 5296949c1b
commit 81a8fde774
3 changed files with 23 additions and 25 deletions

View File

@ -347,21 +347,20 @@ fbattlerecord(battle * b, faction * f, const char *s)
msg_release(m);
}
boolean
enemy(const side * as, const side * ds)
{
switch(as->enemy[ds->index]) {
case E_ENEMY:
case E_ENEMY|E_ATTACKING:
return true;
default:
return false;
}
}
#define enemy(as, ds) (as->enemy[ds->index]&E_ENEMY)
static void
set_enemy(side * as, side * ds, boolean attacking)
{
int i;
for (i=0;i!=128;++i) {
if (ds->enemies[i]==NULL) ds->enemies[i]=as;
if (ds->enemies[i]==as) break;
}
for (i=0;i!=128;++i) {
if (as->enemies[i]==NULL) as->enemies[i]=ds;
if (as->enemies[i]==ds) break;
}
ds->enemy[as->index] |= E_ENEMY;
as->enemy[ds->index] |= E_ENEMY;
if (attacking) as->enemy[ds->index] |= E_ATTACKING;
@ -506,7 +505,6 @@ get_unitrow(const fighter * af)
static size_t csize = 0;
battle * b = af->side->battle;
void **si;
int enemyfront = 0;
int line, result;
int retreat = 0;
@ -530,17 +528,16 @@ get_unitrow(const fighter * af)
else memset(counted, 0, bsize*sizeof(boolean));
memset(size, 0, sizeof(size));
for (line=FIRST_ROW;line!=NUMROWS;++line) {
int si;
/* how many enemies are there in the first row? */
for (si = b->sides.begin; si != b->sides.end; ++si) {
side *s = *si;
if (s->size[line] && enemy(s, af->side))
{
void ** sf;
for (si=0;af->side->enemies[si];++si) {
side *s = af->side->enemies[si];
if (s->size[line]>0) {
int ai;
enemyfront += s->size[line]; /* - s->nonblockers[line] (nicht, weil angreifer) */
for (sf = b->sides.begin; sf != b->sides.end; ++sf) {
side * ally = *sf;
if (!counted[ally->index] && enemy(s, ally) && !enemy(ally, af->side))
{
for (ai=0;s->enemies[ai];++ai) {
side * ally = s->enemies[ai];
if (!counted[ally->index] && !enemy(ally, af->side)) {
int i;
counted[ally->index] = true;
for (i=0;i!=NUMROWS;++i) size[i] += ally->size[i] - ally->nonblockers[i];

View File

@ -84,6 +84,7 @@ extern "C" {
# define E_ENEMY 1
# define E_ATTACKING 2
int enemy[128];
struct side * enemies[128];
cvector fighters; /* vector der Einheiten dieser Fraktion */
int index; /* Eintrag der Fraktion in b->matrix/b->enemies */
int size[NUMROWS]; /* Anzahl Personen in Reihe X. 0 = Summe */

View File

@ -907,7 +907,7 @@ get_addresses(faction * f)
}
seen_region * reuse;
#define MAXSEEHASH 4999
#define MAXSEEHASH 10007
seen_region * seehash[MAXSEEHASH];
void