- replaced sectordist with a floating point variant with better precision.

This commit is contained in:
Christoph Oelckers 2022-08-04 23:47:47 +02:00
parent b31e6c0bdf
commit e1eb54ecda
3 changed files with 19 additions and 43 deletions

View file

@ -172,7 +172,6 @@ inline void updatesectorz(int32_t const x, int32_t const y, int32_t const z, sec
void updatesectorneighbor(int32_t const x, int32_t const y, int * const sectnum, int32_t maxDistance = MAXUPDATESECTORDIST) ATTRIBUTE((nonnull(3)));
int32_t getsectordist(vec2_t const in, int const sectnum, vec2_t * const out = nullptr);
extern const int16_t *chsecptr_onextwall;
inline int32_t krand(void)

View file

@ -413,11 +413,11 @@ static void clipupdatesector(vec2_t const pos, int * const sectnum, int walldist
if (inside_p(pos.X, pos.Y, *sectnum))
return;
int16_t nsecs = min<int16_t>(getsectordist(pos, *sectnum), INT16_MAX);
double nsecs = SquareDistToSector(pos.X * inttoworld, pos.Y * inttoworld, &sector[*sectnum]);
if (nsecs > (walldist + 8))
double wd = (walldist + 8) * inttoworld; wd *= wd;
if (nsecs > wd)
{
Printf("%s(): initial position (%d, %d) not within initial sector %d; shortest distance %d.\n", __func__, pos.X, pos.Y, *sectnum, nsecs);
walldist = 0x7fff;
}
@ -1057,9 +1057,13 @@ void getzrange(const vec3_t& pos, sectortype* sect, int32_t* ceilz, CollisionBas
vec2_t closest = pos.vec2;
int sectnum = ::sectnum(sect);
if (enginecompatibility_mode == ENGINECOMPATIBILITY_NONE)
getsectordist(closest, sectnum, &closest);
else
getzsofslopeptr(sect,closest.X,closest.Y,ceilz,florz);
{
DVector2 v;
SquareDistToSector(closest.X * inttoworld, closest.Y * inttoworld, &sector[sectnum], &v);
closest = { int(v.X * worldtoint), int(v.Y * worldtoint) };
}
getzsofslopeptr(sect,closest.X,closest.Y,ceilz,florz);
ceilhit.setSector(sect);
florhit.setSector(sect);
@ -1119,9 +1123,13 @@ void getzrange(const vec3_t& pos, sectortype* sect, int32_t* ceilz, CollisionBas
int32_t daz = 0, daz2 = 0;
closest = pos.vec2;
if (enginecompatibility_mode == ENGINECOMPATIBILITY_NONE)
getsectordist(closest, nextsectno, &closest);
else
getzsofslopeptr(nextsect, closest.X,closest.Y, &daz,&daz2);
{
DVector2 v;
SquareDistToSector(closest.X * inttoworld, closest.Y * inttoworld, &sector[nextsectno], &v);
closest = { int(v.X * worldtoint), int(v.Y * worldtoint) };
}
getzsofslopeptr(nextsect, closest.X,closest.Y, &daz,&daz2);
{
if (daz > *ceilz)

View file

@ -471,42 +471,11 @@ int32_t getwalldist(vec2_t const in, int const wallnum, vec2_t * const out)
}
int32_t getsectordist(vec2_t const in, int const sectnum, vec2_t * const out /*= nullptr*/)
{
if (inside_p(in.X, in.Y, sectnum))
{
if (out)
*out = in;
return 0;
}
int32_t distance = INT32_MAX;
vec2_t closest = {};
for (auto& wal : wallsofsector(sectnum))
{
vec2_t p;
int32_t const walldist = getwalldist(in, wallnum(&wal), &p);
if (walldist < distance)
{
distance = walldist;
closest = p;
}
}
if (out)
*out = closest;
return distance;
}
template<class Inside>
void updatesectorneighborz(int32_t const x, int32_t const y, int32_t const z, int* const sectnum, int32_t maxDistance, Inside checker)
{
int const initialsectnum = *sectnum;
double maxDist = maxDistance * inttoworld; maxDist *= maxDist;
if ((validSectorIndex(initialsectnum)))
{
@ -526,7 +495,7 @@ void updatesectorneighborz(int32_t const x, int32_t const y, int32_t const z, in
for (auto& wal : wallsofsector(listsectnum))
{
if (wal.nextsector >= 0 && (iter == 0 || getsectordist({ x, y }, wal.nextsector) <= maxDistance))
if (wal.nextsector >= 0 && (iter == 0 || SquareDistToSector(x * inttoworld, y * inttoworld, wal.nextSector()) <= maxDist))
search.Add(wal.nextsector);
}
iter++;