diff --git a/game.c b/game.c index e00757f..aec0a36 100644 --- a/game.c +++ b/game.c @@ -238,9 +238,8 @@ static void adddetonate(bomb *bmb) { static void processbombs() { bomb *bmb; - listhead *iter; - foreach_list_entry(&activebombs, iter, bmb) { + foreach_list_fast(&activebombs, bmb) { switch(bmb->type) { case BOMB_NORMAL: ++bmb->timer; @@ -379,30 +378,28 @@ static void dodetonations(void) { } static void processflames(void) { - flame *fl; - listhead *iter; + flame *fl, *next; - foreach_list_entry(&activeflames, iter, fl) { + foreach_list_safe(&activeflames, fl, next) { ++(fl->timer); if(fl->timer==FLAMELIFE) { field[fl->py][fl->px]=FIELD_EMPTY; info[fl->py][fl->px]=0; - iter = delinkhead(iter); + delink(fl); } } } static void processdecays() { - brickdecay *bd; - listhead *iter; + brickdecay *bd, *next; - foreach_list_entry(&activedecays, iter, bd) { + foreach_list_safe(&activedecays, bd, next) { ++(bd->timer); if(bd->timer == DECAYLIFE) { field[bd->py][bd->px] = FIELD_EMPTY; trybonus(bd->px, bd->py); - iter = delinkhead(iter); + delink(bd); } } } @@ -410,12 +407,11 @@ static void processdecays() { static void drawbombs(void) { int j; bomb *bmb; - listhead *iter; struct figure *figtab; int color; int xpos,ypos; - foreach_list_entry(&activebombs, iter, bmb) { + foreach_list_fast(&activebombs, bmb) { color=bmb->owner->color; figtab=(bmb->type==BOMB_NORMAL) ? bombs1[color] : bombs2[color]; j=bmb->figcount % (NUMBOMBFRAMES<<1); @@ -429,12 +425,11 @@ static void drawbombs(void) { static void drawflames(void) { flame *fl; - listhead *iter; int xpos,ypos; int color; int fig; - foreach_list_entry(&activeflames, iter, fl) { + foreach_list_fast(&activeflames, fl) { color=fl->owner->color; xpos=tovideox(fl->xpos); ypos=tovideoy(fl->ypos); @@ -446,10 +441,9 @@ static void drawflames(void) { } static void drawdecays() { - listhead *iter; brickdecay *bd; - foreach_list_entry(&activedecays, iter, bd) { + foreach_list_fast(&activedecays, bd) { addsprite(tovideox(bd->xpos),tovideoy(bd->ypos), blocksx+(bd->timer*9)/DECAYLIFE); } @@ -457,9 +451,8 @@ static void drawdecays() { static void drawbonus() { bonustile *bonus; - listhead *iter; - foreach_list_entry(&activebonus, iter, bonus) { + foreach_list_fast(&activebonus, bonus) { addsprite(tovideox(bonus->xpos),tovideoy(bonus->ypos), tiles+bonus->type); } @@ -468,9 +461,8 @@ static void drawbonus() { static void drawplayers() { player *pl; int xpos,ypos; - listhead *iter; - foreach_list_entry(&activeplayers, iter, pl) { + foreach_list_fast(&activeplayers, pl) { if(!(pl->flags & FLG_DEAD)) { if(!pl->figure) pl->figure=walking[pl->color]+30; @@ -483,9 +475,8 @@ static void drawplayers() { static void detonatecontrolled(player *pl) { bomb *bmb; - listhead *iter; - foreach_list_entry(&activebombs, iter, bmb) { + foreach_list_fast(&activebombs, bmb) { if(bmb->owner==pl && bmb->type==BOMB_CONTROLLED) adddetonate(bmb); } @@ -543,9 +534,8 @@ static void processgenerics(void) { static void drawgenerics(void) { generic *gen; - listhead *iter; - foreach_list_entry(&activegeneric, iter, gen) { + foreach_list_fast(&activegeneric, gen) { gen->draw(gen); } } @@ -870,12 +860,11 @@ static int iterate(void) { copyup(); if (activegeneric.next == &activegeneric) { player *pl; - listhead *iter; int deadplayers = 0; i = 0; - foreach_list_entry(&activeplayers, iter, pl) { + foreach_list_fast(&activeplayers, pl) { if(!(pl->flags & FLG_DEAD)) ++i; else diff --git a/list.h b/list.h index 3dd7e68..dc1336e 100644 --- a/list.h +++ b/list.h @@ -7,18 +7,20 @@ void *allocentry(void); void _addtail(listhead *header, listhead *entry); #define addtail(head, entry) _addtail(head, &(entry->list)); -/* returns previous entry, use as - * iter = delinkhead(iter); - * in foreach_list_entry loops - */ +/* returns previous entry */ listhead* delinkhead(listhead *entry); #define delink(entry) delinkhead(&(entry->list)); void initheader(listhead *head); -/* listhead *head, listhead *iter, XXX *item */ -#define foreach_list_entry(head, iter, item) \ - for (iter = (head)->next, item = (void*) iter; iter != (head); iter = iter->next, item = (void*) iter) +/* listhead *head, XXX *item */ +#define foreach_list_fast(head, item) \ + for (item = (void*) (head)->next; (listhead*) item != (head); item = (void*) ((listhead*)item)->next) + +/* listhead *head, XXX *item, XXX *next : you are allowed to delink(item) */ +#define foreach_list_safe(head, item, next) \ + for (item = (void*) (head)->next, next = (void*) ((listhead*)item)->next; (listhead*) item != (head); item = next, next = (void*) ((listhead*)item)->next) + #endif