Fixed P_CheckSight to support slopes, both for normal planes and FOF planes

(Untested)
This commit is contained in:
Monster Iestyn 2019-05-27 20:36:35 +01:00
parent ad4006712e
commit abfdac15a8
1 changed files with 52 additions and 16 deletions

View File

@ -14,6 +14,7 @@
#include "doomdef.h" #include "doomdef.h"
#include "doomstat.h" #include "doomstat.h"
#include "p_local.h" #include "p_local.h"
#include "p_slopes.h"
#include "r_main.h" #include "r_main.h"
#include "r_state.h" #include "r_state.h"
@ -216,6 +217,10 @@ static boolean P_CrossSubsector(size_t num, register los_t *los)
const sector_t *front, *back; const sector_t *front, *back;
const vertex_t *v1,*v2; const vertex_t *v1,*v2;
fixed_t frac; fixed_t frac;
fixed_t frontf, backf, frontc, backc;
#ifdef ESLOPE
fixed_t fracx, fracy;
#endif
// already checked other side? // already checked other side?
if (line->validcount == validcount) if (line->validcount == validcount)
@ -250,37 +255,51 @@ static boolean P_CrossSubsector(size_t num, register los_t *los)
if (!(line->flags & ML_TWOSIDED)) if (!(line->flags & ML_TWOSIDED))
return false; return false;
// calculate fractional intercept (how far along we are divided by how far we are from t2)
frac = P_InterceptVector2(&los->strace, &divl);
front = seg->frontsector;
back = seg->backsector;
#ifdef ESLOPE
// calculate position at intercept
fracx = los->strace.x + FixedMul(los->strace.dx, frac);
fracy = los->strace.y + FixedMul(los->strace.dy, frac);
// calculate sector heights
frontf = (front->f_slope) ? P_GetZAt(front->f_slope, fracx, fracy) : front->floorheight;
frontc = (front->c_slope) ? P_GetZAt(front->c_slope, fracx, fracy) : front->ceilingheight;
backf = (back->f_slope) ? P_GetZAt(back->f_slope, fracx, fracy) : back->floorheight;
backc = (back->c_slope) ? P_GetZAt(back->c_slope, fracx, fracy) : back->ceilingheight;
#else
frontf = front->floorheight;
frontc = front->ceilingheight;
backf = back->floorheight;
backc = back->ceilingheight;
#endif
// crosses a two sided line // crosses a two sided line
// no wall to block sight with? // no wall to block sight with?
if ((front = seg->frontsector)->floorheight == if (frontf == backf && frontc == backc
(back = seg->backsector)->floorheight && && !front->ffloors & !back->ffloors) // (and no FOFs)
front->ceilingheight == back->ceilingheight
&& !front->ffloors && !back->ffloors)
continue; continue;
// possible occluder // possible occluder
// because of ceiling height differences // because of ceiling height differences
popentop = front->ceilingheight < back->ceilingheight ? popentop = min(frontc, backc);
front->ceilingheight : back->ceilingheight ;
// because of floor height differences // because of floor height differences
popenbottom = front->floorheight > back->floorheight ? popenbottom = max(frontf, backf);
front->floorheight : back->floorheight ;
// quick test for totally closed doors // quick test for totally closed doors
if (popenbottom >= popentop) if (popenbottom >= popentop)
return false; return false;
frac = P_InterceptVector2(&los->strace, &divl); if (frontf != backf)
if (front->floorheight != back->floorheight)
{ {
fixed_t slope = FixedDiv(popenbottom - los->sightzstart , frac); fixed_t slope = FixedDiv(popenbottom - los->sightzstart , frac);
if (slope > los->bottomslope) if (slope > los->bottomslope)
los->bottomslope = slope; los->bottomslope = slope;
} }
if (front->ceilingheight != back->ceilingheight) if (frontc != backc)
{ {
fixed_t slope = FixedDiv(popentop - los->sightzstart , frac); fixed_t slope = FixedDiv(popentop - los->sightzstart , frac);
if (slope < los->topslope) if (slope < los->topslope)
@ -295,6 +314,7 @@ static boolean P_CrossSubsector(size_t num, register los_t *los)
{ {
ffloor_t *rover; ffloor_t *rover;
fixed_t topslope, bottomslope; fixed_t topslope, bottomslope;
fixed_t topz, bottomz;
// check front sector's FOFs first // check front sector's FOFs first
for (rover = front->ffloors; rover; rover = rover->next) for (rover = front->ffloors; rover; rover = rover->next)
{ {
@ -303,8 +323,16 @@ static boolean P_CrossSubsector(size_t num, register los_t *los)
{ {
continue; continue;
} }
topslope = FixedDiv(*rover->topheight - los->sightzstart , frac);
bottomslope = FixedDiv(*rover->bottomheight - los->sightzstart , frac); #ifdef ESLOPE
topz = (*rover->t_slope) ? P_GetZAt(*rover->t_slope, fracx, fracy) : *rover->topheight;
bottomz = (*rover->b_slope) ? P_GetZAt(*rover->b_slope, fracx, fracy) : *rover->bottomheight;
#else
topz = *rover->topheight;
bottomz = *rover->bottomheight;
#endif
topslope = FixedDiv(topz - los->sightzstart , frac);
bottomslope = FixedDiv(bottomz - los->sightzstart , frac);
if (topslope >= los->topslope && bottomslope <= los->bottomslope) if (topslope >= los->topslope && bottomslope <= los->bottomslope)
return false; // view completely blocked return false; // view completely blocked
} }
@ -316,8 +344,16 @@ static boolean P_CrossSubsector(size_t num, register los_t *los)
{ {
continue; continue;
} }
topslope = FixedDiv(*rover->topheight - los->sightzstart , frac);
bottomslope = FixedDiv(*rover->bottomheight - los->sightzstart , frac); #ifdef ESLOPE
topz = (*rover->t_slope) ? P_GetZAt(*rover->t_slope, fracx, fracy) : *rover->topheight;
bottomz = (*rover->b_slope) ? P_GetZAt(*rover->b_slope, fracx, fracy) : *rover->bottomheight;
#else
topz = *rover->topheight;
bottomz = *rover->bottomheight;
#endif
topslope = FixedDiv(topz - los->sightzstart , frac);
bottomslope = FixedDiv(bottomz - los->sightzstart , frac);
if (topslope >= los->topslope && bottomslope <= los->bottomslope) if (topslope >= los->topslope && bottomslope <= los->bottomslope)
return false; // view completely blocked return false; // view completely blocked
} }