Commit 2609d8cb authored by nukeykt's avatar nukeykt Committed by Richard Gobeille

Engine: Check all TROR layers in collision code

parent 54671115
......@@ -15,9 +15,10 @@
static int16_t clipnum;
static linetype clipit[MAXCLIPNUM];
static int32_t clipsectnum, origclipsectnum, clipspritenum;
static int32_t clipsectnum, origclipsectnum, layerclipsectnum, clipspritenum;
int16_t clipsectorlist[MAXCLIPSECTORS];
static int16_t origclipsectorlist[MAXCLIPSECTORS];
static int16_t layerclipsectorlist[MAXCLIPSECTORS];
static uint8_t clipsectormap[(MAXSECTORS+7)>>3];
static uint8_t origclipsectormap[(MAXSECTORS+7)>>3];
#ifdef HAVE_CLIPSHAPE_FEATURE
......@@ -1827,6 +1828,7 @@ void getzrange(const vec3_t *pos, int16_t sectnum,
int32_t clipsectcnt = 0;
#ifdef YAX_ENABLE
const int16_t origsectnum = sectnum;
// YAX round, -1:center, 0:ceiling, 1:floor
int32_t mcf=-1;
#endif
......@@ -1857,6 +1859,8 @@ void getzrange(const vec3_t *pos, int16_t sectnum,
#ifdef YAX_ENABLE
origclipsectorlist[0] = sectnum;
origclipsectnum = 1;
layerclipsectorlist[0] = sectnum;
layerclipsectnum = 1;
#endif
clipsectorlist[0] = sectnum;
clipsectnum = 1;
......@@ -1993,6 +1997,8 @@ restart_grand:
#ifdef YAX_ENABLE
if (mcf==-1 && curspr==NULL)
origclipsectorlist[origclipsectnum++] = k;
if (curspr == NULL)
layerclipsectorlist[layerclipsectnum++] = k;
#endif
//It actually got here, through all the continue's!!!
int32_t daz, daz2;
......@@ -2173,25 +2179,29 @@ restart_grand:
yax_getbunches(sectnum, &cb, &fb);
mcf++;
if (mcf == -1)
mcf = 0;
clipsectcnt = 0; clipsectnum = 0;
int didchange = 0;
int newsectnum = sectnum;
int mcfchange = 0;
if (cb>=0 && mcf==0 && *ceilhit==sectnum+16384)
{
int i;
for (i=0; i<origclipsectnum; i++)
for (i=0; i<layerclipsectnum; i++)
{
int const j = origclipsectorlist[i];
int const j = layerclipsectorlist[i];
if (yax_getbunch(j, YAX_CEILING) >= 0)
if (sector[j].ceilingstat&dasecclipmask)
break;
}
if (i==origclipsectnum)
for (i=0; i<origclipsectnum; i++)
if (i==layerclipsectnum)
for (i=0; i<layerclipsectnum; i++)
{
cb = yax_getbunch(origclipsectorlist[i], YAX_CEILING);
cb = yax_getbunch(layerclipsectorlist[i], YAX_CEILING);
if (cb < 0)
continue;
......@@ -2206,33 +2216,48 @@ restart_grand:
int const daz = getceilzofslope(j, closest.x, closest.y);
if (!didchange || daz > *ceilz)
didchange=1, *ceilhit = j+16384, *ceilz = daz;
didchange=1, *ceilhit = j+16384, *ceilz = daz, newsectnum = j;
}
}
if (clipsectnum==0)
{
mcfchange = 1;
mcf++;
}
}
else if (mcf==0)
{
mcfchange = 1;
mcf++;
}
if (mcfchange)
{
layerclipsectnum = origclipsectnum;
std::copy(origclipsectorlist, origclipsectorlist + origclipsectnum, layerclipsectorlist);
sectnum = origsectnum;
yax_getbunches(sectnum, &cb, &fb);
}
didchange = 0;
if (fb>=0 && mcf==1 && *florhit==sectnum+16384)
{
int i=0;
for (; i<origclipsectnum; i++)
for (; i<layerclipsectnum; i++)
{
int const j = origclipsectorlist[i];
int const j = layerclipsectorlist[i];
if (yax_getbunch(j, YAX_FLOOR) >= 0)
if (sector[j].floorstat&dasecclipmask)
break;
}
// (almost) same as above, but with floors...
if (i==origclipsectnum)
for (i=0; i<origclipsectnum; i++)
if (i==layerclipsectnum)
for (i=0; i<layerclipsectnum; i++)
{
fb = yax_getbunch(origclipsectorlist[i], YAX_FLOOR);
fb = yax_getbunch(layerclipsectorlist[i], YAX_FLOOR);
if (fb < 0)
continue;
......@@ -2247,7 +2272,7 @@ restart_grand:
int const daz = getflorzofslope(j, closest.x,closest.y);
if (!didchange || daz < *florz)
didchange=1, *florhit = j+16384, *florz = daz;
didchange=1, *florhit = j+16384, *florz = daz, newsectnum = j;
}
}
}
......@@ -2259,6 +2284,10 @@ restart_grand:
curspr = NULL;
clipspritecnt = 0; clipspritenum = 0;
layerclipsectnum = clipsectnum;
std::copy(clipsectorlist, clipsectorlist + clipsectnum, layerclipsectorlist);
sectnum = newsectnum;
goto restart_grand;
}
}
......
......@@ -12228,23 +12228,41 @@ void updatesectorz(int32_t const x, int32_t const y, int32_t const z, int16_t *
nofirstzcheck = 1;
}
#ifdef YAX_ENABLE
int mcf = -1;
restart:
#endif
// this block used to be outside the "if" and caused crashes in Polymost Mapster32
int32_t cz, fz;
getzsofslope(*sectnum, x, y, &cz, &fz);
#ifdef YAX_ENABLE
if (z < cz)
if ((mcf == -1 || mcf == YAX_CEILING) && z < cz)
{
int const next = yax_getneighborsect(x, y, *sectnum, YAX_CEILING);
if (next >= 0 && z >= getceilzofslope(next, x, y))
SET_AND_RETURN(*sectnum, next);
if (next >= 0)
{
if (z >= getceilzofslope(next, x, y))
SET_AND_RETURN(*sectnum, next);
*sectnum = next;
mcf = YAX_CEILING;
goto restart;
}
}
if (z > fz)
if ((mcf == -1 || mcf == YAX_FLOOR) && z > fz)
{
int const next = yax_getneighborsect(x, y, *sectnum, YAX_FLOOR);
if (next >= 0 && z <= getflorzofslope(next, x, y))
SET_AND_RETURN(*sectnum, next);
if (next >= 0)
{
if (z <= getflorzofslope(next, x, y))
SET_AND_RETURN(*sectnum, next);
*sectnum = next;
mcf = YAX_FLOOR;
goto restart;
}
}
#endif
if (nofirstzcheck || (z >= cz && z <= fz))
......@@ -12320,26 +12338,43 @@ void updatesectorneighborz(int32_t const x, int32_t const y, int32_t const z, in
nofirstzcheck = true;
}
#ifdef YAX_ENABLE
int mcf = -1;
restart:
#endif
uint32_t const correctedsectnum = (unsigned)*sectnum;
if (correctedsectnum < (unsigned)numsectors && getsectordist({x, y}, correctedsectnum) <= initialMaxDistance)
{
int32_t cz, fz;
getzsofslope(correctedsectnum, x, y, &cz, &fz);
#ifdef YAX_ENABLE
if (z < cz)
if ((mcf == -1 || mcf == YAX_CEILING) && z < cz)
{
int const next = yax_getneighborsect(x, y, correctedsectnum, YAX_CEILING);
if (next >= 0 && z >= getceilzofslope(next, x, y))
SET_AND_RETURN(*sectnum, next);
if (next >= 0)
{
if (z >= getceilzofslope(next, x, y))
SET_AND_RETURN(*sectnum, next);
*sectnum = next;
mcf = YAX_CEILING;
goto restart;
}
}
if (z > fz)
if ((mcf == -1 || mcf == YAX_FLOOR) && z > fz)
{
int const next = yax_getneighborsect(x, y, correctedsectnum, YAX_FLOOR);
if (next >= 0 && z <= getflorzofslope(next, x, y))
SET_AND_RETURN(*sectnum, next);
if (next >= 0)
{
if (z <= getflorzofslope(next, x, y))
SET_AND_RETURN(*sectnum, next);
*sectnum = next;
mcf = YAX_FLOOR;
goto restart;
}
}
#endif
if ((nofirstzcheck || (z >= cz && z <= fz)) && inside_p(x, y, *sectnum))
......@@ -13045,10 +13080,14 @@ void yax_getzsofslope(int sectNum, int playerX, int playerY, int32_t *pCeilZ, in
int didCeiling = 0;
int didFloor = 0;
int testSector = 0;
int nextSector = 0;
if ((sector[sectNum].ceilingstat & 512) == 0)
{
testSector = yax_getneighborsect(playerX, playerY, sectNum, YAX_CEILING);
testSector = -1;
nextSector = sectNum;
while ((nextSector = yax_getneighborsect(playerX, playerY, nextSector, YAX_CEILING)) >= 0)
testSector = nextSector;
if (testSector >= 0)
{
......@@ -13060,7 +13099,10 @@ ceiling:
if ((sector[sectNum].floorstat & 512) == 0)
{
testSector = yax_getneighborsect(playerX, playerY, sectNum, YAX_FLOOR);
testSector = -1;
nextSector = sectNum;
while ((nextSector = yax_getneighborsect(playerX, playerY, nextSector, YAX_FLOOR)) >= 0)
testSector = nextSector;
if (testSector >= 0)
{
......@@ -13082,9 +13124,10 @@ int32_t yax_getceilzofslope(int const sectnum, vec2_t const vect)
{
if ((sector[sectnum].ceilingstat&512)==0)
{
int const nsect = yax_getneighborsect(vect.x, vect.y, sectnum, YAX_CEILING);
if (nsect >= 0)
return getcorrectceilzofslope(nsect, vect.x, vect.y);
int testsectnum = sectnum, nsect;
while ((nsect = yax_getneighborsect(vect.x, vect.y, testsectnum, YAX_CEILING)) >= 0)
testsectnum = nsect;
return getcorrectceilzofslope(testsectnum, vect.x, vect.y);
}
return getcorrectceilzofslope(sectnum, vect.x, vect.y);
......@@ -13094,9 +13137,10 @@ int32_t yax_getflorzofslope(int const sectnum, vec2_t const vect)
{
if ((sector[sectnum].floorstat&512)==0)
{
int const nsect = yax_getneighborsect(vect.x, vect.y, sectnum, YAX_FLOOR);
if (nsect >= 0)
return getcorrectflorzofslope(nsect, vect.x, vect.y);
int testsectnum = sectnum, nsect;
while ((nsect = yax_getneighborsect(vect.x, vect.y, testsectnum, YAX_FLOOR)) >= 0)
testsectnum = nsect;
return getcorrectflorzofslope(testsectnum, vect.x, vect.y);
}
return getcorrectflorzofslope(sectnum, vect.x, vect.y);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment