- use BFSSearch in cansee and deleted the old variant originally used by Exhumed.

This old variant is only useful for demo compatibility, its main difference is that it does not handle slopes, which even for Exhumed is wrong with some custom maps.
This commit is contained in:
Christoph Oelckers 2021-11-18 01:20:46 +01:00
parent 4e31360fe4
commit 3a259c9c46

View file

@ -855,62 +855,18 @@ int32_t nextsectorneighborz(int16_t sectnum, int32_t refz, int16_t topbottom, in
//
// cansee
//
int32_t cansee_old(int32_t xs, int32_t ys, int32_t zs, int16_t sectnums, int32_t xe, int32_t ye, int32_t ze, int16_t sectnume)
{
sectortype *sec, *nsec;
walltype *wal, *wal2;
int32_t intx, inty, intz, i, cnt, nextsector, dasectnum, dacnt, danum;
if ((xs == xe) && (ys == ye) && (sectnums == sectnume)) return 1;
clipsectorlist[0] = sectnums; danum = 1;
for(dacnt=0;dacnt<danum;dacnt++)
{
dasectnum = clipsectorlist[dacnt]; sec = &sector[dasectnum];
for(cnt=sec->wallnum,wal=&wall[sec->wallptr];cnt>0;cnt--,wal++)
{
wal2 = &wall[wal->point2];
if (lintersect(xs,ys,zs,xe,ye,ze,wal->x,wal->y,wal2->x,wal2->y,&intx,&inty,&intz) != 0)
{
nextsector = wal->nextsector; if (nextsector < 0) return 0;
if (intz <= sec->ceilingz) return 0;
if (intz >= sec->floorz) return 0;
nsec = &sector[nextsector];
if (intz <= nsec->ceilingz) return 0;
if (intz >= nsec->floorz) return 0;
for(i=danum-1;i>=0;i--)
if (clipsectorlist[i] == nextsector) break;
if (i < 0) clipsectorlist[danum++] = nextsector;
}
}
if (clipsectorlist[dacnt] == sectnume)
return 1;
}
return 0;
}
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)
{
if (enginecompatibility_mode == ENGINECOMPATIBILITY_19950829)
return cansee_old(x1, y1, z1, sect1, x2, y2, z2, sect2);
int32_t dacnt, danum;
const int32_t x21 = x2-x1, y21 = y2-y1, z21 = z2-z1;
static uint8_t sectbitmap[(MAXSECTORS+7)>>3];
memset(sectbitmap, 0, sizeof(sectbitmap));
if (x1 == x2 && y1 == y2)
return (sect1 == sect2);
sectbitmap[sect1>>3] |= (1 << (sect1&7));
clipsectorlist[0] = sect1; danum = 1;
BFSSearch search(numsectors, sect1);
for (dacnt=0; dacnt<danum; dacnt++)
for (int dasectnum; (dasectnum = search.GetNext()) != BFSSearch::EOL;)
{
const int32_t dasectnum = clipsectorlist[dacnt];
auto const sec = (usectorptr_t)&sector[dasectnum];
uwallptr_t wal;
bssize_t cnt;
@ -953,19 +909,11 @@ int32_t cansee(int32_t x1, int32_t y1, int32_t z1, int16_t sect1, int32_t x2, in
if (z <= cfz[0] || z >= cfz[1])
return 0;
if (!(sectbitmap[nexts>>3] & (1 << (nexts&7))))
{
sectbitmap[nexts>>3] |= (1 << (nexts&7));
clipsectorlist[danum++] = nexts;
}
search.Add(nexts);
}
}
if (sectbitmap[sect2>>3] & (1<<(sect2&7)))
return 1;
return 0;
return search.Check(sect2);
}
//