Various stylistic cleanup.

- Move ARRAY_SIZE() macro to compat.h, add another one ARRAY_SSIZE()
- In A_RadiusDamage(): note maybe-unaligned access issue, prevent unlikely oob
- sector.c: use SPRITES_OF* macros where appropriate

git-svn-id: https://svn.eduke32.com/eduke32@4199 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-12-12 19:22:16 +00:00
parent 9e4f10f3e1
commit ee9e84c356
4 changed files with 34 additions and 43 deletions

View file

@ -777,5 +777,8 @@ static inline void append_ext_UNSAFE(char *outbuf, const char *ext)
extern void EDUKE32_ASSERT_NAME(__LINE__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1])
#endif
#define ARRAY_SIZE(Ar) (sizeof(Ar)/sizeof((Ar)[0]))
#define ARRAY_SSIZE(Ar) (bssize_t)ARRAY_SIZE(Ar)
#endif // __compat_h__

View file

@ -117,7 +117,9 @@ void A_RadiusDamage(int32_t i, int32_t r, int32_t hp1, int32_t hp2, int32_t hp3,
STAT_PLAYER, STAT_FALLER, STAT_ZOMBIEACTOR, STAT_MISC
};
int16_t *const tempshort = (int16_t *)tempbuf;
// XXX: accesses to 'sectorlist' potentially unaligned
int16_t *const sectorlist = (int16_t *)tempbuf;
const int32_t maxsects = sizeof(tempbuf)/sizeof(int16_t);
if (s->picnum == RPG && s->xrepeat < 11)
goto SKIPWALLCHECK;
@ -127,12 +129,12 @@ void A_RadiusDamage(int32_t i, int32_t r, int32_t hp1, int32_t hp2, int32_t hp3,
int32_t sectcnt = 0;
int32_t sectend = 1;
tempshort[0] = s->sectnum;
sectorlist[0] = s->sectnum;
do
{
const walltype *wal;
const int32_t dasect = tempshort[sectcnt++];
const int32_t dasect = sectorlist[sectcnt++];
const int32_t startwall = sector[dasect].wallptr;
const int32_t endwall = startwall+sector[dasect].wallnum;
int32_t w;
@ -163,11 +165,15 @@ void A_RadiusDamage(int32_t i, int32_t r, int32_t hp1, int32_t hp2, int32_t hp3,
{
int32_t dasect2;
for (dasect2=sectend-1; dasect2>=0; dasect2--)
if (tempshort[dasect2] == nextsect)
if (sectorlist[dasect2] == nextsect)
break;
if (dasect2 < 0)
tempshort[sectend++] = nextsect;
{
if (sectend == maxsects)
goto SKIPWALLCHECK; // prevent oob access of 'sectorlist'
sectorlist[sectend++] = nextsect;
}
}
x1 = (((wal->x+wall[wal->point2].x)>>1)+s->x)>>1;
@ -189,7 +195,7 @@ SKIPWALLCHECK:
q = -(16<<8) + (krand()&((32<<8)-1));
for (stati=0; stati<7; stati++) // TODO: ARRAY_SIZE
for (stati=0; stati < ARRAY_SSIZE(statlist); stati++)
{
int32_t j = headspritestat[statlist[stati]];

View file

@ -1816,8 +1816,6 @@ static void G_DrawWeaponTile(int32_t x, int32_t y, int32_t tilenum, int32_t shad
}
}
#define ARRAY_SIZE(Ar) (sizeof(Ar)/sizeof((Ar)[0]))
static int32_t P_DisplayKnee(int32_t gs,int32_t snum)
{
static const int8_t knee_y[] = {0,-8,-16,-32,-64,-84,-108,-108,-108,-72,-32,-8};

View file

@ -1844,10 +1844,12 @@ void A_DamageWall(int32_t spr,int32_t dawallnum,const vec3_t *pos,int32_t atwith
if (wal->picnum == TECHLIGHT4)
wal->picnum = TECHLIGHTBUST4;
if (!wal->lotag) return;
if (wal->lotag == 0)
return;
sn = wal->nextsector;
if (sn < 0) return;
if (sn < 0)
return;
darkestwall = 0;
wal = &wall[sector[sn].wallptr];
@ -1856,17 +1858,15 @@ void A_DamageWall(int32_t spr,int32_t dawallnum,const vec3_t *pos,int32_t atwith
darkestwall=wal->shade;
j = krand()&1;
i= headspritestat[STAT_EFFECTOR];
while (i >= 0)
{
for (SPRITES_OF(STAT_EFFECTOR, i))
if (SHT == wall[dawallnum].lotag && SLT == SE_3_RANDOM_LIGHTS_AFTER_SHOT_OUT)
{
T3 = j;
T4 = darkestwall;
T5 = 1;
}
i = nextspritestat[i];
}
break;
}
}
@ -1906,37 +1906,28 @@ int32_t Sect_DamageCeiling(int32_t sn)
sector[sn].ceilingpicnum = TECHLIGHTBUST4;
if (!sector[sn].hitag)
if (sector[sn].hitag == 0)
{
i = headspritesect[sn];
while (i >= 0)
for (SPRITES_OF_SECT(sn, i))
{
if (PN == SECTOREFFECTOR && SLT == SE_12_LIGHT_SWITCH)
{
j = headspritestat[STAT_EFFECTOR];
while (j >= 0)
{
for (SPRITES_OF(STAT_EFFECTOR, j))
if (sprite[j].hitag == SHT)
actor[j].t_data[3] = 1;
j = nextspritestat[j];
}
break;
}
i = nextspritesect[i];
}
}
i = headspritestat[STAT_EFFECTOR];
j = krand()&1;
while (i >= 0)
{
if (SHT == (sector[sn].hitag) && SLT == SE_3_RANDOM_LIGHTS_AFTER_SHOT_OUT)
for (SPRITES_OF(STAT_EFFECTOR, i))
if (SHT == sector[sn].hitag && SLT == SE_3_RANDOM_LIGHTS_AFTER_SHOT_OUT)
{
T3 = j;
T5 = 1;
}
i = nextspritestat[i];
}
return 1;
}
@ -2413,28 +2404,21 @@ void A_DamageObject(int32_t i,int32_t sn)
void G_AlignWarpElevators(void)
{
int32_t j, i = headspritestat[STAT_EFFECTOR];
int32_t i, j;
while (i >= 0)
for (SPRITES_OF(STAT_EFFECTOR, i))
{
if (SLT == SE_17_WARP_ELEVATOR && SS > 16)
{
j = headspritestat[STAT_EFFECTOR];
while (j >= 0)
for (SPRITES_OF(STAT_EFFECTOR, j))
{
if ((sprite[j].lotag) == SE_17_WARP_ELEVATOR && i != j &&
(SHT) == (sprite[j].hitag))
if (i != j && sprite[j].lotag == SE_17_WARP_ELEVATOR && SHT == sprite[j].hitag)
{
sector[sprite[j].sectnum].floorz =
sector[SECT].floorz;
sector[sprite[j].sectnum].ceilingz =
sector[SECT].ceilingz;
}
j = nextspritestat[j];
sector[sprite[j].sectnum].floorz = sector[SECT].floorz;
sector[sprite[j].sectnum].ceilingz = sector[SECT].ceilingz;
}
}
}
i = nextspritestat[i];
}
}