mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
2.2 sight checks backport
This commit is contained in:
parent
1cbb4bea6b
commit
04b443d58c
1 changed files with 142 additions and 19 deletions
161
src/p_sight.c
161
src/p_sight.c
|
|
@ -2,7 +2,7 @@
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Copyright (C) 1993-1996 by id Software, Inc.
|
// Copyright (C) 1993-1996 by id Software, Inc.
|
||||||
// Copyright (C) 1998-2000 by DooM Legacy Team.
|
// Copyright (C) 1998-2000 by DooM Legacy Team.
|
||||||
// Copyright (C) 1999-2018 by Sonic Team Junior.
|
// Copyright (C) 1999-2020 by Sonic Team Junior.
|
||||||
//
|
//
|
||||||
// This program is free software distributed under the
|
// This program is free software distributed under the
|
||||||
// terms of the GNU General Public License, version 2.
|
// terms of the GNU General Public License, version 2.
|
||||||
|
|
@ -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"
|
||||||
|
|
||||||
|
|
@ -103,12 +104,20 @@ static fixed_t P_InterceptVector2(divline_t *v2, divline_t *v1)
|
||||||
static boolean P_CrossSubsecPolyObj(polyobj_t *po, register los_t *los)
|
static boolean P_CrossSubsecPolyObj(polyobj_t *po, register los_t *los)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
sector_t *polysec;
|
||||||
|
|
||||||
|
if (!(po->flags & POF_RENDERALL))
|
||||||
|
return true; // the polyobject isn't visible, so we can ignore it
|
||||||
|
|
||||||
|
polysec = po->lines[0]->backsector;
|
||||||
|
|
||||||
for (i = 0; i < po->numLines; ++i)
|
for (i = 0; i < po->numLines; ++i)
|
||||||
{
|
{
|
||||||
line_t *line = po->lines[i];
|
line_t *line = po->lines[i];
|
||||||
divline_t divl;
|
divline_t divl;
|
||||||
const vertex_t *v1,*v2;
|
const vertex_t *v1,*v2;
|
||||||
|
fixed_t frac;
|
||||||
|
fixed_t topslope, bottomslope;
|
||||||
|
|
||||||
// already checked other side?
|
// already checked other side?
|
||||||
if (line->validcount == validcount)
|
if (line->validcount == validcount)
|
||||||
|
|
@ -140,7 +149,22 @@ static boolean P_CrossSubsecPolyObj(polyobj_t *po, register los_t *los)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// stop because it is not two sided
|
// stop because it is not two sided
|
||||||
return false;
|
//if (!(po->flags & POF_TESTHEIGHT))
|
||||||
|
//return false;
|
||||||
|
|
||||||
|
frac = P_InterceptVector2(&los->strace, &divl);
|
||||||
|
|
||||||
|
// get slopes of top and bottom of this polyobject line
|
||||||
|
topslope = FixedDiv(polysec->ceilingheight - los->sightzstart , frac);
|
||||||
|
bottomslope = FixedDiv(polysec->floorheight - los->sightzstart , frac);
|
||||||
|
|
||||||
|
if (topslope >= los->topslope && bottomslope <= los->bottomslope)
|
||||||
|
return false; // view completely blocked
|
||||||
|
|
||||||
|
// TODO: figure out if it's worth considering partially blocked cases or not?
|
||||||
|
// maybe to adjust los's top/bottom slopes if needed
|
||||||
|
//if (los->topslope <= los->bottomslope)
|
||||||
|
//return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -193,6 +217,15 @@ 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
|
||||||
|
|
||||||
|
/* SRB2Kart doesn't have this?
|
||||||
|
if (seg->glseg)
|
||||||
|
continue;
|
||||||
|
*/
|
||||||
|
|
||||||
// already checked other side?
|
// already checked other side?
|
||||||
if (line->validcount == validcount)
|
if (line->validcount == validcount)
|
||||||
|
|
@ -227,36 +260,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)
|
|
||||||
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)
|
||||||
|
|
@ -265,6 +313,58 @@ static boolean P_CrossSubsector(size_t num, register los_t *los)
|
||||||
|
|
||||||
if (los->topslope <= los->bottomslope)
|
if (los->topslope <= los->bottomslope)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// Monster Iestyn: check FOFs!
|
||||||
|
if (front->ffloors || back->ffloors)
|
||||||
|
{
|
||||||
|
ffloor_t *rover;
|
||||||
|
fixed_t topslope, bottomslope;
|
||||||
|
fixed_t topz, bottomz;
|
||||||
|
// check front sector's FOFs first
|
||||||
|
for (rover = front->ffloors; rover; rover = rover->next)
|
||||||
|
{
|
||||||
|
if (!(rover->flags & FF_EXISTS)
|
||||||
|
|| !(rover->flags & FF_RENDERSIDES) || rover->flags & FF_TRANSLUCENT)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
#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)
|
||||||
|
return false; // view completely blocked
|
||||||
|
}
|
||||||
|
// check back sector's FOFs as well
|
||||||
|
for (rover = back->ffloors; rover; rover = rover->next)
|
||||||
|
{
|
||||||
|
if (!(rover->flags & FF_EXISTS)
|
||||||
|
|| !(rover->flags & FF_RENDERSIDES) || rover->flags & FF_TRANSLUCENT)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
#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)
|
||||||
|
return false; // view completely blocked
|
||||||
|
}
|
||||||
|
// TODO: figure out if it's worth considering partially blocked cases or not?
|
||||||
|
// maybe to adjust los's top/bottom slopes if needed
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// passed the subsector ok
|
// passed the subsector ok
|
||||||
|
|
@ -375,6 +475,8 @@ boolean P_CheckSight(mobj_t *t1, mobj_t *t2)
|
||||||
if (s1 == s2) // Both sectors are the same.
|
if (s1 == s2) // Both sectors are the same.
|
||||||
{
|
{
|
||||||
ffloor_t *rover;
|
ffloor_t *rover;
|
||||||
|
fixed_t topz1, bottomz1; // top, bottom heights at t1's position
|
||||||
|
fixed_t topz2, bottomz2; // likewise but for t2
|
||||||
|
|
||||||
for (rover = s1->ffloors; rover; rover = rover->next)
|
for (rover = s1->ffloors; rover; rover = rover->next)
|
||||||
{
|
{
|
||||||
|
|
@ -387,9 +489,30 @@ boolean P_CheckSight(mobj_t *t1, mobj_t *t2)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ESLOPE
|
||||||
|
if (*rover->t_slope)
|
||||||
|
{
|
||||||
|
topz1 = P_GetZAt(*rover->t_slope, t1->x, t1->y);
|
||||||
|
topz2 = P_GetZAt(*rover->t_slope, t2->x, t2->y);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
topz1 = topz2 = *rover->topheight;
|
||||||
|
|
||||||
|
if (*rover->b_slope)
|
||||||
|
{
|
||||||
|
bottomz1 = P_GetZAt(*rover->b_slope, t1->x, t1->y);
|
||||||
|
bottomz2 = P_GetZAt(*rover->b_slope, t2->x, t2->y);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
bottomz1 = bottomz2 = *rover->bottomheight;
|
||||||
|
#else
|
||||||
|
topz1 = topz2 = *rover->topheight;
|
||||||
|
bottomz1 = bottomz2 = *rover->bottomheight;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Check for blocking floors here.
|
// Check for blocking floors here.
|
||||||
if ((los.sightzstart < *rover->bottomheight && t2->z >= *rover->topheight)
|
if ((los.sightzstart < bottomz1 && t2->z >= topz2)
|
||||||
|| (los.sightzstart >= *rover->topheight && t2->z + t2->height < *rover->bottomheight))
|
|| (los.sightzstart >= topz1 && t2->z + t2->height < bottomz2))
|
||||||
{
|
{
|
||||||
// no way to see through that
|
// no way to see through that
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -400,19 +523,19 @@ boolean P_CheckSight(mobj_t *t1, mobj_t *t2)
|
||||||
|
|
||||||
if (!(rover->flags & FF_INVERTPLANES))
|
if (!(rover->flags & FF_INVERTPLANES))
|
||||||
{
|
{
|
||||||
if (los.sightzstart >= *rover->topheight && t2->z + t2->height < *rover->topheight)
|
if (los.sightzstart >= topz1 && t2->z + t2->height < topz2)
|
||||||
return false; // blocked by upper outside plane
|
return false; // blocked by upper outside plane
|
||||||
|
|
||||||
if (los.sightzstart < *rover->bottomheight && t2->z >= *rover->bottomheight)
|
if (los.sightzstart < bottomz1 && t2->z >= bottomz2)
|
||||||
return false; // blocked by lower outside plane
|
return false; // blocked by lower outside plane
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rover->flags & FF_INVERTPLANES || rover->flags & FF_BOTHPLANES)
|
if (rover->flags & FF_INVERTPLANES || rover->flags & FF_BOTHPLANES)
|
||||||
{
|
{
|
||||||
if (los.sightzstart < *rover->topheight && t2->z >= *rover->topheight)
|
if (los.sightzstart < topz1 && t2->z >= topz2)
|
||||||
return false; // blocked by upper inside plane
|
return false; // blocked by upper inside plane
|
||||||
|
|
||||||
if (los.sightzstart >= *rover->bottomheight && t2->z + t2->height < *rover->bottomheight)
|
if (los.sightzstart >= bottomz1 && t2->z + t2->height < bottomz2)
|
||||||
return false; // blocked by lower inside plane
|
return false; // blocked by lower inside plane
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue