From 4c58270bb9524959721ce5f7898f1b514c5fe705 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 24 Feb 2007 11:08:07 +0000 Subject: [PATCH] FASTCOUNT macro to speed up count_enemies() --- src/common/kernel/battle.c | 22 ++++++++++++++++++++++ src/common/kernel/battle.h | 10 ++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/common/kernel/battle.c b/src/common/kernel/battle.c index 50d9f977c..f0e92b37c 100644 --- a/src/common/kernel/battle.c +++ b/src/common/kernel/battle.c @@ -1248,6 +1248,25 @@ count_enemies(battle * b, const fighter * af, int minrow, int maxrow, int select int i = 0; side *es, *as = af->side; +#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 { + b->fast.side = as; + b->fast.status = sr; + b->fast.minrow = minrow; + b->fast.alive=b->alive; + b->fast.maxrow = maxrow; + memset(b->fast.enemies, -1, sizeof(b->fast.enemies)); + } + } + +#endif if (maxrowsides; es; es = es->next) { if (as==NULL || enemy(es, as)) { @@ -1259,6 +1278,9 @@ count_enemies(battle * b, const fighter * af, int minrow, int maxrow, int select if (i>0 && (select&SELECT_FIND)) break; } } +#ifdef FASTCOUNT + b->fast.enemies[select] = i; +#endif return i; } diff --git a/src/common/kernel/battle.h b/src/common/kernel/battle.h index abdbeac38..227c16dd1 100644 --- a/src/common/kernel/battle.h +++ b/src/common/kernel/battle.h @@ -69,6 +69,16 @@ extern "C" { int alive; #ifdef SMALL_BATTLE_MESSAGES boolean small; +#endif +#define FASTCOUNT +#ifdef FASTCOUNT + struct { + struct side * side; + int status; + int alive; + int minrow, maxrow; + int enemies[8]; + } fast; #endif } battle;