From 5b387f7a08013004623875fc64514e3fc1889505 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Tue, 29 May 2012 20:01:48 +0000 Subject: [PATCH] Introduce two convenient sprite iteration macros in build.h, add a few uses. Defines SPRITES_OF(Statnum, Iter) and SPRITES_OF_SECT(Sectnum, Iter) [The first is so that STAT_* can be substituted for Iter and it reads nicely.] Usage should be self-explanatory, but one thing to keep in mind is that the sprites that are iterated over MUST NOT be deleted. git-svn-id: https://svn.eduke32.com/eduke32@2707 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/include/build.h | 5 +++++ polymer/eduke32/source/actors.c | 13 ++----------- polymer/eduke32/source/sector.c | 6 +++--- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/polymer/eduke32/build/include/build.h b/polymer/eduke32/build/include/build.h index abe4e7e1a..f468fa7e4 100644 --- a/polymer/eduke32/build/include/build.h +++ b/polymer/eduke32/build/include/build.h @@ -76,6 +76,11 @@ extern "C" { #define PR_LIGHT_PRIO_LOW 4 #define PR_LIGHT_PRIO_LOW_GAME 5 +// Convenient sprite iterators, must not be used if any sprites are potentially deleted! +#define SPRITES_OF(Statnum, Iter) Iter=headspritestat[Statnum]; Iter>=0; Iter=nextspritestat[Iter] +#define SPRITES_OF_SECT(Sectnum, Iter) Iter=headspritesect[Sectnum]; Iter>=0; Iter=nextspritesect[Iter] + + ////////// True Room over Room (YAX == rot -17 of "PRO") ////////// #define YAX_ENABLE //#define YAX_DEBUG diff --git a/polymer/eduke32/source/actors.c b/polymer/eduke32/source/actors.c index 5027adc96..954942f2b 100644 --- a/polymer/eduke32/source/actors.c +++ b/polymer/eduke32/source/actors.c @@ -5664,8 +5664,7 @@ ACTOR_STATIC void G_MoveEffectors(void) //STATNUM 3 } } - p = headspritesect[s->sectnum]; - while (p >= 0) + for (SPRITES_OF_SECT(s->sectnum, p)) { // that hardcoded SE light behavior here should be considered temporary at best... // really need some more general system for handling them! @@ -5674,10 +5673,7 @@ ACTOR_STATIC void G_MoveEffectors(void) //STATNUM 3 if (sprite[p].picnum != LASERLINE) { if (sprite[p].picnum == APLAYER && sprite[p].owner >= 0) - { - p = nextspritesect[p]; continue; - } sprite[p].ang += (l*q); sprite[p].ang &= 2047; @@ -5691,7 +5687,6 @@ ACTOR_STATIC void G_MoveEffectors(void) //STATNUM 3 if (move_fixed_sprite(p, j, t[2])) rotatepoint(sprite[j].x,sprite[j].y,sprite[p].x,sprite[p].y,(q*l),&sprite[p].x,&sprite[p].y); } - p = nextspritesect[p]; } } @@ -7391,13 +7386,9 @@ ACTOR_STATIC void G_MoveEffectors(void) //STATNUM 3 A_PlaySound(LIGHTNING_SLAP,i); else if (T3 == (T2>>2)) { - j = headspritestat[STAT_DEFAULT]; - while (j >= 0) - { + for (SPRITES_OF(STAT_DEFAULT, j)) if (sprite[j].picnum == NATURALLIGHTNING && sprite[j].hitag == s->hitag) sprite[j].cstat |= 32768; - j = nextspritestat[j]; - } } else if (T3 > (T2>>3) && T3 < (T2>>2)) { diff --git a/polymer/eduke32/source/sector.c b/polymer/eduke32/source/sector.c index c6873534c..ff43be677 100644 --- a/polymer/eduke32/source/sector.c +++ b/polymer/eduke32/source/sector.c @@ -35,13 +35,14 @@ static int32_t g_haltSoundHack = 0; int32_t A_CallSound(int32_t sn,int32_t whatsprite) { int32_t i; + if (g_haltSoundHack) { g_haltSoundHack = 0; return -1; } - i = headspritesect[sn]; - while (i >= 0) + + for (SPRITES_OF_SECT(sn, i)) { if (PN == MUSICANDSFX && SLT < 1000) { @@ -73,7 +74,6 @@ int32_t A_CallSound(int32_t sn,int32_t whatsprite) } return SLT; } - i = nextspritesect[i]; } return -1; }