engine.c: rewrite nextsectorneighborz() for clarity.

git-svn-id: https://svn.eduke32.com/eduke32@2969 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2012-08-26 22:15:02 +00:00
parent 948b4f82fc
commit 41f2535e91

View file

@ -11062,63 +11062,39 @@ int32_t setspritez(int16_t spritenum, const vec3_t *new)
// //
// nextsectorneighborz // nextsectorneighborz
// //
// -1: ceiling or up
// 1: floor or down
int32_t nextsectorneighborz(int16_t sectnum, int32_t thez, int16_t topbottom, int16_t direction) int32_t nextsectorneighborz(int16_t sectnum, int32_t thez, int16_t topbottom, int16_t direction)
{ {
walltype *wal; int32_t nextz = (direction==1) ? INT32_MAX : INT32_MIN;
int32_t i, testz, nextz; int32_t sectortouse = -1;
int16_t sectortouse;
if (direction == 1) nextz = INT32_MAX; else nextz = INT32_MIN; walltype *wal = &wall[sector[sectnum].wallptr];
int32_t i = sector[sectnum].wallnum;
sectortouse = -1;
wal = &wall[sector[sectnum].wallptr];
i = sector[sectnum].wallnum;
do do
{ {
if (wal->nextsector >= 0) const int32_t ns = wal->nextsector;
if (ns >= 0)
{ {
if (topbottom == 1) const int32_t testz = (topbottom==1) ?
{ sector[ns].floorz : sector[ns].ceilingz;
testz = sector[wal->nextsector].floorz;
if (direction == 1) int32_t ok;
{
if ((testz > thez) && (testz < nextz)) if (direction == 1)
{ ok = (testz > thez && testz < nextz);
nextz = testz;
sectortouse = wal->nextsector;
}
}
else
{
if ((testz < thez) && (testz > nextz))
{
nextz = testz;
sectortouse = wal->nextsector;
}
}
}
else else
ok = (testz < thez && testz > nextz);
if (ok)
{ {
testz = sector[wal->nextsector].ceilingz; nextz = testz;
if (direction == 1) sectortouse = wal->nextsector;
{
if ((testz > thez) && (testz < nextz))
{
nextz = testz;
sectortouse = wal->nextsector;
}
}
else
{
if ((testz < thez) && (testz > nextz))
{
nextz = testz;
sectortouse = wal->nextsector;
}
}
} }
} }
wal++; wal++;
i--; i--;
} }