2016-03-01 15:47:10 +00:00
|
|
|
/*
|
|
|
|
** p_trace.cpp
|
|
|
|
** Generalized trace function, like most 3D games have
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 1998-2006 Randy Heit
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "p_trace.h"
|
|
|
|
#include "p_local.h"
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "r_sky.h"
|
|
|
|
#include "doomstat.h"
|
|
|
|
#include "p_maputl.h"
|
|
|
|
#include "r_defs.h"
|
|
|
|
#include "p_spec.h"
|
2017-01-08 17:45:30 +00:00
|
|
|
#include "g_levellocals.h"
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
struct FTraceInfo
|
|
|
|
{
|
2016-03-30 14:30:22 +00:00
|
|
|
DVector3 Start;
|
|
|
|
DVector3 Vec;
|
2016-03-01 15:47:10 +00:00
|
|
|
ActorFlags ActorMask;
|
|
|
|
DWORD WallMask;
|
|
|
|
AActor *IgnoreThis;
|
|
|
|
FTraceResults *Results;
|
|
|
|
sector_t *CurSector;
|
2016-03-30 14:30:22 +00:00
|
|
|
double MaxDist;
|
|
|
|
double EnterDist;
|
2016-03-01 15:47:10 +00:00
|
|
|
ETraceStatus (*TraceCallback)(FTraceResults &res, void *data);
|
|
|
|
void *TraceCallbackData;
|
|
|
|
DWORD TraceFlags;
|
|
|
|
int inshootthrough;
|
2016-03-30 14:30:22 +00:00
|
|
|
double startfrac;
|
|
|
|
double limitz;
|
2016-04-16 17:41:33 +00:00
|
|
|
int ptflags;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
// These are required for 3D-floor checking
|
|
|
|
// to create a fake sector with a floor
|
|
|
|
// or ceiling plane coming from a 3D-floor
|
|
|
|
sector_t DummySector[2];
|
|
|
|
int sectorsel;
|
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
void Setup3DFloors();
|
2016-04-16 17:41:33 +00:00
|
|
|
bool LineCheck(intercept_t *in, double dist, DVector3 hit);
|
|
|
|
bool ThingCheck(intercept_t *in, double dist, DVector3 hit);
|
2016-03-01 15:47:10 +00:00
|
|
|
bool TraceTraverse (int ptflags);
|
|
|
|
bool CheckPlane(const secplane_t &plane);
|
2016-04-16 17:41:33 +00:00
|
|
|
void EnterLinePortal(FPathTraverse &pt, intercept_t *in);
|
|
|
|
void EnterSectorPortal(FPathTraverse &pt, int position, double frac, sector_t *entersec);
|
2016-03-05 20:44:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool CheckSectorPlane(const sector_t *sector, bool checkFloor)
|
|
|
|
{
|
|
|
|
return CheckPlane(checkFloor ? sector->floorplane : sector->ceilingplane);
|
|
|
|
}
|
|
|
|
|
2016-03-06 20:58:36 +00:00
|
|
|
bool Check3DFloorPlane(const F3DFloor *ffloor, bool checkBottom)
|
2016-03-05 20:44:31 +00:00
|
|
|
{
|
|
|
|
return CheckPlane(checkBottom? *(ffloor->bottom.plane) : *(ffloor->top.plane));
|
|
|
|
}
|
|
|
|
|
2016-03-06 20:58:36 +00:00
|
|
|
void SetSourcePosition()
|
|
|
|
{
|
2016-03-30 14:30:22 +00:00
|
|
|
Results->SrcFromTarget = Start;
|
|
|
|
Results->HitVector = Vec;
|
2016-03-27 18:58:01 +00:00
|
|
|
Results->SrcAngleFromTarget = Results->HitVector.Angle();
|
2016-03-06 20:58:36 +00:00
|
|
|
}
|
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool EditTraceResult (DWORD flags, FTraceResults &res);
|
|
|
|
|
|
|
|
|
2016-04-16 17:41:33 +00:00
|
|
|
|
|
|
|
static void GetPortalTransition(DVector3 &pos, sector_t *&sec)
|
|
|
|
{
|
|
|
|
bool moved = false;
|
|
|
|
double testz = pos.Z;
|
|
|
|
|
|
|
|
while (!sec->PortalBlocksMovement(sector_t::ceiling))
|
|
|
|
{
|
2016-04-19 09:35:28 +00:00
|
|
|
if (pos.Z > sec->GetPortalPlaneZ(sector_t::ceiling))
|
2016-04-16 17:41:33 +00:00
|
|
|
{
|
2016-04-19 09:35:28 +00:00
|
|
|
pos += sec->GetPortalDisplacement(sector_t::ceiling);
|
2016-04-16 17:41:33 +00:00
|
|
|
sec = P_PointInSector(pos);
|
|
|
|
moved = true;
|
|
|
|
}
|
|
|
|
else break;
|
|
|
|
}
|
|
|
|
if (!moved)
|
|
|
|
{
|
|
|
|
while (!sec->PortalBlocksMovement(sector_t::floor))
|
|
|
|
{
|
2016-04-19 09:35:28 +00:00
|
|
|
if (pos.Z <= sec->GetPortalPlaneZ(sector_t::floor))
|
2016-04-16 17:41:33 +00:00
|
|
|
{
|
2016-04-19 09:35:28 +00:00
|
|
|
pos += sec->GetPortalDisplacement(sector_t::floor);
|
2016-04-16 17:41:33 +00:00
|
|
|
sec = P_PointInSector(pos);
|
|
|
|
}
|
|
|
|
else break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Trace entry point
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2016-03-30 14:30:22 +00:00
|
|
|
bool Trace(const DVector3 &start, sector_t *sector, const DVector3 &direction, double maxDist,
|
|
|
|
ActorFlags actorMask, DWORD wallMask, AActor *ignore, FTraceResults &res, DWORD flags,
|
|
|
|
ETraceStatus(*callback)(FTraceResults &res, void *), void *callbackdata)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
|
|
|
FTraceInfo inf;
|
2016-03-05 20:44:31 +00:00
|
|
|
FTraceResults tempResult;
|
|
|
|
|
|
|
|
memset(&tempResult, 0, sizeof(tempResult));
|
2016-03-23 17:07:04 +00:00
|
|
|
tempResult.Fraction = tempResult.Distance = NO_VALUE;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-30 14:30:22 +00:00
|
|
|
inf.Start = start;
|
2016-04-16 17:41:33 +00:00
|
|
|
GetPortalTransition(inf.Start, sector);
|
|
|
|
inf.ptflags = actorMask ? PT_ADDLINES|PT_ADDTHINGS|PT_COMPATIBLE : PT_ADDLINES;
|
2016-03-30 14:30:22 +00:00
|
|
|
inf.Vec = direction;
|
2016-03-01 15:47:10 +00:00
|
|
|
inf.ActorMask = actorMask;
|
|
|
|
inf.WallMask = wallMask;
|
|
|
|
inf.IgnoreThis = ignore;
|
|
|
|
inf.CurSector = sector;
|
|
|
|
inf.MaxDist = maxDist;
|
|
|
|
inf.EnterDist = 0;
|
|
|
|
inf.TraceCallback = callback;
|
|
|
|
inf.TraceCallbackData = callbackdata;
|
|
|
|
inf.TraceFlags = flags;
|
|
|
|
inf.Results = &res;
|
|
|
|
inf.inshootthrough = true;
|
|
|
|
inf.sectorsel=0;
|
2016-03-05 20:44:31 +00:00
|
|
|
inf.startfrac = 0;
|
2016-04-16 17:41:33 +00:00
|
|
|
inf.limitz = inf.Start.Z;
|
2016-03-01 15:47:10 +00:00
|
|
|
memset(&res, 0, sizeof(res));
|
|
|
|
|
2016-04-16 17:41:33 +00:00
|
|
|
if ((flags & TRACE_ReportPortals) && callback != NULL)
|
|
|
|
{
|
|
|
|
tempResult.HitType = TRACE_CrossingPortal;
|
|
|
|
tempResult.HitPos = tempResult.SrcFromTarget = inf.Start;
|
|
|
|
tempResult.HitVector = inf.Vec;
|
|
|
|
callback(tempResult, inf.TraceCallbackData);
|
|
|
|
}
|
|
|
|
bool reslt = inf.TraceTraverse(inf.ptflags);
|
|
|
|
|
|
|
|
if ((flags & TRACE_ReportPortals) && callback != NULL)
|
|
|
|
{
|
|
|
|
tempResult.HitType = TRACE_CrossingPortal;
|
|
|
|
tempResult.HitPos = tempResult.SrcFromTarget = inf.Results->HitPos;
|
|
|
|
tempResult.HitVector = inf.Vec;
|
|
|
|
callback(tempResult, inf.TraceCallbackData);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reslt)
|
2016-03-05 20:44:31 +00:00
|
|
|
{
|
2016-03-06 00:41:52 +00:00
|
|
|
return flags ? EditTraceResult(flags, res) : true;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// traverses a sector portal
|
|
|
|
//
|
|
|
|
//============================================================================
|
|
|
|
|
2016-04-16 17:41:33 +00:00
|
|
|
void FTraceInfo::EnterSectorPortal(FPathTraverse &pt, int position, double frac, sector_t *entersec)
|
2016-03-05 20:44:31 +00:00
|
|
|
{
|
2016-04-19 09:35:28 +00:00
|
|
|
DVector2 displacement = entersec->GetPortalDisplacement(position);;
|
2016-04-16 17:41:33 +00:00
|
|
|
double enterdist = MaxDist * frac;
|
|
|
|
DVector3 exit = Start + enterdist * Vec;
|
2016-04-19 09:35:28 +00:00
|
|
|
DVector3 enter = exit + displacement;
|
2016-03-05 20:44:31 +00:00
|
|
|
|
2016-04-19 09:35:28 +00:00
|
|
|
Start += displacement;
|
2016-04-16 17:41:33 +00:00
|
|
|
CurSector = P_PointInSector(enter);
|
|
|
|
inshootthrough = true;
|
|
|
|
startfrac = frac;
|
|
|
|
EnterDist = enterdist;
|
2016-04-20 17:20:11 +00:00
|
|
|
pt.PortalRelocate(entersec->GetPortal(position)->mDisplacement, ptflags, frac);
|
2016-03-05 20:44:31 +00:00
|
|
|
|
2016-04-16 17:41:33 +00:00
|
|
|
if ((TraceFlags & TRACE_ReportPortals) && TraceCallback != NULL)
|
2016-03-05 20:44:31 +00:00
|
|
|
{
|
2016-04-16 17:41:33 +00:00
|
|
|
enterdist = MaxDist * frac;
|
|
|
|
Results->HitType = TRACE_CrossingPortal;
|
|
|
|
Results->HitPos = exit;
|
|
|
|
Results->SrcFromTarget = enter;
|
|
|
|
Results->HitVector = Vec;
|
|
|
|
TraceCallback(*Results, TraceCallbackData);
|
2016-03-05 20:44:31 +00:00
|
|
|
}
|
2016-04-16 17:41:33 +00:00
|
|
|
|
|
|
|
Setup3DFloors();
|
2016-03-05 20:44:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// traverses a line portal
|
|
|
|
//
|
|
|
|
//============================================================================
|
|
|
|
|
2016-04-16 17:41:33 +00:00
|
|
|
void FTraceInfo::EnterLinePortal(FPathTraverse &pt, intercept_t *in)
|
2016-03-05 20:44:31 +00:00
|
|
|
{
|
2016-04-16 17:41:33 +00:00
|
|
|
line_t *li = in->d.line;
|
2016-03-05 20:44:31 +00:00
|
|
|
FLinePortal *port = li->getPortal();
|
|
|
|
|
2016-04-16 17:41:33 +00:00
|
|
|
double frac = in->frac + EQUAL_EPSILON;
|
|
|
|
double enterdist = MaxDist * frac;
|
|
|
|
DVector3 exit = Start + MaxDist * in->frac * Vec;
|
2016-03-06 00:04:19 +00:00
|
|
|
|
2016-04-16 17:41:33 +00:00
|
|
|
P_TranslatePortalXY(li, Start.X, Start.Y);
|
|
|
|
P_TranslatePortalZ(li, Start.Z);
|
|
|
|
P_TranslatePortalVXVY(li, Vec.X, Vec.Y);
|
|
|
|
P_TranslatePortalZ(li, limitz);
|
2016-03-06 00:04:19 +00:00
|
|
|
|
2016-04-16 17:41:33 +00:00
|
|
|
CurSector = P_PointInSector(Start + enterdist * Vec);
|
|
|
|
EnterDist = enterdist;
|
|
|
|
inshootthrough = true;
|
|
|
|
startfrac = frac;
|
|
|
|
Results->unlinked |= (port->mType != PORTT_LINKED);
|
|
|
|
pt.PortalRelocate(in, ptflags);
|
2016-04-11 08:46:30 +00:00
|
|
|
|
|
|
|
if ((TraceFlags & TRACE_ReportPortals) && TraceCallback != NULL)
|
|
|
|
{
|
2016-04-16 17:41:33 +00:00
|
|
|
enterdist = MaxDist * in->frac;
|
2016-04-11 08:46:30 +00:00
|
|
|
Results->HitType = TRACE_CrossingPortal;
|
2016-04-16 17:41:33 +00:00
|
|
|
Results->HitPos = exit;
|
|
|
|
P_TranslatePortalXY(li, exit.X, exit.Y);
|
|
|
|
P_TranslatePortalZ(li, exit.Z);
|
|
|
|
Results->SrcFromTarget = exit;
|
|
|
|
Results->HitVector = Vec;
|
2016-04-11 08:46:30 +00:00
|
|
|
TraceCallback(*Results, TraceCallbackData);
|
|
|
|
}
|
2016-03-05 20:44:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Checks 3D floors at trace start and sets up related data
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void FTraceInfo::Setup3DFloors()
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-04 00:12:38 +00:00
|
|
|
TDeletingArray<F3DFloor*> &ff = CurSector->e->XFloor.ffloors;
|
|
|
|
|
|
|
|
if (ff.Size())
|
|
|
|
{
|
|
|
|
memcpy(&DummySector[0], CurSector, sizeof(sector_t));
|
|
|
|
CurSector = &DummySector[0];
|
|
|
|
sectorsel = 1;
|
|
|
|
|
2016-03-30 14:30:22 +00:00
|
|
|
double sdist = MaxDist * startfrac;
|
|
|
|
DVector3 pos = Start + Vec * sdist;
|
2016-03-04 00:12:38 +00:00
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
|
2016-03-30 14:30:22 +00:00
|
|
|
double bf = CurSector->floorplane.ZatPoint(pos);
|
|
|
|
double bc = CurSector->ceilingplane.ZatPoint(pos);
|
2016-03-04 00:12:38 +00:00
|
|
|
|
|
|
|
for (auto rover : ff)
|
|
|
|
{
|
|
|
|
if (!(rover->flags&FF_EXISTS))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (rover->flags&FF_SWIMMABLE && Results->Crossed3DWater == NULL)
|
|
|
|
{
|
|
|
|
if (Check3DFloorPlane(rover, false))
|
2016-03-05 20:44:31 +00:00
|
|
|
{
|
2016-08-14 18:52:13 +00:00
|
|
|
// only consider if the plane is above the actual floor.
|
|
|
|
if (rover->top.plane->ZatPoint(Results->HitPos) > bf)
|
|
|
|
{
|
|
|
|
Results->Crossed3DWater = rover;
|
|
|
|
Results->Crossed3DWaterPos = Results->HitPos;
|
|
|
|
Results->Distance = 0;
|
|
|
|
}
|
2016-03-05 20:44:31 +00:00
|
|
|
}
|
2016-03-04 00:12:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(rover->flags&FF_SHOOTTHROUGH))
|
|
|
|
{
|
2016-03-30 14:30:22 +00:00
|
|
|
double ff_bottom = rover->bottom.plane->ZatPoint(pos);
|
|
|
|
double ff_top = rover->top.plane->ZatPoint(pos);
|
2016-03-04 00:12:38 +00:00
|
|
|
// clip to the part of the sector we are in
|
2016-03-30 14:30:22 +00:00
|
|
|
if (pos.Z > ff_top)
|
2016-03-04 00:12:38 +00:00
|
|
|
{
|
|
|
|
// above
|
2016-03-05 20:44:31 +00:00
|
|
|
if (bf < ff_top)
|
2016-03-04 00:12:38 +00:00
|
|
|
{
|
|
|
|
CurSector->floorplane = *rover->top.plane;
|
|
|
|
CurSector->SetTexture(sector_t::floor, *rover->top.texture, false);
|
2016-04-20 17:20:11 +00:00
|
|
|
CurSector->ClearPortal(sector_t::floor);
|
2016-03-04 00:12:38 +00:00
|
|
|
bf = ff_top;
|
|
|
|
}
|
|
|
|
}
|
2016-03-30 14:30:22 +00:00
|
|
|
else if (pos.Z < ff_bottom)
|
2016-03-04 00:12:38 +00:00
|
|
|
{
|
|
|
|
//below
|
2016-03-05 20:44:31 +00:00
|
|
|
if (bc > ff_bottom)
|
2016-03-04 00:12:38 +00:00
|
|
|
{
|
|
|
|
CurSector->ceilingplane = *rover->bottom.plane;
|
|
|
|
CurSector->SetTexture(sector_t::ceiling, *rover->bottom.texture, false);
|
|
|
|
bc = ff_bottom;
|
2016-04-20 17:20:11 +00:00
|
|
|
CurSector->ClearPortal(sector_t::ceiling);
|
2016-03-04 00:12:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// inside
|
2016-03-05 20:44:31 +00:00
|
|
|
if (bf < ff_bottom)
|
2016-03-04 00:12:38 +00:00
|
|
|
{
|
|
|
|
CurSector->floorplane = *rover->bottom.plane;
|
|
|
|
CurSector->SetTexture(sector_t::floor, *rover->bottom.texture, false);
|
2016-04-20 17:20:11 +00:00
|
|
|
CurSector->ClearPortal(sector_t::floor);
|
2016-03-04 00:12:38 +00:00
|
|
|
bf = ff_bottom;
|
|
|
|
}
|
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
if (bc > ff_top)
|
2016-03-04 00:12:38 +00:00
|
|
|
{
|
|
|
|
CurSector->ceilingplane = *rover->top.plane;
|
|
|
|
CurSector->SetTexture(sector_t::ceiling, *rover->top.texture, false);
|
2016-04-20 17:20:11 +00:00
|
|
|
CurSector->ClearPortal(sector_t::ceiling);
|
2016-03-04 00:12:38 +00:00
|
|
|
bc = ff_top;
|
|
|
|
}
|
|
|
|
inshootthrough = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-05 20:44:31 +00:00
|
|
|
}
|
2016-03-04 00:12:38 +00:00
|
|
|
|
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Processes one line intercept
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-04-16 17:41:33 +00:00
|
|
|
bool FTraceInfo::LineCheck(intercept_t *in, double dist, DVector3 hit)
|
2016-03-05 20:44:31 +00:00
|
|
|
{
|
|
|
|
int lineside;
|
|
|
|
sector_t *entersector;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-30 14:30:22 +00:00
|
|
|
double ff, fc, bf = 0, bc = 0;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
if (in->d.line->frontsector->sectornum == CurSector->sectornum)
|
|
|
|
{
|
|
|
|
lineside = 0;
|
|
|
|
}
|
|
|
|
else if (in->d.line->backsector && in->d.line->backsector->sectornum == CurSector->sectornum)
|
|
|
|
{
|
|
|
|
lineside = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // Dammit. Why does Doom have to allow non-closed sectors?
|
|
|
|
if (in->d.line->backsector == NULL)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-05 20:44:31 +00:00
|
|
|
lineside = 0;
|
|
|
|
CurSector = in->d.line->frontsector;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-30 14:30:22 +00:00
|
|
|
lineside = P_PointOnLineSide(Start, in->d.line);
|
2016-03-05 20:44:31 +00:00
|
|
|
CurSector = lineside ? in->d.line->backsector : in->d.line->frontsector;
|
|
|
|
}
|
|
|
|
}
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
if (!(in->d.line->flags & ML_TWOSIDED))
|
|
|
|
{
|
|
|
|
entersector = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
entersector = (lineside == 0) ? in->d.line->backsector : in->d.line->frontsector;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
// For backwards compatibility: Ignore lines with the same sector on both sides.
|
|
|
|
// This is the way Doom.exe did it and some WADs (e.g. Alien Vendetta MAP15) need it.
|
|
|
|
if (i_compatflags & COMPATF_TRACE && in->d.line->backsector == in->d.line->frontsector)
|
|
|
|
{
|
|
|
|
// We must check special activation here because the code below is never reached.
|
|
|
|
if (TraceFlags & TRACE_PCross)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-05 20:44:31 +00:00
|
|
|
P_ActivateLine(in->d.line, IgnoreThis, lineside, SPAC_PCross);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
2016-03-05 20:44:31 +00:00
|
|
|
if (TraceFlags & TRACE_Impact)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-05 20:44:31 +00:00
|
|
|
P_ActivateLine(in->d.line, IgnoreThis, lineside, SPAC_Impact);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
2016-03-05 20:44:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-30 14:30:22 +00:00
|
|
|
ff = CurSector->floorplane.ZatPoint(hit);
|
|
|
|
fc = CurSector->ceilingplane.ZatPoint(hit);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
if (entersector != NULL)
|
|
|
|
{
|
2016-03-30 14:30:22 +00:00
|
|
|
bf = entersector->floorplane.ZatPoint(hit);
|
|
|
|
bc = entersector->ceilingplane.ZatPoint(hit);
|
2016-03-05 20:44:31 +00:00
|
|
|
}
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
sector_t *hsec = CurSector->GetHeightSec();
|
|
|
|
if (Results->CrossedWater == NULL &&
|
|
|
|
hsec != NULL &&
|
2016-06-13 19:30:58 +00:00
|
|
|
Start.Z > hsec->floorplane.ZatPoint(Start) &&
|
2016-03-30 14:30:22 +00:00
|
|
|
hit.Z <= hsec->floorplane.ZatPoint(hit))
|
2016-03-05 20:44:31 +00:00
|
|
|
{
|
|
|
|
// hit crossed a water plane
|
|
|
|
if (CheckSectorPlane(hsec, true))
|
|
|
|
{
|
2017-01-07 18:32:24 +00:00
|
|
|
Results->CrossedWater = &level.sectors[CurSector->sectornum];
|
2016-03-06 20:58:36 +00:00
|
|
|
Results->CrossedWaterPos = Results->HitPos;
|
2016-04-18 16:31:19 +00:00
|
|
|
Results->Distance = 0;
|
2016-03-05 20:44:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-30 14:30:22 +00:00
|
|
|
if (hit.Z <= ff)
|
2016-03-05 20:44:31 +00:00
|
|
|
{
|
2016-04-16 17:41:33 +00:00
|
|
|
// hit floor in front of wall
|
|
|
|
Results->HitType = TRACE_HitFloor;
|
|
|
|
Results->HitTexture = CurSector->GetTexture(sector_t::floor);
|
2016-03-05 20:44:31 +00:00
|
|
|
}
|
2016-03-30 14:30:22 +00:00
|
|
|
else if (hit.Z >= fc)
|
2016-03-05 20:44:31 +00:00
|
|
|
{
|
2016-04-16 17:41:33 +00:00
|
|
|
// hit ceiling in front of wall
|
|
|
|
Results->HitType = TRACE_HitCeiling;
|
|
|
|
Results->HitTexture = CurSector->GetTexture(sector_t::ceiling);
|
2016-03-06 00:04:19 +00:00
|
|
|
}
|
2016-03-05 20:44:31 +00:00
|
|
|
else if (entersector == NULL ||
|
2016-03-30 14:30:22 +00:00
|
|
|
hit.Z < bf || hit.Z > bc ||
|
2016-03-05 20:44:31 +00:00
|
|
|
in->d.line->flags & WallMask)
|
|
|
|
{
|
|
|
|
// hit the wall
|
|
|
|
Results->HitType = TRACE_HitWall;
|
|
|
|
Results->Tier =
|
|
|
|
entersector == NULL ? TIER_Middle :
|
2016-03-30 14:30:22 +00:00
|
|
|
hit.Z <= bf ? TIER_Lower :
|
|
|
|
hit.Z >= bc ? TIER_Upper : TIER_Middle;
|
2016-03-05 20:44:31 +00:00
|
|
|
if (TraceFlags & TRACE_Impact)
|
|
|
|
{
|
|
|
|
P_ActivateLine(in->d.line, IgnoreThis, lineside, SPAC_Impact);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // made it past the wall
|
|
|
|
// check for 3D floors first
|
|
|
|
if (entersector->e->XFloor.ffloors.Size())
|
|
|
|
{
|
|
|
|
memcpy(&DummySector[sectorsel], entersector, sizeof(sector_t));
|
|
|
|
entersector = &DummySector[sectorsel];
|
|
|
|
sectorsel ^= 1;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
for (auto rover : entersector->e->XFloor.ffloors)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-05 20:44:31 +00:00
|
|
|
int entershootthrough = !!(rover->flags&FF_SHOOTTHROUGH);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
if (entershootthrough != inshootthrough && rover->flags&FF_EXISTS)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-30 14:30:22 +00:00
|
|
|
double ff_bottom = rover->bottom.plane->ZatPoint(hit);
|
|
|
|
double ff_top = rover->top.plane->ZatPoint(hit);
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
// clip to the part of the sector we are in
|
2016-03-30 14:30:22 +00:00
|
|
|
if (hit.Z > ff_top)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-05-01 17:30:51 +00:00
|
|
|
// 3D floor height is the same as the floor height. We need to test a second spot to see if it is above or below
|
|
|
|
if (fabs(bf - ff_top) < EQUAL_EPSILON)
|
|
|
|
{
|
|
|
|
double cf = entersector->floorplane.ZatPoint(entersector->centerspot);
|
|
|
|
double ffc = rover->top.plane->ZatPoint(entersector->centerspot);
|
|
|
|
if (ffc > cf)
|
|
|
|
{
|
|
|
|
bf = ff_top - EQUAL_EPSILON;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
// above
|
|
|
|
if (bf < ff_top)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-05 20:44:31 +00:00
|
|
|
entersector->floorplane = *rover->top.plane;
|
|
|
|
entersector->SetTexture(sector_t::floor, *rover->top.texture, false);
|
2016-04-20 17:20:11 +00:00
|
|
|
entersector->ClearPortal(sector_t::floor);
|
2016-03-05 20:44:31 +00:00
|
|
|
bf = ff_top;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-30 14:30:22 +00:00
|
|
|
else if (hit.Z < ff_bottom)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-05-01 17:30:51 +00:00
|
|
|
// 3D floor height is the same as the ceiling height. We need to test a second spot to see if it is above or below
|
|
|
|
if (fabs(bc - ff_bottom) < EQUAL_EPSILON)
|
|
|
|
{
|
|
|
|
double cc = entersector->ceilingplane.ZatPoint(entersector->centerspot);
|
|
|
|
double fcc = rover->bottom.plane->ZatPoint(entersector->centerspot);
|
|
|
|
if (fcc < cc)
|
|
|
|
{
|
|
|
|
bc = ff_bottom + EQUAL_EPSILON;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
//below
|
|
|
|
if (bc > ff_bottom)
|
|
|
|
{
|
|
|
|
entersector->ceilingplane = *rover->bottom.plane;
|
|
|
|
entersector->SetTexture(sector_t::ceiling, *rover->bottom.texture, false);
|
2016-04-20 17:20:11 +00:00
|
|
|
entersector->ClearPortal(sector_t::ceiling);
|
2016-03-05 20:44:31 +00:00
|
|
|
bc = ff_bottom;
|
|
|
|
}
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-05 20:44:31 +00:00
|
|
|
//hit the edge - equivalent to hitting the wall
|
|
|
|
Results->HitType = TRACE_HitWall;
|
|
|
|
Results->Tier = TIER_FFloor;
|
|
|
|
Results->ffloor = rover;
|
|
|
|
if ((TraceFlags & TRACE_Impact) && in->d.line->special)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-05 20:44:31 +00:00
|
|
|
P_ActivateLine(in->d.line, IgnoreThis, lineside, SPAC_Impact);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
2016-03-05 20:44:31 +00:00
|
|
|
goto cont;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-05 20:44:31 +00:00
|
|
|
}
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
Results->HitType = TRACE_HitNone;
|
|
|
|
if (TraceFlags & TRACE_PCross)
|
|
|
|
{
|
|
|
|
P_ActivateLine(in->d.line, IgnoreThis, lineside, SPAC_PCross);
|
|
|
|
}
|
|
|
|
if (TraceFlags & TRACE_Impact)
|
|
|
|
{ // This is incorrect for "impact", but Hexen did this, so
|
|
|
|
// we need to as well, for compatibility
|
|
|
|
P_ActivateLine(in->d.line, IgnoreThis, lineside, SPAC_Impact);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cont:
|
|
|
|
|
|
|
|
if (Results->HitType != TRACE_HitNone)
|
|
|
|
{
|
|
|
|
// We hit something, so figure out where exactly
|
2017-01-07 18:32:24 +00:00
|
|
|
Results->Sector = &level.sectors[CurSector->sectornum];
|
2016-03-05 20:44:31 +00:00
|
|
|
|
|
|
|
if (Results->HitType != TRACE_HitWall &&
|
|
|
|
!CheckSectorPlane(CurSector, Results->HitType == TRACE_HitFloor))
|
|
|
|
{ // trace is parallel to the plane (or right on it)
|
|
|
|
if (entersector == NULL)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-05 20:44:31 +00:00
|
|
|
Results->HitType = TRACE_HitWall;
|
|
|
|
Results->Tier = TIER_Middle;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
2016-03-05 20:44:31 +00:00
|
|
|
else
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-30 14:30:22 +00:00
|
|
|
if (hit.Z <= bf || hit.Z >= bc)
|
2016-03-05 20:44:31 +00:00
|
|
|
{
|
|
|
|
Results->HitType = TRACE_HitWall;
|
|
|
|
Results->Tier =
|
2016-03-30 14:30:22 +00:00
|
|
|
hit.Z <= bf ? TIER_Lower :
|
|
|
|
hit.Z >= bc ? TIER_Upper : TIER_Middle;
|
2016-03-05 20:44:31 +00:00
|
|
|
}
|
|
|
|
else
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-05 20:44:31 +00:00
|
|
|
Results->HitType = TRACE_HitNone;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-05 20:44:31 +00:00
|
|
|
if (Results->HitType == TRACE_HitWall && TraceFlags & TRACE_Impact)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-05 20:44:31 +00:00
|
|
|
P_ActivateLine(in->d.line, IgnoreThis, lineside, SPAC_Impact);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
if (Results->HitType == TRACE_HitWall)
|
|
|
|
{
|
2016-03-30 14:30:22 +00:00
|
|
|
Results->HitPos = hit;
|
2016-03-06 20:58:36 +00:00
|
|
|
SetSourcePosition();
|
2016-03-30 14:30:22 +00:00
|
|
|
Results->Distance = dist;
|
2016-03-31 14:52:25 +00:00
|
|
|
Results->Fraction = in->frac;
|
2016-03-05 20:44:31 +00:00
|
|
|
Results->Line = in->d.line;
|
|
|
|
Results->Side = lineside;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TraceCallback != NULL && Results->HitType != TRACE_HitNone)
|
|
|
|
{
|
|
|
|
switch (TraceCallback(*Results, TraceCallbackData))
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-05 20:44:31 +00:00
|
|
|
case TRACE_Stop: return false;
|
|
|
|
case TRACE_Abort: Results->HitType = TRACE_HitNone; return false;
|
|
|
|
case TRACE_Skip: Results->HitType = TRACE_HitNone; break;
|
|
|
|
default: break;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
2016-03-05 20:44:31 +00:00
|
|
|
}
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
if (Results->HitType == TRACE_HitNone)
|
|
|
|
{
|
|
|
|
CurSector = entersector;
|
|
|
|
EnterDist = dist;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-04-16 17:41:33 +00:00
|
|
|
bool FTraceInfo::ThingCheck(intercept_t *in, double dist, DVector3 hit)
|
2016-03-05 20:44:31 +00:00
|
|
|
{
|
2016-03-30 14:30:22 +00:00
|
|
|
if (hit.Z > in->d.thing->Top())
|
2016-03-05 20:44:31 +00:00
|
|
|
{
|
|
|
|
// trace enters above actor
|
2016-03-30 14:30:22 +00:00
|
|
|
if (Vec.Z >= 0) return true; // Going up: can't hit
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
// Does it hit the top of the actor?
|
2016-03-30 14:30:22 +00:00
|
|
|
dist = (in->d.thing->Top() - Start.Z) / Vec.Z;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
if (dist > MaxDist) return true;
|
2016-03-31 14:52:25 +00:00
|
|
|
in->frac = dist / MaxDist;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-30 14:30:22 +00:00
|
|
|
hit = Start + Vec * dist;
|
2016-03-05 20:44:31 +00:00
|
|
|
|
|
|
|
// calculated coordinate is outside the actor's bounding box
|
2016-03-30 14:30:22 +00:00
|
|
|
if (fabs(hit.X - in->d.thing->X()) > in->d.thing->radius ||
|
|
|
|
fabs(hit.Y - in->d.thing->Y()) > in->d.thing->radius) return true;
|
2016-03-05 20:44:31 +00:00
|
|
|
}
|
2016-03-30 14:30:22 +00:00
|
|
|
else if (hit.Z < in->d.thing->Z())
|
2016-03-05 20:44:31 +00:00
|
|
|
{ // trace enters below actor
|
2016-03-30 14:30:22 +00:00
|
|
|
if (Vec.Z <= 0) return true; // Going down: can't hit
|
2016-03-05 20:44:31 +00:00
|
|
|
|
|
|
|
// Does it hit the bottom of the actor?
|
2016-03-30 14:30:22 +00:00
|
|
|
dist = (in->d.thing->Z() - Start.Z) / Vec.Z;
|
2016-03-05 20:44:31 +00:00
|
|
|
if (dist > MaxDist) return true;
|
2016-03-31 14:52:25 +00:00
|
|
|
in->frac = dist / MaxDist;
|
2016-03-05 20:44:31 +00:00
|
|
|
|
2016-03-30 14:30:22 +00:00
|
|
|
hit = Start + Vec * dist;
|
2016-03-05 20:44:31 +00:00
|
|
|
|
|
|
|
// calculated coordinate is outside the actor's bounding box
|
2016-03-30 14:30:22 +00:00
|
|
|
if (fabs(hit.X - in->d.thing->X()) > in->d.thing->radius ||
|
|
|
|
fabs(hit.Y - in->d.thing->Y()) > in->d.thing->radius) return true;
|
2016-03-05 20:44:31 +00:00
|
|
|
}
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
if (CurSector->e->XFloor.ffloors.Size())
|
|
|
|
{
|
|
|
|
// check for 3D floor hits first.
|
2016-03-30 14:30:22 +00:00
|
|
|
double ff_floor = CurSector->floorplane.ZatPoint(hit);
|
|
|
|
double ff_ceiling = CurSector->ceilingplane.ZatPoint(hit);
|
2016-03-05 20:44:31 +00:00
|
|
|
|
2016-03-30 14:30:22 +00:00
|
|
|
if (hit.Z > ff_ceiling && CurSector->PortalBlocksMovement(sector_t::ceiling)) // actor is hit above the current ceiling
|
2016-03-05 20:44:31 +00:00
|
|
|
{
|
|
|
|
Results->HitType = TRACE_HitCeiling;
|
|
|
|
Results->HitTexture = CurSector->GetTexture(sector_t::ceiling);
|
|
|
|
}
|
2016-03-30 14:30:22 +00:00
|
|
|
else if (hit.Z < ff_floor && CurSector->PortalBlocksMovement(sector_t::floor)) // actor is hit below the current floor
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-05 20:44:31 +00:00
|
|
|
Results->HitType = TRACE_HitFloor;
|
|
|
|
Results->HitTexture = CurSector->GetTexture(sector_t::floor);
|
|
|
|
}
|
|
|
|
else goto cont1;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
// the trace hit a 3D floor before the thing.
|
|
|
|
// Calculate an intersection and abort.
|
2017-01-07 18:32:24 +00:00
|
|
|
Results->Sector = &level.sectors[CurSector->sectornum];
|
2016-03-05 20:44:31 +00:00
|
|
|
if (!CheckSectorPlane(CurSector, Results->HitType == TRACE_HitFloor))
|
|
|
|
{
|
|
|
|
Results->HitType = TRACE_HitNone;
|
|
|
|
}
|
|
|
|
if (TraceCallback != NULL)
|
|
|
|
{
|
|
|
|
switch (TraceCallback(*Results, TraceCallbackData))
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-05 20:44:31 +00:00
|
|
|
case TRACE_Continue: return true;
|
|
|
|
case TRACE_Stop: return false;
|
|
|
|
case TRACE_Abort: Results->HitType = TRACE_HitNone; return false;
|
|
|
|
case TRACE_Skip: Results->HitType = TRACE_HitNone; return true;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
2016-03-05 20:44:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cont1:
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
|
|
|
|
Results->HitType = TRACE_HitActor;
|
2016-03-30 14:30:22 +00:00
|
|
|
Results->HitPos = hit;
|
2016-03-06 20:58:36 +00:00
|
|
|
SetSourcePosition();
|
2016-03-30 14:30:22 +00:00
|
|
|
Results->Distance = dist;
|
2016-03-31 14:52:25 +00:00
|
|
|
Results->Fraction = in->frac;
|
2016-03-05 20:44:31 +00:00
|
|
|
Results->Actor = in->d.thing;
|
|
|
|
|
|
|
|
if (TraceCallback != NULL)
|
|
|
|
{
|
|
|
|
switch (TraceCallback(*Results, TraceCallbackData))
|
|
|
|
{
|
|
|
|
case TRACE_Stop: return false;
|
|
|
|
case TRACE_Abort: Results->HitType = TRACE_HitNone; return false;
|
|
|
|
case TRACE_Skip: Results->HitType = TRACE_HitNone; return true;
|
|
|
|
default: return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
bool FTraceInfo::TraceTraverse (int ptflags)
|
|
|
|
{
|
|
|
|
// Do a 3D floor check in the starting sector
|
|
|
|
Setup3DFloors();
|
|
|
|
|
2016-03-30 14:30:22 +00:00
|
|
|
FPathTraverse it(Start.X, Start.Y, Vec.X * MaxDist, Vec.Y * MaxDist, ptflags | PT_DELTA, startfrac);
|
2016-03-05 20:44:31 +00:00
|
|
|
intercept_t *in;
|
|
|
|
int lastsplashsector = -1;
|
|
|
|
|
|
|
|
while ((in = it.Next()))
|
|
|
|
{
|
|
|
|
// Deal with splashes in 3D floors (but only run once per sector, not each iteration - and stop if something was found.)
|
|
|
|
if (Results->Crossed3DWater == NULL && lastsplashsector != CurSector->sectornum)
|
|
|
|
{
|
|
|
|
for (auto rover : CurSector->e->XFloor.ffloors)
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-05 20:44:31 +00:00
|
|
|
if ((rover->flags & FF_EXISTS) && (rover->flags&FF_SWIMMABLE))
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-05 20:44:31 +00:00
|
|
|
if (Check3DFloorPlane(rover, false))
|
|
|
|
{
|
2016-08-14 18:52:13 +00:00
|
|
|
// only consider if the plane is above the actual floor.
|
|
|
|
if (rover->top.plane->ZatPoint(Results->HitPos) > CurSector->floorplane.ZatPoint(Results->HitPos))
|
|
|
|
{
|
|
|
|
Results->Crossed3DWater = rover;
|
|
|
|
Results->Crossed3DWaterPos = Results->HitPos;
|
|
|
|
Results->Distance = 0;
|
|
|
|
}
|
2016-03-05 20:44:31 +00:00
|
|
|
}
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-05 20:44:31 +00:00
|
|
|
lastsplashsector = CurSector->sectornum;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
2016-04-16 17:41:33 +00:00
|
|
|
double dist = MaxDist * in->frac;
|
|
|
|
DVector3 hit = Start + Vec * dist;
|
|
|
|
|
|
|
|
// Crossed a floor portal?
|
|
|
|
if (Vec.Z < 0 && !CurSector->PortalBlocksMovement(sector_t::floor))
|
2016-03-05 20:44:31 +00:00
|
|
|
{
|
2016-04-16 17:41:33 +00:00
|
|
|
// calculate position where the portal is crossed
|
2016-04-19 09:35:28 +00:00
|
|
|
double portz = CurSector->GetPortalPlaneZ(sector_t::floor);
|
2016-04-16 17:41:33 +00:00
|
|
|
if (hit.Z < portz && limitz > portz)
|
|
|
|
{
|
|
|
|
limitz = portz;
|
|
|
|
EnterSectorPortal(it, sector_t::floor, (portz - Start.Z) / (Vec.Z * MaxDist), CurSector);
|
|
|
|
continue;
|
|
|
|
}
|
2016-03-05 20:44:31 +00:00
|
|
|
}
|
2016-04-16 17:41:33 +00:00
|
|
|
// ... or a ceiling portal?
|
|
|
|
else if (Vec.Z > 0 && !CurSector->PortalBlocksMovement(sector_t::ceiling))
|
2016-03-05 20:44:31 +00:00
|
|
|
{
|
2016-04-16 17:41:33 +00:00
|
|
|
// calculate position where the portal is crossed
|
2016-04-19 09:35:28 +00:00
|
|
|
double portz = CurSector->GetPortalPlaneZ(sector_t::ceiling);
|
2016-04-16 17:41:33 +00:00
|
|
|
if (hit.Z > portz && limitz < portz)
|
|
|
|
{
|
|
|
|
limitz = portz;
|
|
|
|
EnterSectorPortal(it, sector_t::ceiling, (portz - Start.Z) / (Vec.Z * MaxDist), CurSector);
|
|
|
|
continue;
|
|
|
|
}
|
2016-03-05 20:44:31 +00:00
|
|
|
}
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-04-16 17:41:33 +00:00
|
|
|
if (in->isaline)
|
2016-03-06 01:07:04 +00:00
|
|
|
{
|
2016-04-16 17:41:33 +00:00
|
|
|
if (in->d.line->isLinePortal() && P_PointOnLineSidePrecise(Start, in->d.line) == 0)
|
2016-03-06 01:07:04 +00:00
|
|
|
{
|
2016-04-16 17:41:33 +00:00
|
|
|
sector_t *entersector = in->d.line->backsector;
|
|
|
|
if (entersector == NULL || (hit.Z >= entersector->floorplane.ZatPoint(hit) && hit.Z <= entersector->ceilingplane.ZatPoint(hit)))
|
|
|
|
{
|
|
|
|
FLinePortal *port = in->d.line->getPortal();
|
|
|
|
// The caller cannot handle portals without global offset.
|
|
|
|
if (port->mType == PORTT_LINKED || !(TraceFlags & TRACE_PortalRestrict))
|
|
|
|
{
|
|
|
|
EnterLinePortal(it, in);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2016-03-06 01:07:04 +00:00
|
|
|
}
|
2016-04-16 17:41:33 +00:00
|
|
|
if (!LineCheck(in, dist, hit)) break;
|
|
|
|
}
|
|
|
|
else if ((in->d.thing->flags & ActorMask) && in->d.thing != IgnoreThis)
|
|
|
|
{
|
|
|
|
if (!ThingCheck(in, dist, hit)) break;
|
2016-03-06 01:07:04 +00:00
|
|
|
}
|
2016-03-05 20:44:31 +00:00
|
|
|
}
|
2016-04-16 17:41:33 +00:00
|
|
|
|
|
|
|
if (Results->HitType == TRACE_HitNone)
|
2016-03-05 20:44:31 +00:00
|
|
|
{
|
|
|
|
if (CurSector->PortalBlocksMovement(sector_t::floor) && CheckSectorPlane(CurSector, true))
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-05 20:44:31 +00:00
|
|
|
Results->HitType = TRACE_HitFloor;
|
|
|
|
Results->HitTexture = CurSector->GetTexture(sector_t::floor);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
2016-03-05 20:44:31 +00:00
|
|
|
else if (CurSector->PortalBlocksMovement(sector_t::ceiling) && CheckSectorPlane(CurSector, false))
|
2016-03-01 15:47:10 +00:00
|
|
|
{
|
2016-03-05 20:44:31 +00:00
|
|
|
Results->HitType = TRACE_HitCeiling;
|
|
|
|
Results->HitTexture = CurSector->GetTexture(sector_t::ceiling);
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-05 20:44:31 +00:00
|
|
|
|
|
|
|
// check for intersection with floor/ceiling
|
2017-01-07 18:32:24 +00:00
|
|
|
Results->Sector = &level.sectors[CurSector->sectornum];
|
2016-03-05 20:44:31 +00:00
|
|
|
|
|
|
|
if (Results->CrossedWater == NULL &&
|
|
|
|
CurSector->heightsec != NULL &&
|
2016-06-13 19:30:58 +00:00
|
|
|
CurSector->heightsec->floorplane.ZatPoint(Start) < Start.Z &&
|
2016-03-23 17:07:04 +00:00
|
|
|
CurSector->heightsec->floorplane.ZatPoint(Results->HitPos) >= Results->HitPos.Z)
|
2016-03-05 20:44:31 +00:00
|
|
|
{
|
|
|
|
// Save the result so that the water check doesn't destroy it.
|
|
|
|
FTraceResults *res = Results;
|
|
|
|
FTraceResults hsecResult;
|
|
|
|
Results = &hsecResult;
|
|
|
|
|
|
|
|
if (CheckSectorPlane(CurSector->heightsec, true))
|
|
|
|
{
|
2017-01-07 18:32:24 +00:00
|
|
|
Results->CrossedWater = &level.sectors[CurSector->sectornum];
|
2016-03-06 20:58:36 +00:00
|
|
|
Results->CrossedWaterPos = Results->HitPos;
|
2016-04-18 16:31:19 +00:00
|
|
|
Results->Distance = 0;
|
2016-03-05 20:44:31 +00:00
|
|
|
}
|
|
|
|
Results = res;
|
|
|
|
}
|
2016-03-06 00:41:52 +00:00
|
|
|
if (Results->HitType == TRACE_HitNone && Results->Distance == 0)
|
|
|
|
{
|
2016-03-30 14:30:22 +00:00
|
|
|
Results->HitPos = Start + Vec * MaxDist;
|
2016-03-06 20:58:36 +00:00
|
|
|
SetSourcePosition();
|
2016-03-30 14:30:22 +00:00
|
|
|
Results->Distance = MaxDist;
|
2016-03-23 17:07:04 +00:00
|
|
|
Results->Fraction = 1.;
|
2016-03-06 00:41:52 +00:00
|
|
|
}
|
|
|
|
return Results->HitType != TRACE_HitNone;
|
2016-03-01 15:47:10 +00:00
|
|
|
}
|
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2016-03-01 15:47:10 +00:00
|
|
|
bool FTraceInfo::CheckPlane (const secplane_t &plane)
|
|
|
|
{
|
2016-04-03 17:46:00 +00:00
|
|
|
double den = plane.Normal() | Vec;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
if (den != 0)
|
|
|
|
{
|
2016-04-03 17:46:00 +00:00
|
|
|
double num = (plane.Normal() | Start) + plane.fD();
|
2016-03-01 15:47:10 +00:00
|
|
|
|
2016-03-30 14:30:22 +00:00
|
|
|
double hitdist = -num / den;
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
if (hitdist > EnterDist && hitdist < MaxDist)
|
|
|
|
{
|
2016-03-30 14:30:22 +00:00
|
|
|
Results->HitPos = Start + Vec * hitdist;
|
2016-03-06 20:58:36 +00:00
|
|
|
SetSourcePosition();
|
2016-03-30 14:30:22 +00:00
|
|
|
Results->Distance = hitdist;
|
|
|
|
Results->Fraction = hitdist / MaxDist;
|
2016-03-01 15:47:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-05 20:44:31 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2016-03-01 15:47:10 +00:00
|
|
|
|
|
|
|
static bool EditTraceResult (DWORD flags, FTraceResults &res)
|
|
|
|
{
|
|
|
|
if (flags & TRACE_NoSky)
|
|
|
|
{ // Throw away sky hits
|
|
|
|
if (res.HitType == TRACE_HitFloor || res.HitType == TRACE_HitCeiling)
|
|
|
|
{
|
|
|
|
if (res.HitTexture == skyflatnum)
|
|
|
|
{
|
|
|
|
res.HitType = TRACE_HitNone;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (res.HitType == TRACE_HitWall)
|
|
|
|
{
|
|
|
|
if (res.Tier == TIER_Upper &&
|
|
|
|
res.Line->frontsector->GetTexture(sector_t::ceiling) == skyflatnum &&
|
|
|
|
res.Line->backsector->GetTexture(sector_t::ceiling) == skyflatnum)
|
|
|
|
{
|
|
|
|
res.HitType = TRACE_HitNone;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|