Skip to content

Commit

Permalink
- merged the cansee wrapper into the actual function and added sector…
Browse files Browse the repository at this point in the history
… validation.
  • Loading branch information
coelckers committed Dec 5, 2021
1 parent 9207195 commit 6928b89
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
8 changes: 1 addition & 7 deletions source/build/include/build.h
Expand Up @@ -379,8 +379,7 @@ int32_t hitscan_(const vec3_t* sv, int16_t sectnum, int32_t vx, int32_t vy, in
void neartag_(int32_t xs, int32_t ys, int32_t zs, int16_t sectnum, int16_t ange,
int16_t *neartagsector, int16_t *neartagwall, int16_t *neartagsprite,
int32_t *neartaghitdist, int32_t neartagrange, uint8_t tagsearch);
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);
int cansee(int x1, int y1, int z1, sectortype* sect1, int x2, int y2, int z2, sectortype* sect2);
int32_t inside(int32_t x, int32_t y, int sectnum);
void dragpoint(int pointhighlight, int32_t dax, int32_t day);
int32_t try_facespr_intersect(uspriteptr_t const spr, vec3_t const in,
Expand Down Expand Up @@ -720,11 +719,6 @@ inline walltype* sectortype::lastWall() const
return &wall[wallptr + wallnum - 1]; // cannot be -1 in a proper map
}

inline int cansee(int x1, int y1, int z1, sectortype* sect1, int x2, int y2, int z2, sectortype* sect2)
{
return cansee(x1, y1, z1, sector.IndexOf(sect1), x2, y2, z2, sector.IndexOf(sect2));
}



#include "iterators.h"
Expand Down
21 changes: 11 additions & 10 deletions source/build/src/engine.cpp
Expand Up @@ -812,18 +812,19 @@ int32_t nextsectorneighborz(int16_t sectnum, int32_t refz, int16_t topbottom, in
// cansee
//

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)
int cansee(int x1, int y1, int z1, sectortype* sect1, int x2, int y2, int z2, sectortype* sect2)
{
if (!sect1 || !sect2) return false;

const int32_t x21 = x2-x1, y21 = y2-y1, z21 = z2-z1;

if (x1 == x2 && y1 == y2)
return (sect1 == sect2);

BFSSearch search(numsectors, sect1);
BFSSectorSearch search(sect1);

for (unsigned dasectnum; (dasectnum = search.GetNext()) != BFSSearch::EOL;)
while (auto sec = search.GetNext())
{
auto const sec = (usectorptr_t)&sector[dasectnum];
uwallptr_t wal;
bssize_t cnt;
for (cnt=sec->wallnum,wal=(uwallptr_t)sec->firstWall(); cnt>0; cnt--,wal++)
Expand All @@ -832,7 +833,7 @@ int32_t cansee(int32_t x1, int32_t y1, int32_t z1, int16_t sect1, int32_t x2, in
const int32_t x31 = wal->x-x1, x34 = wal->x-wal2->x;
const int32_t y31 = wal->y-y1, y34 = wal->y-wal2->y;

int32_t x, y, z, nexts, t, bot;
int32_t x, y, z, t, bot;
int32_t cfz[2];

bot = y21*x34-x21*y34; if (bot <= 0) continue;
Expand All @@ -844,24 +845,24 @@ int32_t cansee(int32_t x1, int32_t y1, int32_t z1, int16_t sect1, int32_t x2, in
continue;
}

nexts = wal->nextsector;

if (nexts < 0 || wal->cstat&32)
return 0;
if (!wal->twoSided() || wal->cstat&32)
return 0;

t = DivScale(t,bot, 24);
x = x1 + MulScale(x21,t, 24);
y = y1 + MulScale(y21,t, 24);
z = z1 + MulScale(z21,t, 24);

getzsofslope(dasectnum, x,y, &cfz[0],&cfz[1]);
getzsofslopeptr(sec, x,y, &cfz[0],&cfz[1]);

if (z <= cfz[0] || z >= cfz[1])
{
return 0;
}

getzsofslope(nexts, x,y, &cfz[0],&cfz[1]);
auto nexts = wal->nextSector();
getzsofslopeptr(nexts, x,y, &cfz[0],&cfz[1]);
if (z <= cfz[0] || z >= cfz[1])
return 0;

Expand Down

0 comments on commit 6928b89

Please sign in to comment.