FASTROW macro to slightly speed up get_unitrow()

This commit is contained in:
Enno Rehling 2007-02-24 20:09:52 +00:00
parent 4c58270bb9
commit 0e2478bdb9
2 changed files with 40 additions and 13 deletions

View File

@ -476,8 +476,23 @@ get_unitrow(const fighter * af, const side * vs)
int i;
for (i=FIGHT_ROW;i!=row;++i) if (af->side->size[i]) break;
return FIGHT_ROW+(row-i);
} else {
#ifdef FASTROW
battle * b = vs->battle;
if (row==b->rowcache.row && b->alive==b->rowcache.alive && af->side==b->rowcache.as && vs==b->rowcache.vs) {
return b->rowcache.result;
} else {
b->rowcache.alive = b->alive;
b->rowcache.as = af->side;
b->rowcache.vs = vs;
b->rowcache.row = row;
b->rowcache.result = get_row(af->side, row, vs);
return b->rowcache.result;
}
#else
return b->rowcache.result;
#endif
}
return get_row(af->side, row, vs);
}
static void
@ -1251,10 +1266,13 @@ count_enemies(battle * b, const fighter * af, int minrow, int maxrow, int select
#ifdef FASTCOUNT
int sr = statusrow(af->status);
if (select!=SELECT_FIND) {
if (b->alive==b->fast.alive && as==b->fast.side && sr==b->fast.status && minrow==b->fast.minrow && maxrow==b->fast.maxrow) {
if (b->fast.enemies[select]>=0) {
return b->fast.enemies[select];
} else if (select&SELECT_FIND) {
if (b->fast.enemies[select-SELECT_FIND]>=0) {
return b->fast.enemies[select-SELECT_FIND];
}
}
} else {
b->fast.side = as;
@ -1264,7 +1282,6 @@ count_enemies(battle * b, const fighter * af, int minrow, int maxrow, int select
b->fast.maxrow = maxrow;
memset(b->fast.enemies, -1, sizeof(b->fast.enemies));
}
}
#endif
if (maxrow<FIRST_ROW) return 0;

View File

@ -70,6 +70,16 @@ extern "C" {
#ifdef SMALL_BATTLE_MESSAGES
boolean small;
#endif
#define FASTROW
#ifdef FASTROW
struct {
const struct side * as;
const struct side * vs;
int alive;
int row;
int result;
} rowcache;
#endif
#define FASTCOUNT
#ifdef FASTCOUNT
struct {