- final cleanup of sectnum related stuff.

Made sure that remaining uses of sector indices are safe to be kept and deleted a few redundant functions.
This commit is contained in:
Christoph Oelckers 2021-12-06 18:17:45 +01:00
parent 6d432fca0a
commit 838bed7800
10 changed files with 38 additions and 63 deletions

View file

@ -351,7 +351,7 @@ int hitscan(const vec3_t& start, const sectortype* startsect, const vec3_t& dire
void neartag(const vec3_t& pos, sectortype* sect, int angle, HitInfoBase& result, int neartagrange, int tagsearch);
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);
int32_t inside(int32_t x, int32_t y, const sectortype* sectnum);
void dragpoint(int pointhighlight, int32_t dax, int32_t day);
int32_t try_facespr_intersect(uspriteptr_t const spr, vec3_t const in,
int32_t vx, int32_t vy, int32_t vz,
@ -380,9 +380,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)));
int findwallbetweensectors(int sect1, int sect2);
inline int sectoradjacent(int sect1, int sect2) { return findwallbetweensectors(sect1, sect2) != -1; }
int32_t getsectordist(vec2_t const in, int const sectnum, vec2_t * const out = nullptr);
extern const int16_t *chsecptr_onextwall;
@ -556,9 +553,9 @@ extern int skiptile;
static vec2_t const zerovec = { 0, 0 };
inline int inside_p(int32_t const x, int32_t const y, int const sectnum) { return (sectnum >= 0 && inside(x, y, sectnum) == 1); }
inline int inside_p(int32_t const x, int32_t const y, int const sectnum) { return (sectnum >= 0 && inside(x, y, &sector[sectnum]) == 1); }
// same as above but with the same signature as inside_z_p for passing to updatesectorneighborz.
inline int inside_p0(int32_t const x, int32_t const y, int32_t const z, int const sectnum) { return (sectnum >= 0 && inside(x, y, sectnum) == 1); }
inline int inside_p0(int32_t const x, int32_t const y, int32_t const z, int const sectnum) { return inside_p(x, y, sectnum); }
#define SET_AND_RETURN(Lval, Rval) \
do \

View file

@ -529,7 +529,7 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect,
// We're not interested in any sector reached by portal traversal that we're "inside" of.
if (enginecompatibility_mode == ENGINECOMPATIBILITY_NONE && !curspr && dasect != initialsectnum
&& inside(pos->x, pos->y, dasect) == 1)
&& inside(pos->x, pos->y, sec) == 1)
{
int k;
for (k=startwall; k<endwall; k++)
@ -706,7 +706,7 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect,
{
vec2_t const vec = pos->vec2;
keepaway(&pos->x, &pos->y, i);
if (inside(pos->x,pos->y, *sectnum) != 1)
if (inside_p(pos->x,pos->y, *sectnum) != 1)
pos->vec2 = vec;
break;
}
@ -779,7 +779,7 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect,
if (enginecompatibility_mode != ENGINECOMPATIBILITY_NONE)
{
for (int j=0; j<clipsectnum; j++)
if (inside(pos->x, pos->y, clipsectorlist[j]) == 1)
if (inside_p(pos->x, pos->y, clipsectorlist[j]) == 1)
{
*sectnum = clipsectorlist[j];
return clipReturn;
@ -788,7 +788,7 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect,
int32_t tempint2, tempint1 = INT32_MAX;
*sectnum = -1;
for (int j=numsectors-1; j>=0; j--)
if (inside(pos->x, pos->y, j) == 1)
if (inside_p(pos->x, pos->y, j) == 1)
{
if (enginecompatibility_mode != ENGINECOMPATIBILITY_19950829 && (sector[j].ceilingstat&2))
tempint2 = getceilzofslope(j, pos->x, pos->y) - pos->z;
@ -1234,7 +1234,7 @@ static int32_t hitscan_trysector(const vec3_t *sv, sectortype* sec, HitInfoBase
if ((x1 != INT32_MAX) && (abs(x1-sv->x)+abs(y1-sv->y) < abs((hit->hitpos.x)-sv->x)+abs((hit->hitpos.y)-sv->y)))
{
if (inside(x1,y1,sectnum(sec)) == 1)
if (inside(x1,y1,sec) == 1)
{
hit_set(hit, sec, nullptr, nullptr, x1, y1, z1);
hitscan_hitsectcf = (how+1)>>1;

View file

@ -443,21 +443,16 @@ int32_t engineInit(void)
// See http://fabiensanglard.net/duke3d/build_engine_internals.php,
// "Inside details" for the idea behind the algorithm.
int32_t inside(int32_t x, int32_t y, int sectnum)
int32_t inside(int32_t x, int32_t y, const sectortype* sect)
{
if (validSectorIndex(sectnum))
if (sect)
{
uint32_t cnt = 0;
auto wal = (uwallptr_t)sector[sectnum].firstWall();
int wallsleft = sector[sectnum].wallnum;
do
unsigned cnt = 0;
vec2_t xy = { x, y };
for(auto& wal : wallsofsector(sect))
{
// Get the x and y components of the [tested point]-->[wall
// point{1,2}] vectors.
vec2_t v1 = { wal->x - x, wal->y - y };
auto const &wal2 = *(uwallptr_t)wal->point2Wall();
vec2_t v2 = { wal2.x - x, wal2.y - y };
vec2_t v1 = wal.pos - xy;
vec2_t v2 = wal.point2Wall()->pos - xy;
// If their signs differ[*], ...
//
@ -467,14 +462,9 @@ int32_t inside(int32_t x, int32_t y, int sectnum)
// where y_m := min(y1, y2) and y_M := max(y1, y2).
if ((v1.y^v2.y) < 0)
cnt ^= (((v1.x^v2.x) >= 0) ? v1.x : (v1.x*v2.y-v2.x*v1.y)^v2.y);
wal++;
}
while (--wallsleft);
return cnt>>31;
}
return -1;
}
@ -854,22 +844,6 @@ int32_t getsectordist(vec2_t const in, int const sectnum, vec2_t * const out /*=
return distance;
}
int findwallbetweensectors(int sect1, int sect2)
{
if (sector[sect1].wallnum > sector[sect2].wallnum)
std::swap(sect1, sect2);
auto const sec = (usectorptr_t)&sector[sect1];
int const last = sec->wallptr + sec->wallnum;
for (int i = sec->wallptr; i < last; i++)
if (wall[i].nextsector == sect2)
return i;
return -1;
}
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)