Retire the original naive updatesector() and updatesectorz() in favor of the breadth-first versions

git-svn-id: https://svn.eduke32.com/eduke32@7484 1a8010ca-5511-0410-912e-c29ae57300e0

# Conflicts:
#	source/build/src/build.cpp
#	source/build/src/polymer.cpp
This commit is contained in:
terminx 2019-04-06 06:38:10 +00:00 committed by Christoph Oelckers
parent 3c2ea5904a
commit 0edbd45145
3 changed files with 13 additions and 86 deletions

View file

@ -1155,7 +1155,6 @@ void neartag(int32_t xs, int32_t ys, int32_t zs, int16_t sectnum, int16_t ange
int32_t cansee(int32_t x1, int32_t y1, int32_t z1, int16_t sect1,
int32_t x2, int32_t y2, int32_t z2, int16_t sect2);
void updatesector(int32_t const x, int32_t const y, int16_t * const sectnum) ATTRIBUTE((nonnull(3)));
void updatesectorbreadth(int32_t const x, int32_t const y, int16_t * const sectnum) ATTRIBUTE((nonnull(3)));
void updatesectorexclude(int32_t const x, int32_t const y, int16_t * const sectnum,
const uint8_t * const excludesectbitmap) ATTRIBUTE((nonnull(3,4)));
void updatesectorz(int32_t const x, int32_t const y, int32_t const z, int16_t * const sectnum) ATTRIBUTE((nonnull(4)));

View file

@ -1285,7 +1285,7 @@ int32_t clipmove(vec3_t *pos, int16_t *sectnum, int32_t xvect, int32_t yvect,
if ((tempint1^tempint2) < 0)
{
updatesectorbreadth(pos->x, pos->y, sectnum);
updatesector(pos->x, pos->y, sectnum);
return clipReturn;
}
}
@ -1300,7 +1300,7 @@ int32_t clipmove(vec3_t *pos, int16_t *sectnum, int32_t xvect, int32_t yvect,
}
int const osectnum = *sectnum;
updatesectorbreadth(vec.x, vec.y, sectnum);
updatesector(vec.x, vec.y, sectnum);
if (*sectnum == osectnum || editstatus || (*sectnum != -1 && !check_floor_curb(osectnum, *sectnum, flordist, pos->z, vec.x, vec.y)))
{
@ -1435,7 +1435,7 @@ int32_t pushmove(vec3_t *vect, int16_t *sectnum,
} while (clipinsidebox((vec2_t *)vect, i, walldist-4) != 0);
bad = -1;
k--; if (k <= 0) return bad;
updatesectorbreadth(vect->x, vect->y, sectnum);
updatesector(vect->x, vect->y, sectnum);
if (*sectnum < 0) return -1;
}
else

View file

@ -8136,7 +8136,7 @@ int32_t renderDrawRoomsQ16(int32_t daposx, int32_t daposy, int32_t daposz,
else
{
i = globalcursectnum;
updatesectorbreadth(globalposx,globalposy,&globalcursectnum);
updatesector(globalposx,globalposy,&globalcursectnum);
if (globalcursectnum < 0) globalcursectnum = i;
// PK 20110123: I'm not sure what the line above is supposed to do, but 'i'
@ -10994,36 +10994,20 @@ static inline bool inside_z_p(int32_t const x, int32_t const y, int32_t const z,
//
void updatesector(int32_t const x, int32_t const y, int16_t * const sectnum)
{
if (inside_p(x,y,*sectnum))
if (inside_p(x, y, *sectnum))
return;
if ((unsigned)*sectnum < (unsigned)numsectors)
if ((unsigned)*sectnum >= (unsigned)numsectors)
{
const uwalltype *wal = (uwalltype *)&wall[sector[*sectnum].wallptr];
int wallsleft = sector[*sectnum].wallnum;
// we need to support passing in a sectnum of -1, unfortunately
do
{
int const next = wal->nextsector;
if (inside_p(x, y, next))
SET_AND_RETURN(*sectnum, next);
wal++;
}
while (--wallsleft);
for (int i = numsectors - 1; i >= 0; --i)
if (inside_p(x, y, i))
SET_AND_RETURN(*sectnum, i);
SET_AND_RETURN(*sectnum, -1);
}
for (bssize_t i=numsectors-1; i>=0; --i)
if (inside_p(x, y, i))
SET_AND_RETURN(*sectnum, i);
*sectnum = -1;
}
void updatesectorbreadth(int32_t const x, int32_t const y, int16_t * const sectnum)
{
if ((unsigned)*sectnum >= (unsigned)numsectors || inside_p(x, y, *sectnum))
return;
static int16_t sectlist[MAXSECTORS];
static uint8_t sectbitmap[MAXSECTORS>>3];
int32_t nsecs;
@ -11077,64 +11061,8 @@ void updatesectorexclude(int32_t const x, int32_t const y, int16_t * const sectn
// new: if *sectnum >= MAXSECTORS, *sectnum-=MAXSECTORS is considered instead
// as starting sector and the 'initial' z check is skipped
// (not initial anymore because it follows the sector updating due to TROR)
void updatesectorz(int32_t const x, int32_t const y, int32_t const z, int16_t * const sectnum)
{
if ((uint32_t)(*sectnum) < 2*MAXSECTORS)
{
bool nofirstzcheck = false;
if (*sectnum >= MAXSECTORS)
{
*sectnum -= MAXSECTORS;
nofirstzcheck = true;
}
// this block used to be outside the "if" and caused crashes in Polymost Mapster32
int32_t cz, fz;
getzsofslope(*sectnum, x, y, &cz, &fz);
#ifdef YAX_ENABLE
if (z < cz)
{
int const next = yax_getneighborsect(x, y, *sectnum, YAX_CEILING);
if (next >= 0 && z >= getceilzofslope(next, x, y))
SET_AND_RETURN(*sectnum, next);
}
if (z > fz)
{
int const next = yax_getneighborsect(x, y, *sectnum, YAX_FLOOR);
if (next >= 0 && z <= getflorzofslope(next, x, y))
SET_AND_RETURN(*sectnum, next);
}
#endif
if (nofirstzcheck || (z >= cz && z <= fz))
if (inside_p(x, y, *sectnum))
return;
uwalltype const * wal = (uwalltype *)&wall[sector[*sectnum].wallptr];
int wallsleft = sector[*sectnum].wallnum;
do
{
// YAX: TODO: check neighboring sectors here too?
int const next = wal->nextsector;
if (next>=0 && inside_z_p(x,y,z, next))
SET_AND_RETURN(*sectnum, next);
wal++;
}
while (--wallsleft);
}
for (bssize_t i=numsectors-1; i>=0; --i)
if (inside_z_p(x,y,z, i))
SET_AND_RETURN(*sectnum, i);
// fall back to regular old updatesector() because that's still better than returning -1
updatesector(x, y, sectnum);
}
void updatesectorbreadthz(int32_t const x, int32_t const y, int32_t const z, int16_t * const sectnum)
{
bool nofirstzcheck = false;