mirror of
https://github.com/DrBeef/Raze.git
synced 2025-01-31 13:10:39 +00:00
- 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:
parent
6d432fca0a
commit
838bed7800
10 changed files with 38 additions and 63 deletions
|
@ -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);
|
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);
|
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);
|
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 try_facespr_intersect(uspriteptr_t const spr, vec3_t const in,
|
||||||
int32_t vx, int32_t vy, int32_t vz,
|
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)));
|
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);
|
int32_t getsectordist(vec2_t const in, int const sectnum, vec2_t * const out = nullptr);
|
||||||
extern const int16_t *chsecptr_onextwall;
|
extern const int16_t *chsecptr_onextwall;
|
||||||
|
|
||||||
|
@ -556,9 +553,9 @@ extern int skiptile;
|
||||||
|
|
||||||
static vec2_t const zerovec = { 0, 0 };
|
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, §or[sectnum]) == 1); }
|
||||||
// same as above but with the same signature as inside_z_p for passing to updatesectorneighborz.
|
// 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) \
|
#define SET_AND_RETURN(Lval, Rval) \
|
||||||
do \
|
do \
|
||||||
|
|
|
@ -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.
|
// We're not interested in any sector reached by portal traversal that we're "inside" of.
|
||||||
if (enginecompatibility_mode == ENGINECOMPATIBILITY_NONE && !curspr && dasect != initialsectnum
|
if (enginecompatibility_mode == ENGINECOMPATIBILITY_NONE && !curspr && dasect != initialsectnum
|
||||||
&& inside(pos->x, pos->y, dasect) == 1)
|
&& inside(pos->x, pos->y, sec) == 1)
|
||||||
{
|
{
|
||||||
int k;
|
int k;
|
||||||
for (k=startwall; k<endwall; 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;
|
vec2_t const vec = pos->vec2;
|
||||||
keepaway(&pos->x, &pos->y, i);
|
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;
|
pos->vec2 = vec;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -779,7 +779,7 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect,
|
||||||
if (enginecompatibility_mode != ENGINECOMPATIBILITY_NONE)
|
if (enginecompatibility_mode != ENGINECOMPATIBILITY_NONE)
|
||||||
{
|
{
|
||||||
for (int j=0; j<clipsectnum; j++)
|
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];
|
*sectnum = clipsectorlist[j];
|
||||||
return clipReturn;
|
return clipReturn;
|
||||||
|
@ -788,7 +788,7 @@ CollisionBase clipmove_(vec3_t * const pos, int * const sectnum, int32_t xvect,
|
||||||
int32_t tempint2, tempint1 = INT32_MAX;
|
int32_t tempint2, tempint1 = INT32_MAX;
|
||||||
*sectnum = -1;
|
*sectnum = -1;
|
||||||
for (int j=numsectors-1; j>=0; j--)
|
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))
|
if (enginecompatibility_mode != ENGINECOMPATIBILITY_19950829 && (sector[j].ceilingstat&2))
|
||||||
tempint2 = getceilzofslope(j, pos->x, pos->y) - pos->z;
|
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 ((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);
|
hit_set(hit, sec, nullptr, nullptr, x1, y1, z1);
|
||||||
hitscan_hitsectcf = (how+1)>>1;
|
hitscan_hitsectcf = (how+1)>>1;
|
||||||
|
|
|
@ -443,21 +443,16 @@ int32_t engineInit(void)
|
||||||
// See http://fabiensanglard.net/duke3d/build_engine_internals.php,
|
// See http://fabiensanglard.net/duke3d/build_engine_internals.php,
|
||||||
// "Inside details" for the idea behind the algorithm.
|
// "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;
|
unsigned cnt = 0;
|
||||||
auto wal = (uwallptr_t)sector[sectnum].firstWall();
|
vec2_t xy = { x, y };
|
||||||
int wallsleft = sector[sectnum].wallnum;
|
for(auto& wal : wallsofsector(sect))
|
||||||
|
|
||||||
do
|
|
||||||
{
|
{
|
||||||
// Get the x and y components of the [tested point]-->[wall
|
vec2_t v1 = wal.pos - xy;
|
||||||
// point{1,2}] vectors.
|
vec2_t v2 = wal.point2Wall()->pos - xy;
|
||||||
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 };
|
|
||||||
|
|
||||||
// If their signs differ[*], ...
|
// 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).
|
// where y_m := min(y1, y2) and y_M := max(y1, y2).
|
||||||
if ((v1.y^v2.y) < 0)
|
if ((v1.y^v2.y) < 0)
|
||||||
cnt ^= (((v1.x^v2.x) >= 0) ? v1.x : (v1.x*v2.y-v2.x*v1.y)^v2.y);
|
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 cnt>>31;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -854,22 +844,6 @@ int32_t getsectordist(vec2_t const in, int const sectnum, vec2_t * const out /*=
|
||||||
return distance;
|
return distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
int findwallbetweensectors(int sect1, int sect2)
|
|
||||||
{
|
|
||||||
if (sector[sect1].wallnum > sector[sect2].wallnum)
|
|
||||||
std::swap(sect1, sect2);
|
|
||||||
|
|
||||||
auto const sec = (usectorptr_t)§or[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>
|
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)
|
void updatesectorneighborz(int32_t const x, int32_t const y, int32_t const z, int* const sectnum, int32_t maxDistance, Inside checker)
|
||||||
|
|
|
@ -300,6 +300,21 @@ void checkRotatedWalls()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
//
|
||||||
|
// check if two sectors share a wall connection
|
||||||
|
//
|
||||||
|
//==========================================================================
|
||||||
|
|
||||||
|
bool sectorsConnected(int sect1, int sect2)
|
||||||
|
{
|
||||||
|
for (auto& wal : wallsofsector(sect1))
|
||||||
|
{
|
||||||
|
if (wal.nextsector == sect2) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// vector serializers
|
// vector serializers
|
||||||
|
|
|
@ -128,6 +128,7 @@ void GetWallSpritePosition(const tspritetype* spr, vec2_t pos, vec2_t* out, bool
|
||||||
void GetFlatSpritePosition(const tspritetype* spr, vec2_t pos, vec2_t* out, bool render = false);
|
void GetFlatSpritePosition(const tspritetype* spr, vec2_t pos, vec2_t* out, bool render = false);
|
||||||
void GetFlatSpritePosition(const spritetype* spr, vec2_t pos, vec2_t* out, bool render = false);
|
void GetFlatSpritePosition(const spritetype* spr, vec2_t pos, vec2_t* out, bool render = false);
|
||||||
void checkRotatedWalls();
|
void checkRotatedWalls();
|
||||||
|
bool sectorsConnected(int sect1, int sect2);
|
||||||
|
|
||||||
// y is negated so that the orientation is the same as in GZDoom, in order to use its utilities.
|
// y is negated so that the orientation is the same as in GZDoom, in order to use its utilities.
|
||||||
// The render code should NOT use Build coordinates for anything!
|
// The render code should NOT use Build coordinates for anything!
|
||||||
|
@ -319,11 +320,6 @@ inline double SquareDistToWall(double px, double py, const walltype* wal)
|
||||||
return SquareDist(px, py, lx1 + t * (lx2 - lx1), ly1 + t * (ly2 - ly1));
|
return SquareDist(px, py, lx1 + t * (lx2 - lx1), ly1 + t * (ly2 - ly1));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int inside(int x, int y, sectortype* sect)
|
|
||||||
{
|
|
||||||
return inside(x, y, sectnum(sect));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void dragpoint(walltype* pointhighlight, int32_t dax, int32_t day)
|
inline void dragpoint(walltype* pointhighlight, int32_t dax, int32_t day)
|
||||||
{
|
{
|
||||||
dragpoint(wallnum(pointhighlight), dax, day);
|
dragpoint(wallnum(pointhighlight), dax, day);
|
||||||
|
@ -344,10 +340,3 @@ inline void updatesectorneighbor(int32_t const x, int32_t const y, sectortype* *
|
||||||
updatesectorneighbor(x, y, §no, maxDistance);
|
updatesectorneighbor(x, y, §no, maxDistance);
|
||||||
*sect = sectno < 0? nullptr : §or[sectno];
|
*sect = sectno < 0? nullptr : §or[sectno];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline int findwallbetweensectors(sectortype* sect1, sectortype* sect2)
|
|
||||||
{
|
|
||||||
return findwallbetweensectors(sectnum(sect1), sectnum(sect2));
|
|
||||||
}
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ void hw_BuildSections()
|
||||||
{
|
{
|
||||||
// Fix maps which do not set their wallptr to the first wall. Lo Wang In Time's map 11 is such a case.
|
// Fix maps which do not set their wallptr to the first wall. Lo Wang In Time's map 11 is such a case.
|
||||||
int wp = sector[i].wallptr;
|
int wp = sector[i].wallptr;
|
||||||
while (wp > 0 && wall[wp - 1].nextwall >= 0 && wall[wall[wp - 1].nextwall].nextsector == i)
|
while (wp > 0 && wall[wp - 1].nextwall >= 0 && wall[wp - 1].nextWall()->nextsector == i)
|
||||||
{
|
{
|
||||||
sector[i].wallptr--;
|
sector[i].wallptr--;
|
||||||
sector[i].wallnum++;
|
sector[i].wallnum++;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "build.h"
|
#include "build.h"
|
||||||
|
#include "gamefuncs.h"
|
||||||
|
|
||||||
class FSerializer;
|
class FSerializer;
|
||||||
struct IntRect;
|
struct IntRect;
|
||||||
|
@ -56,7 +57,7 @@ inline void mergePortals()
|
||||||
{
|
{
|
||||||
for (unsigned t = 0; t < pt2.targets.Size(); t++)
|
for (unsigned t = 0; t < pt2.targets.Size(); t++)
|
||||||
{
|
{
|
||||||
if (findwallbetweensectors(pt1.targets[s], pt2.targets[t]) >= 0)
|
if (sectorsConnected(pt1.targets[s], pt2.targets[t]))
|
||||||
{
|
{
|
||||||
pt1.targets.Append(pt2.targets);
|
pt1.targets.Append(pt2.targets);
|
||||||
pt2.targets.Reset();
|
pt2.targets.Reset();
|
||||||
|
|
|
@ -54,7 +54,7 @@ static FVector3 CalcNormal(sectortype* sector, int plane)
|
||||||
{
|
{
|
||||||
FVector3 pt[3];
|
FVector3 pt[3];
|
||||||
|
|
||||||
auto wal = &wall[sector->wallptr];
|
auto wal = sector->firstWall();
|
||||||
auto wal2 = wal->point2Wall();
|
auto wal2 = wal->point2Wall();
|
||||||
|
|
||||||
pt[0] = { (float)WallStartX(wal), (float)WallStartY(wal), 0 };
|
pt[0] = { (float)WallStartX(wal), (float)WallStartY(wal), 0 };
|
||||||
|
|
|
@ -892,7 +892,7 @@ static void SpawnPortals()
|
||||||
{
|
{
|
||||||
for (auto& t : pt.targets)
|
for (auto& t : pt.targets)
|
||||||
{
|
{
|
||||||
if (findwallbetweensectors(i, t) >= 0)
|
if (sectorsConnected(i, t))
|
||||||
{
|
{
|
||||||
sectp->portalflags = PORTAL_SECTOR_FLOOR;
|
sectp->portalflags = PORTAL_SECTOR_FLOOR;
|
||||||
sectp->portalnum = uint8_t(1 ^ (&pt - allPortals.Data()));
|
sectp->portalnum = uint8_t(1 ^ (&pt - allPortals.Data()));
|
||||||
|
@ -909,9 +909,9 @@ static void SpawnPortals()
|
||||||
{
|
{
|
||||||
if (pt.type == PORTAL_SECTOR_FLOOR)
|
if (pt.type == PORTAL_SECTOR_FLOOR)
|
||||||
{
|
{
|
||||||
for (auto& t : pt.targets)
|
for (auto t : pt.targets)
|
||||||
{
|
{
|
||||||
if (findwallbetweensectors(i, t) >= 0)
|
if (sectorsConnected(i, t))
|
||||||
{
|
{
|
||||||
sectp->portalflags = PORTAL_SECTOR_CEILING;
|
sectp->portalflags = PORTAL_SECTOR_CEILING;
|
||||||
sectp->portalnum = uint8_t(1 ^ (&pt - allPortals.Data()));
|
sectp->portalnum = uint8_t(1 ^ (&pt - allPortals.Data()));
|
||||||
|
|
|
@ -1021,7 +1021,6 @@ void MoveSector(sectortype* pSector, int nAngle, int *nXVel, int *nYVel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int nNextSector = sectnum(pNextSector);
|
|
||||||
it.Reset(pNextSector);
|
it.Reset(pNextSector);
|
||||||
while (auto pActor = it.Next())
|
while (auto pActor = it.Next())
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue