2006-02-24 04:48:15 +00:00
|
|
|
/*
|
|
|
|
** p_trace.cpp
|
|
|
|
** Generalized trace function, like most 3D games have
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
2006-06-11 01:37:00 +00:00
|
|
|
** Copyright 1998-2006 Randy Heit
|
2006-02-24 04:48:15 +00:00
|
|
|
** 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"
|
2008-06-15 18:36:26 +00:00
|
|
|
#include "r_sky.h"
|
2008-09-14 23:54:38 +00:00
|
|
|
#include "doomstat.h"
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2008-04-09 18:35:21 +00:00
|
|
|
struct FTraceInfo
|
|
|
|
{
|
|
|
|
fixed_t StartX, StartY, StartZ;
|
|
|
|
fixed_t Vx, Vy, Vz;
|
2015-10-12 22:30:06 +00:00
|
|
|
ActorFlags ActorMask;
|
|
|
|
DWORD WallMask;
|
2008-04-09 18:35:21 +00:00
|
|
|
AActor *IgnoreThis;
|
|
|
|
FTraceResults *Results;
|
|
|
|
sector_t *CurSector;
|
|
|
|
fixed_t MaxDist;
|
|
|
|
fixed_t EnterDist;
|
2013-03-23 02:54:13 +00:00
|
|
|
ETraceStatus (*TraceCallback)(FTraceResults &res, void *data);
|
|
|
|
void *TraceCallbackData;
|
2008-04-09 18:35:21 +00:00
|
|
|
DWORD TraceFlags;
|
2009-01-04 15:00:29 +00:00
|
|
|
int inshootthrough;
|
|
|
|
|
|
|
|
// 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;
|
2008-04-09 18:35:21 +00:00
|
|
|
|
|
|
|
bool TraceTraverse (int ptflags);
|
2011-09-21 19:39:12 +00:00
|
|
|
bool CheckPlane(const secplane_t &plane);
|
2008-04-09 18:35:21 +00:00
|
|
|
bool CheckSectorPlane (const sector_t *sector, bool checkFloor);
|
2011-09-21 19:39:12 +00:00
|
|
|
bool Check3DFloorPlane(const F3DFloor *ffloor, bool checkBottom);
|
2008-04-09 18:35:21 +00:00
|
|
|
};
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
static bool EditTraceResult (DWORD flags, FTraceResults &res);
|
|
|
|
|
2008-04-09 18:35:21 +00:00
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
bool Trace (fixed_t x, fixed_t y, fixed_t z, sector_t *sector,
|
|
|
|
fixed_t vx, fixed_t vy, fixed_t vz, fixed_t maxDist,
|
2015-10-12 22:30:06 +00:00
|
|
|
ActorFlags actorMask, DWORD wallMask, AActor *ignore,
|
2006-02-24 04:48:15 +00:00
|
|
|
FTraceResults &res,
|
2013-03-23 02:54:13 +00:00
|
|
|
DWORD flags, ETraceStatus (*callback)(FTraceResults &res, void *), void *callbackdata)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
int ptflags;
|
2008-04-09 18:35:21 +00:00
|
|
|
FTraceInfo inf;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2010-05-28 21:07:45 +00:00
|
|
|
ptflags = actorMask ? PT_ADDLINES|PT_ADDTHINGS|PT_COMPATIBLE : PT_ADDLINES;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2008-04-09 18:35:21 +00:00
|
|
|
inf.StartX = x;
|
|
|
|
inf.StartY = y;
|
|
|
|
inf.StartZ = z;
|
|
|
|
inf.Vx = vx;
|
|
|
|
inf.Vy = vy;
|
|
|
|
inf.Vz = vz;
|
|
|
|
inf.ActorMask = actorMask;
|
|
|
|
inf.WallMask = wallMask;
|
|
|
|
inf.IgnoreThis = ignore;
|
|
|
|
inf.CurSector = sector;
|
|
|
|
inf.MaxDist = maxDist;
|
|
|
|
inf.EnterDist = 0;
|
|
|
|
inf.TraceCallback = callback;
|
2013-03-23 02:54:13 +00:00
|
|
|
inf.TraceCallbackData = callbackdata;
|
2008-04-09 18:35:21 +00:00
|
|
|
inf.TraceFlags = flags;
|
|
|
|
inf.Results = &res;
|
2009-01-04 15:00:29 +00:00
|
|
|
inf.inshootthrough = true;
|
|
|
|
inf.sectorsel=0;
|
2011-09-21 19:39:12 +00:00
|
|
|
memset(&res, 0, sizeof(res));
|
|
|
|
/* // Redundant with the memset
|
|
|
|
res.HitType = TRACE_HitNone;
|
|
|
|
res.CrossedWater = NULL;
|
|
|
|
res.Crossed3DWater = NULL;
|
|
|
|
*/
|
2009-01-04 15:00:29 +00:00
|
|
|
|
2011-09-21 19:39:12 +00:00
|
|
|
// Do a 3D floor check in the starting sector
|
2009-01-04 15:00:29 +00:00
|
|
|
TDeletingArray<F3DFloor*> &ff = sector->e->XFloor.ffloors;
|
|
|
|
|
|
|
|
if (ff.Size())
|
|
|
|
{
|
|
|
|
memcpy(&inf.DummySector[0],sector,sizeof(sector_t));
|
|
|
|
inf.CurSector=sector=&inf.DummySector[0];
|
|
|
|
inf.sectorsel=1;
|
|
|
|
fixed_t bf = sector->floorplane.ZatPoint (x, y);
|
|
|
|
fixed_t bc = sector->ceilingplane.ZatPoint (x, y);
|
|
|
|
|
|
|
|
for(unsigned int i=0;i<ff.Size();i++)
|
|
|
|
{
|
|
|
|
F3DFloor * rover=ff[i];
|
2011-09-21 19:39:12 +00:00
|
|
|
if (!(rover->flags&FF_EXISTS))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (rover->flags&FF_SWIMMABLE && res.Crossed3DWater == NULL)
|
|
|
|
{
|
|
|
|
if (inf.Check3DFloorPlane(rover, false))
|
|
|
|
res.Crossed3DWater = rover;
|
|
|
|
}
|
2009-01-04 15:00:29 +00:00
|
|
|
|
2011-09-21 19:39:12 +00:00
|
|
|
if (!(rover->flags&FF_SHOOTTHROUGH))
|
2009-01-04 15:00:29 +00:00
|
|
|
{
|
|
|
|
fixed_t ff_bottom=rover->bottom.plane->ZatPoint(x, y);
|
|
|
|
fixed_t ff_top=rover->top.plane->ZatPoint(x, y);
|
|
|
|
// clip to the part of the sector we are in
|
|
|
|
if (z>ff_top)
|
|
|
|
{
|
|
|
|
// above
|
|
|
|
if (bf<ff_top)
|
|
|
|
{
|
|
|
|
sector->floorplane=*rover->top.plane;
|
|
|
|
sector->SetTexture(sector_t::floor, *rover->top.texture, false);
|
|
|
|
bf=ff_top;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (z<ff_bottom)
|
|
|
|
{
|
|
|
|
//below
|
|
|
|
if (bc>ff_bottom)
|
|
|
|
{
|
|
|
|
sector->ceilingplane=*rover->bottom.plane;
|
|
|
|
sector->SetTexture(sector_t::ceiling, *rover->bottom.texture, false);
|
|
|
|
bc=ff_bottom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// inside
|
|
|
|
if (bf<ff_bottom)
|
|
|
|
{
|
|
|
|
sector->floorplane=*rover->bottom.plane;
|
|
|
|
sector->SetTexture(sector_t::floor, *rover->bottom.texture, false);
|
|
|
|
bf=ff_bottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bc>ff_top)
|
|
|
|
{
|
|
|
|
sector->ceilingplane=*rover->top.plane;
|
|
|
|
sector->SetTexture(sector_t::ceiling, *rover->top.texture, false);
|
|
|
|
bc=ff_top;
|
|
|
|
}
|
|
|
|
inf.inshootthrough = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for overflows and clip if necessary
|
2012-03-28 04:20:23 +00:00
|
|
|
SQWORD xd = (SQWORD)x + ( ( SQWORD(vx) * SQWORD(maxDist) )>>16);
|
2009-01-04 15:00:29 +00:00
|
|
|
|
|
|
|
if (xd>SQWORD(32767)*FRACUNIT)
|
|
|
|
{
|
2012-03-28 04:20:23 +00:00
|
|
|
maxDist = inf.MaxDist = FixedDiv(FIXED_MAX - x, vx);
|
2009-01-04 15:00:29 +00:00
|
|
|
}
|
|
|
|
else if (xd<-SQWORD(32767)*FRACUNIT)
|
|
|
|
{
|
2012-03-28 04:20:23 +00:00
|
|
|
maxDist = inf.MaxDist = FixedDiv(FIXED_MIN - x, vx);
|
2009-01-04 15:00:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-28 04:20:23 +00:00
|
|
|
SQWORD yd = (SQWORD)y + ( ( SQWORD(vy) * SQWORD(maxDist) )>>16);
|
2009-01-04 15:00:29 +00:00
|
|
|
|
|
|
|
if (yd>SQWORD(32767)*FRACUNIT)
|
|
|
|
{
|
|
|
|
maxDist = inf.MaxDist=FixedDiv(FIXED_MAX-y,vy);
|
|
|
|
}
|
|
|
|
else if (yd<-SQWORD(32767)*FRACUNIT)
|
|
|
|
{
|
|
|
|
maxDist = inf.MaxDist=FixedDiv(FIXED_MIN-y,vy);
|
|
|
|
}
|
2008-04-09 18:35:21 +00:00
|
|
|
|
2009-01-04 15:00:29 +00:00
|
|
|
// recalculate the trace's end points for robustness
|
2008-04-09 18:35:21 +00:00
|
|
|
if (inf.TraceTraverse (ptflags))
|
2006-02-24 04:48:15 +00:00
|
|
|
{ // check for intersection with floor/ceiling
|
2009-01-04 15:00:29 +00:00
|
|
|
res.Sector = §ors[inf.CurSector->sectornum];
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2008-04-09 18:35:21 +00:00
|
|
|
if (inf.CheckSectorPlane (inf.CurSector, true))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
res.HitType = TRACE_HitFloor;
|
2009-01-04 15:00:29 +00:00
|
|
|
res.HitTexture = inf.CurSector->GetTexture(sector_t::floor);
|
2006-02-24 04:48:15 +00:00
|
|
|
if (res.CrossedWater == NULL &&
|
2008-04-09 18:35:21 +00:00
|
|
|
inf.CurSector->heightsec != NULL &&
|
|
|
|
inf.CurSector->heightsec->floorplane.ZatPoint (res.X, res.Y) >= res.Z)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-01-04 15:00:29 +00:00
|
|
|
res.CrossedWater = §ors[inf.CurSector->sectornum];
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
2008-04-09 18:35:21 +00:00
|
|
|
else if (inf.CheckSectorPlane (inf.CurSector, false))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
res.HitType = TRACE_HitCeiling;
|
2009-01-04 15:00:29 +00:00
|
|
|
res.HitTexture = inf.CurSector->GetTexture(sector_t::ceiling);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (res.HitType != TRACE_HitNone)
|
|
|
|
{
|
|
|
|
if (flags)
|
|
|
|
{
|
|
|
|
return EditTraceResult (flags, res);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res.HitType = TRACE_HitNone;
|
|
|
|
res.X = x + FixedMul (vx, maxDist);
|
|
|
|
res.Y = y + FixedMul (vy, maxDist);
|
|
|
|
res.Z = z + FixedMul (vz, maxDist);
|
|
|
|
res.Distance = maxDist;
|
|
|
|
res.Fraction = FRACUNIT;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-09 18:35:21 +00:00
|
|
|
bool FTraceInfo::TraceTraverse (int ptflags)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2012-03-28 04:20:23 +00:00
|
|
|
FPathTraverse it(StartX, StartY, FixedMul (Vx, MaxDist), FixedMul (Vy, MaxDist), ptflags | PT_DELTA);
|
2008-04-09 18:35:21 +00:00
|
|
|
intercept_t *in;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2008-04-09 18:35:21 +00:00
|
|
|
while ((in = it.Next()))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-04-09 18:35:21 +00:00
|
|
|
fixed_t hitx, hity, hitz;
|
|
|
|
fixed_t dist;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2011-09-21 19:39:12 +00:00
|
|
|
// Deal with splashes in 3D floors
|
|
|
|
if (CurSector->e->XFloor.ffloors.Size())
|
|
|
|
{
|
|
|
|
for(unsigned int i=0;i<CurSector->e->XFloor.ffloors.Size();i++)
|
|
|
|
{
|
|
|
|
F3DFloor * rover=CurSector->e->XFloor.ffloors[i];
|
|
|
|
if (!(rover->flags&FF_EXISTS))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Deal with splashy stuff
|
|
|
|
if (rover->flags&FF_SWIMMABLE && Results->Crossed3DWater == NULL)
|
|
|
|
{
|
|
|
|
if (Check3DFloorPlane(rover, false))
|
|
|
|
Results->Crossed3DWater = rover;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-09 18:35:21 +00:00
|
|
|
if (in->isaline)
|
|
|
|
{
|
|
|
|
int lineside;
|
|
|
|
sector_t *entersector;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2008-04-09 18:35:21 +00:00
|
|
|
dist = FixedMul (MaxDist, in->frac);
|
|
|
|
hitx = StartX + FixedMul (Vx, dist);
|
|
|
|
hity = StartY + FixedMul (Vy, dist);
|
|
|
|
hitz = StartZ + FixedMul (Vz, dist);
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2008-04-09 18:35:21 +00:00
|
|
|
fixed_t ff, fc, bf = 0, bc = 0;
|
|
|
|
|
2009-01-04 15:00:29 +00:00
|
|
|
// CurSector may be a copy so we must compare the sector number, not the index!
|
|
|
|
if (in->d.line->frontsector->sectornum == CurSector->sectornum)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
lineside = 0;
|
|
|
|
}
|
2009-01-04 15:00:29 +00:00
|
|
|
else if (in->d.line->backsector && in->d.line->backsector->sectornum == CurSector->sectornum)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-04-09 18:35:21 +00:00
|
|
|
lineside = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // Dammit. Why does Doom have to allow non-closed sectors?
|
|
|
|
if (in->d.line->backsector == NULL)
|
|
|
|
{
|
|
|
|
lineside = 0;
|
|
|
|
CurSector = in->d.line->frontsector;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lineside = P_PointOnLineSide (StartX, StartY, in->d.line);
|
|
|
|
CurSector = lineside ? in->d.line->backsector : in->d.line->frontsector;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2008-04-09 18:35:21 +00:00
|
|
|
if (!(in->d.line->flags & ML_TWOSIDED))
|
2006-04-24 14:26:06 +00:00
|
|
|
{
|
2008-04-09 18:35:21 +00:00
|
|
|
entersector = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
entersector = (lineside == 0) ? in->d.line->backsector : in->d.line->frontsector;
|
|
|
|
|
|
|
|
// For backwards compatibility: Ignore lines with the same sector on both sides.
|
2011-09-21 19:39:12 +00:00
|
|
|
// This is the way Doom.exe did it and some WADs (e.g. Alien Vendetta MAP15) need it.
|
2008-04-09 18:35:21 +00:00
|
|
|
if (i_compatflags & COMPATF_TRACE && in->d.line->backsector == in->d.line->frontsector)
|
|
|
|
{
|
2009-01-24 00:04:58 +00:00
|
|
|
// We must check special activation here because the code below is never reached.
|
|
|
|
if (TraceFlags & TRACE_PCross)
|
|
|
|
{
|
|
|
|
P_ActivateLine (in->d.line, IgnoreThis, lineside, SPAC_PCross);
|
|
|
|
}
|
|
|
|
if (TraceFlags & TRACE_Impact)
|
|
|
|
{
|
|
|
|
P_ActivateLine (in->d.line, IgnoreThis, lineside, SPAC_Impact);
|
|
|
|
}
|
2008-04-09 18:35:21 +00:00
|
|
|
continue;
|
|
|
|
}
|
2006-04-24 14:26:06 +00:00
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2008-04-09 18:35:21 +00:00
|
|
|
ff = CurSector->floorplane.ZatPoint (hitx, hity);
|
|
|
|
fc = CurSector->ceilingplane.ZatPoint (hitx, hity);
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2008-04-09 18:35:21 +00:00
|
|
|
if (entersector != NULL)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-04-09 18:35:21 +00:00
|
|
|
bf = entersector->floorplane.ZatPoint (hitx, hity);
|
|
|
|
bc = entersector->ceilingplane.ZatPoint (hitx, hity);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2008-04-09 18:35:21 +00:00
|
|
|
|
2009-05-23 10:21:33 +00:00
|
|
|
sector_t *hsec = CurSector->GetHeightSec();
|
2008-04-09 18:35:21 +00:00
|
|
|
if (Results->CrossedWater == NULL &&
|
2009-05-23 10:21:33 +00:00
|
|
|
hsec != NULL &&
|
2008-04-09 18:35:21 +00:00
|
|
|
//CurSector->heightsec->waterzone &&
|
2009-05-23 10:21:33 +00:00
|
|
|
hitz <= hsec->floorplane.ZatPoint (hitx, hity))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-04-09 18:35:21 +00:00
|
|
|
// hit crossed a water plane
|
2009-01-04 15:00:29 +00:00
|
|
|
Results->CrossedWater = §ors[CurSector->sectornum];
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2008-04-09 18:35:21 +00:00
|
|
|
if (hitz <= ff)
|
|
|
|
{ // hit floor in front of wall
|
|
|
|
Results->HitType = TRACE_HitFloor;
|
2009-01-04 15:00:29 +00:00
|
|
|
Results->HitTexture = CurSector->GetTexture(sector_t::floor);
|
2008-04-09 18:35:21 +00:00
|
|
|
}
|
|
|
|
else if (hitz >= fc)
|
|
|
|
{ // hit ceiling in front of wall
|
|
|
|
Results->HitType = TRACE_HitCeiling;
|
2009-01-04 15:00:29 +00:00
|
|
|
Results->HitTexture = CurSector->GetTexture(sector_t::ceiling);
|
2008-04-09 18:35:21 +00:00
|
|
|
}
|
|
|
|
else if (entersector == NULL ||
|
2014-10-25 08:44:00 +00:00
|
|
|
hitz < bf || hitz > bc ||
|
2008-04-09 18:35:21 +00:00
|
|
|
in->d.line->flags & WallMask)
|
|
|
|
{ // hit the wall
|
|
|
|
Results->HitType = TRACE_HitWall;
|
|
|
|
Results->Tier =
|
|
|
|
entersector == NULL ? TIER_Middle :
|
|
|
|
hitz <= bf ? TIER_Lower :
|
|
|
|
hitz >= bc ? TIER_Upper : TIER_Middle;
|
|
|
|
if (TraceFlags & TRACE_Impact)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-05-02 10:55:48 +00:00
|
|
|
P_ActivateLine (in->d.line, IgnoreThis, lineside, SPAC_Impact);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2008-04-09 18:35:21 +00:00
|
|
|
}
|
|
|
|
else
|
2009-01-04 15:00:29 +00:00
|
|
|
{ // 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;
|
|
|
|
|
|
|
|
for(unsigned int i=0;i<entersector->e->XFloor.ffloors.Size();i++)
|
|
|
|
{
|
|
|
|
F3DFloor * rover=entersector->e->XFloor.ffloors[i];
|
|
|
|
int entershootthrough = !!(rover->flags&FF_SHOOTTHROUGH);
|
|
|
|
|
|
|
|
if (entershootthrough != inshootthrough && rover->flags&FF_EXISTS)
|
|
|
|
{
|
|
|
|
fixed_t ff_bottom=rover->bottom.plane->ZatPoint(hitx, hity);
|
|
|
|
fixed_t ff_top=rover->top.plane->ZatPoint(hitx, hity);
|
|
|
|
|
|
|
|
// clip to the part of the sector we are in
|
|
|
|
if (hitz>ff_top)
|
|
|
|
{
|
|
|
|
// above
|
|
|
|
if (bf<ff_top)
|
|
|
|
{
|
|
|
|
entersector->floorplane=*rover->top.plane;
|
|
|
|
entersector->SetTexture(sector_t::floor, *rover->top.texture, false);
|
|
|
|
bf=ff_top;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (hitz<ff_bottom)
|
|
|
|
{
|
|
|
|
//below
|
|
|
|
if (bc>ff_bottom)
|
|
|
|
{
|
|
|
|
entersector->ceilingplane=*rover->bottom.plane;
|
|
|
|
entersector->SetTexture(sector_t::ceiling, *rover->bottom.texture, false);
|
|
|
|
bc=ff_bottom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//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)
|
|
|
|
{
|
|
|
|
P_ActivateLine (in->d.line, IgnoreThis, lineside, SPAC_Impact);
|
|
|
|
}
|
|
|
|
goto cont;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-09 18:35:21 +00:00
|
|
|
Results->HitType = TRACE_HitNone;
|
|
|
|
if (TraceFlags & TRACE_PCross)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-05-02 10:55:48 +00:00
|
|
|
P_ActivateLine (in->d.line, IgnoreThis, lineside, SPAC_PCross);
|
2008-04-09 18:35:21 +00:00
|
|
|
}
|
|
|
|
if (TraceFlags & TRACE_Impact)
|
|
|
|
{ // This is incorrect for "impact", but Hexen did this, so
|
|
|
|
// we need to as well, for compatibility
|
2008-05-02 10:55:48 +00:00
|
|
|
P_ActivateLine (in->d.line, IgnoreThis, lineside, SPAC_Impact);
|
2008-04-09 18:35:21 +00:00
|
|
|
}
|
|
|
|
}
|
2009-01-04 15:00:29 +00:00
|
|
|
cont:
|
2008-04-09 18:35:21 +00:00
|
|
|
|
|
|
|
if (Results->HitType != TRACE_HitNone)
|
|
|
|
{
|
|
|
|
// We hit something, so figure out where exactly
|
2009-01-04 15:00:29 +00:00
|
|
|
Results->Sector = §ors[CurSector->sectornum];
|
2008-04-09 18:35:21 +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)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
Results->HitType = TRACE_HitWall;
|
2008-04-09 18:35:21 +00:00
|
|
|
Results->Tier = TIER_Middle;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-09 18:35:21 +00:00
|
|
|
if (hitz <= bf || hitz >= bc)
|
|
|
|
{
|
|
|
|
Results->HitType = TRACE_HitWall;
|
|
|
|
Results->Tier =
|
|
|
|
hitz <= bf ? TIER_Lower :
|
|
|
|
hitz >= bc ? TIER_Upper : TIER_Middle;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Results->HitType = TRACE_HitNone;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Results->HitType == TRACE_HitWall && TraceFlags & TRACE_Impact)
|
|
|
|
{
|
2008-05-02 10:55:48 +00:00
|
|
|
P_ActivateLine (in->d.line, IgnoreThis, lineside, SPAC_Impact);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
2008-04-09 18:35:21 +00:00
|
|
|
|
|
|
|
if (Results->HitType == TRACE_HitWall)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-04-09 18:35:21 +00:00
|
|
|
Results->X = hitx;
|
|
|
|
Results->Y = hity;
|
|
|
|
Results->Z = hitz;
|
|
|
|
Results->Distance = dist;
|
|
|
|
Results->Fraction = in->frac;
|
|
|
|
Results->Line = in->d.line;
|
|
|
|
Results->Side = lineside;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-09 18:35:21 +00:00
|
|
|
if (Results->HitType == TRACE_HitNone)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-04-09 18:35:21 +00:00
|
|
|
CurSector = entersector;
|
|
|
|
EnterDist = dist;
|
|
|
|
continue;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2008-04-09 18:35:21 +00:00
|
|
|
if (TraceCallback != NULL)
|
|
|
|
{
|
2013-03-23 02:54:13 +00:00
|
|
|
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; break;
|
|
|
|
default: break;
|
|
|
|
}
|
2008-04-09 18:35:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2008-04-09 18:35:21 +00:00
|
|
|
// Encountered an actor
|
2013-03-23 02:54:13 +00:00
|
|
|
if (!(in->d.thing->flags & ActorMask) || in->d.thing == IgnoreThis)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-04-09 18:35:21 +00:00
|
|
|
continue;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2008-04-09 18:35:21 +00:00
|
|
|
dist = FixedMul (MaxDist, in->frac);
|
|
|
|
hitx = StartX + FixedMul (Vx, dist);
|
|
|
|
hity = StartY + FixedMul (Vy, dist);
|
|
|
|
hitz = StartZ + FixedMul (Vz, dist);
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2008-04-09 18:35:21 +00:00
|
|
|
if (hitz > in->d.thing->z + in->d.thing->height)
|
|
|
|
{ // trace enters above actor
|
|
|
|
if (Vz >= 0) continue; // Going up: can't hit
|
|
|
|
|
|
|
|
// Does it hit the top of the actor?
|
|
|
|
dist = FixedDiv(in->d.thing->z + in->d.thing->height - StartZ, Vz);
|
2007-10-08 09:54:00 +00:00
|
|
|
|
2008-04-09 18:35:21 +00:00
|
|
|
if (dist > MaxDist) continue;
|
|
|
|
in->frac = FixedDiv(dist, MaxDist);
|
2007-09-27 14:08:45 +00:00
|
|
|
|
2008-04-09 18:35:21 +00:00
|
|
|
hitx = StartX + FixedMul (Vx, dist);
|
|
|
|
hity = StartY + FixedMul (Vy, dist);
|
|
|
|
hitz = StartZ + FixedMul (Vz, dist);
|
2007-10-19 08:49:02 +00:00
|
|
|
|
2008-04-09 18:35:21 +00:00
|
|
|
// calculated coordinate is outside the actor's bounding box
|
|
|
|
if (abs(hitx - in->d.thing->x) > in->d.thing->radius ||
|
|
|
|
abs(hity - in->d.thing->y) > in->d.thing->radius) continue;
|
|
|
|
}
|
|
|
|
else if (hitz < in->d.thing->z)
|
|
|
|
{ // trace enters below actor
|
|
|
|
if (Vz <= 0) continue; // Going down: can't hit
|
|
|
|
|
|
|
|
// Does it hit the bottom of the actor?
|
|
|
|
dist = FixedDiv(in->d.thing->z - StartZ, Vz);
|
|
|
|
if (dist > MaxDist) continue;
|
|
|
|
in->frac = FixedDiv(dist, MaxDist);
|
|
|
|
|
|
|
|
hitx = StartX + FixedMul (Vx, dist);
|
|
|
|
hity = StartY + FixedMul (Vy, dist);
|
|
|
|
hitz = StartZ + FixedMul (Vz, dist);
|
|
|
|
|
|
|
|
// calculated coordinate is outside the actor's bounding box
|
|
|
|
if (abs(hitx - in->d.thing->x) > in->d.thing->radius ||
|
|
|
|
abs(hity - in->d.thing->y) > in->d.thing->radius) continue;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2009-01-04 15:00:29 +00:00
|
|
|
// check for extrafloors first
|
|
|
|
if (CurSector->e->XFloor.ffloors.Size())
|
|
|
|
{
|
|
|
|
fixed_t ff_floor=CurSector->floorplane.ZatPoint(hitx, hity);
|
|
|
|
fixed_t ff_ceiling=CurSector->ceilingplane.ZatPoint(hitx, hity);
|
|
|
|
|
|
|
|
if (hitz>ff_ceiling) // actor is hit above the current ceiling
|
|
|
|
{
|
|
|
|
Results->HitType=TRACE_HitCeiling;
|
|
|
|
Results->HitTexture = CurSector->GetTexture(sector_t::ceiling);
|
|
|
|
}
|
|
|
|
else if (hitz<ff_floor) // actor is hit below the current floor
|
|
|
|
{
|
|
|
|
Results->HitType=TRACE_HitFloor;
|
|
|
|
Results->HitTexture = CurSector->GetTexture(sector_t::floor);
|
|
|
|
}
|
|
|
|
else goto cont1;
|
|
|
|
|
|
|
|
// the trace hit a 3D-floor before the thing.
|
|
|
|
// Calculate an intersection and abort.
|
|
|
|
Results->Sector = §ors[CurSector->sectornum];
|
2013-03-23 02:54:13 +00:00
|
|
|
if (!CheckSectorPlane(CurSector, Results->HitType == TRACE_HitFloor))
|
2009-01-04 15:00:29 +00:00
|
|
|
{
|
2013-03-23 02:54:13 +00:00
|
|
|
Results->HitType = TRACE_HitNone;
|
2009-01-04 15:00:29 +00:00
|
|
|
}
|
|
|
|
if (TraceCallback != NULL)
|
|
|
|
{
|
2013-03-23 02:54:13 +00:00
|
|
|
switch (TraceCallback(*Results, TraceCallbackData))
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2009-01-04 15:00:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cont1:
|
2007-09-27 14:08:45 +00:00
|
|
|
|
2008-04-09 18:35:21 +00:00
|
|
|
Results->HitType = TRACE_HitActor;
|
|
|
|
Results->X = hitx;
|
|
|
|
Results->Y = hity;
|
|
|
|
Results->Z = hitz;
|
|
|
|
Results->Distance = dist;
|
|
|
|
Results->Fraction = in->frac;
|
|
|
|
Results->Actor = in->d.thing;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2008-04-09 18:35:21 +00:00
|
|
|
if (TraceCallback != NULL)
|
|
|
|
{
|
2013-03-23 02:54:13 +00:00
|
|
|
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; break;
|
|
|
|
default: break;
|
|
|
|
}
|
2008-04-09 18:35:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2008-04-09 18:35:21 +00:00
|
|
|
return true;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2011-09-21 19:39:12 +00:00
|
|
|
bool FTraceInfo::CheckPlane (const secplane_t &plane)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
fixed_t den = TMulScale16 (plane.a, Vx, plane.b, Vy, plane.c, Vz);
|
|
|
|
|
|
|
|
if (den != 0)
|
|
|
|
{
|
2008-04-09 18:35:21 +00:00
|
|
|
fixed_t num = TMulScale16 (plane.a, StartX,
|
|
|
|
plane.b, StartY,
|
2006-02-24 04:48:15 +00:00
|
|
|
plane.c, StartZ) + plane.d;
|
|
|
|
|
|
|
|
fixed_t hitdist = FixedDiv (-num, den);
|
|
|
|
|
|
|
|
if (hitdist > EnterDist && hitdist < MaxDist)
|
|
|
|
{
|
2008-04-09 18:35:21 +00:00
|
|
|
Results->X = StartX + FixedMul (Vx, hitdist);
|
|
|
|
Results->Y = StartY + FixedMul (Vy, hitdist);
|
2006-02-24 04:48:15 +00:00
|
|
|
Results->Z = StartZ + FixedMul (Vz, hitdist);
|
|
|
|
Results->Distance = hitdist;
|
|
|
|
Results->Fraction = FixedDiv (hitdist, MaxDist);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-09-21 19:39:12 +00:00
|
|
|
bool FTraceInfo::CheckSectorPlane (const sector_t *sector, bool checkFloor)
|
|
|
|
{
|
|
|
|
secplane_t plane;
|
|
|
|
|
|
|
|
if (checkFloor)
|
|
|
|
{
|
|
|
|
plane = sector->floorplane;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
plane = sector->ceilingplane;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CheckPlane(plane);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FTraceInfo::Check3DFloorPlane (const F3DFloor *ffloor, bool checkBottom)
|
|
|
|
{
|
|
|
|
secplane_t plane;
|
|
|
|
|
|
|
|
if (checkBottom)
|
|
|
|
{
|
|
|
|
plane = *(ffloor->bottom.plane);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
plane = *(ffloor->top.plane);
|
|
|
|
}
|
|
|
|
|
|
|
|
return CheckPlane(plane);
|
|
|
|
}
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
static bool EditTraceResult (DWORD flags, FTraceResults &res)
|
|
|
|
{
|
|
|
|
if (flags & TRACE_NoSky)
|
|
|
|
{ // Throw away sky hits
|
2009-01-04 15:00:29 +00:00
|
|
|
if (res.HitType == TRACE_HitFloor || res.HitType == TRACE_HitCeiling)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-01-04 15:00:29 +00:00
|
|
|
if (res.HitTexture == skyflatnum)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
res.HitType = TRACE_HitNone;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (res.HitType == TRACE_HitWall)
|
|
|
|
{
|
|
|
|
if (res.Tier == TIER_Upper &&
|
2008-08-16 20:19:35 +00:00
|
|
|
res.Line->frontsector->GetTexture(sector_t::ceiling) == skyflatnum &&
|
|
|
|
res.Line->backsector->GetTexture(sector_t::ceiling) == skyflatnum)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
res.HitType = TRACE_HitNone;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|