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