2006-02-24 04:48:15 +00:00
|
|
|
//**************************************************************************
|
|
|
|
//**
|
|
|
|
//** p_sight.cpp : Heretic 2 : Raven Software, Corp.
|
|
|
|
//**
|
|
|
|
//** $RCSfile: p_sight.c,v $
|
|
|
|
//** $Revision: 1.1 $
|
|
|
|
//** $Date: 95/05/11 00:22:50 $
|
|
|
|
//** $Author: bgokey $
|
|
|
|
//**
|
|
|
|
//**************************************************************************
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "doomdef.h"
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "p_local.h"
|
|
|
|
#include "m_random.h"
|
|
|
|
#include "m_bbox.h"
|
|
|
|
#include "p_lnspec.h"
|
2008-09-14 23:54:38 +00:00
|
|
|
#include "g_level.h"
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
// State.
|
|
|
|
#include "r_state.h"
|
|
|
|
|
|
|
|
#include "stats.h"
|
|
|
|
|
|
|
|
static FRandom pr_botchecksight ("BotCheckSight");
|
|
|
|
static FRandom pr_checksight ("CheckSight");
|
|
|
|
|
|
|
|
/*
|
|
|
|
==============================================================================
|
|
|
|
|
|
|
|
P_CheckSight
|
|
|
|
|
|
|
|
This uses specialized forms of the maputils routines for optimized performance
|
|
|
|
|
|
|
|
==============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Performance meters
|
|
|
|
static int sightcounts[6];
|
|
|
|
static cycle_t SightCycles;
|
|
|
|
static cycle_t MaxSightCycles;
|
|
|
|
|
2009-01-04 15:00:29 +00:00
|
|
|
static TArray<intercept_t> intercepts (128);
|
|
|
|
|
|
|
|
class SightCheck
|
|
|
|
{
|
|
|
|
fixed_t sightzstart; // eye z of looker
|
|
|
|
const AActor * sightthing;
|
|
|
|
const AActor * seeingthing;
|
|
|
|
fixed_t lastztop; // z at last line
|
|
|
|
fixed_t lastzbottom; // z at last line
|
|
|
|
sector_t * lastsector; // last sector being entered by trace
|
|
|
|
fixed_t topslope, bottomslope; // slopes to top and bottom of target
|
|
|
|
int SeePastBlockEverything, SeePastShootableLines;
|
|
|
|
divline_t trace;
|
|
|
|
int myseethrough;
|
|
|
|
|
|
|
|
bool PTR_SightTraverse (intercept_t *in);
|
|
|
|
bool P_SightCheckLine (line_t *ld);
|
|
|
|
bool P_SightBlockLinesIterator (int x, int y);
|
|
|
|
bool P_SightTraverseIntercepts ();
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool P_SightPathTraverse (fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2);
|
|
|
|
|
|
|
|
SightCheck(const AActor * t1, const AActor * t2, int flags)
|
|
|
|
{
|
|
|
|
lastztop = lastzbottom = sightzstart = t1->z + t1->height - (t1->height>>2);
|
|
|
|
lastsector = t1->Sector;
|
|
|
|
sightthing=t1;
|
|
|
|
seeingthing=t2;
|
|
|
|
bottomslope = t2->z - sightzstart;
|
|
|
|
topslope = bottomslope + t2->height;
|
|
|
|
|
|
|
|
SeePastBlockEverything = flags & 6;
|
|
|
|
SeePastShootableLines = flags & 4;
|
2009-01-24 00:21:12 +00:00
|
|
|
myseethrough = FF_SEETHROUGH;
|
2009-01-04 15:00:29 +00:00
|
|
|
}
|
|
|
|
};
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
==============
|
|
|
|
=
|
|
|
|
= PTR_SightTraverse
|
|
|
|
=
|
|
|
|
==============
|
|
|
|
*/
|
|
|
|
|
2009-01-04 15:00:29 +00:00
|
|
|
/*
|
2006-02-24 04:48:15 +00:00
|
|
|
static bool PTR_SightTraverse (intercept_t *in)
|
2009-01-04 15:00:29 +00:00
|
|
|
*/
|
|
|
|
bool SightCheck::PTR_SightTraverse (intercept_t *in)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
line_t *li;
|
|
|
|
fixed_t slope;
|
2008-03-18 18:18:18 +00:00
|
|
|
FLineOpening open;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
li = in->d.line;
|
|
|
|
|
|
|
|
//
|
|
|
|
// crosses a two sided line
|
|
|
|
//
|
2009-01-04 15:00:29 +00:00
|
|
|
fixed_t trX=trace.x + FixedMul (trace.dx, in->frac);
|
|
|
|
fixed_t trY=trace.y + FixedMul (trace.dy, in->frac);
|
|
|
|
P_LineOpening (open, NULL, li, trX, trY);
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2008-03-18 18:18:18 +00:00
|
|
|
if (open.range <= 0) // quick test for totally closed doors
|
2006-02-24 04:48:15 +00:00
|
|
|
return false; // stop
|
|
|
|
|
|
|
|
// check bottom
|
2008-03-18 18:18:18 +00:00
|
|
|
slope = FixedDiv (open.bottom - sightzstart, in->frac);
|
2006-02-24 04:48:15 +00:00
|
|
|
if (slope > bottomslope)
|
|
|
|
bottomslope = slope;
|
|
|
|
|
|
|
|
// check top
|
2008-03-18 18:18:18 +00:00
|
|
|
slope = FixedDiv (open.top - sightzstart, in->frac);
|
2006-02-24 04:48:15 +00:00
|
|
|
if (slope < topslope)
|
|
|
|
topslope = slope;
|
|
|
|
|
|
|
|
if (topslope <= bottomslope)
|
|
|
|
return false; // stop
|
|
|
|
|
2009-01-04 15:00:29 +00:00
|
|
|
#ifdef _3DFLOORS
|
|
|
|
// now handle 3D-floors
|
|
|
|
if(li->frontsector->e->XFloor.ffloors.Size() || li->backsector->e->XFloor.ffloors.Size())
|
|
|
|
{
|
|
|
|
int frontflag;
|
|
|
|
|
|
|
|
frontflag = P_PointOnLineSide(sightthing->x, sightthing->y, li);
|
|
|
|
|
|
|
|
//Check 3D FLOORS!
|
|
|
|
for(int i=1;i<=2;i++)
|
|
|
|
{
|
|
|
|
sector_t * s=i==1? li->frontsector:li->backsector;
|
|
|
|
fixed_t highslope, lowslope;
|
|
|
|
|
|
|
|
fixed_t topz= FixedMul (topslope, in->frac) + sightzstart;
|
|
|
|
fixed_t bottomz= FixedMul (bottomslope, in->frac) + sightzstart;
|
|
|
|
|
|
|
|
for(unsigned int j=0;j<s->e->XFloor.ffloors.Size();j++)
|
|
|
|
{
|
|
|
|
F3DFloor* rover=s->e->XFloor.ffloors[j];
|
|
|
|
|
|
|
|
if((rover->flags & FF_SEETHROUGH) == myseethrough || !(rover->flags & FF_EXISTS)) continue;
|
|
|
|
|
|
|
|
fixed_t ff_bottom=rover->bottom.plane->ZatPoint(trX, trY);
|
|
|
|
fixed_t ff_top=rover->top.plane->ZatPoint(trX, trY);
|
|
|
|
|
|
|
|
highslope = FixedDiv (ff_top - sightzstart, in->frac);
|
|
|
|
lowslope = FixedDiv (ff_bottom - sightzstart, in->frac);
|
|
|
|
|
|
|
|
if (highslope>=topslope)
|
|
|
|
{
|
|
|
|
// blocks completely
|
|
|
|
if (lowslope<=bottomslope) return false;
|
|
|
|
// blocks upper edge of view
|
|
|
|
if (lowslope<topslope) topslope=lowslope;
|
|
|
|
}
|
|
|
|
else if (lowslope<=bottomslope)
|
|
|
|
{
|
|
|
|
// blocks lower edge of view
|
|
|
|
if (highslope>bottomslope) bottomslope=highslope;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// the 3D-floor is inside the viewing cone but neither clips the top nor the bottom so by
|
|
|
|
// itself it can't be view blocking.
|
|
|
|
// However, if there's a 3D-floor on the other side that obstructs the same vertical range
|
|
|
|
// the 2 together will block sight.
|
|
|
|
sector_t * sb=i==2? li->frontsector:li->backsector;
|
|
|
|
|
|
|
|
for(unsigned int k=0;k<sb->e->XFloor.ffloors.Size();k++)
|
|
|
|
{
|
|
|
|
F3DFloor* rover2=sb->e->XFloor.ffloors[k];
|
|
|
|
|
|
|
|
if((rover2->flags & FF_SEETHROUGH) == myseethrough || !(rover2->flags & FF_EXISTS)) continue;
|
|
|
|
|
|
|
|
fixed_t ffb_bottom=rover2->bottom.plane->ZatPoint(trX, trY);
|
|
|
|
fixed_t ffb_top=rover2->top.plane->ZatPoint(trX, trY);
|
|
|
|
|
|
|
|
if (ffb_bottom >= ff_bottom && ffb_bottom<=ff_top ||
|
|
|
|
ffb_top <= ff_top && ffb_top >= ff_bottom ||
|
|
|
|
ffb_top >= ff_top && ffb_bottom <= ff_bottom ||
|
|
|
|
ffb_top <= ff_top && ffb_bottom >= ff_bottom)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// trace is leaving a sector with a 3d-floor
|
|
|
|
if (s==lastsector && frontflag==i-1)
|
|
|
|
{
|
|
|
|
// upper slope intersects with this 3d-floor
|
|
|
|
if (lastztop<=ff_bottom && topz>ff_top)
|
|
|
|
{
|
|
|
|
topslope=lowslope;
|
|
|
|
}
|
|
|
|
// lower slope intersects with this 3d-floor
|
|
|
|
if (lastzbottom>=ff_top && bottomz<ff_top)
|
|
|
|
{
|
|
|
|
bottomslope=highslope;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (topslope <= bottomslope) return false; // stop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lastsector = frontflag==0 ? li->backsector : li->frontsector;
|
|
|
|
}
|
|
|
|
else lastsector=NULL; // don't need it if there are no 3D-floors
|
|
|
|
|
|
|
|
lastztop= FixedMul (topslope, in->frac) + sightzstart;
|
|
|
|
lastzbottom= FixedMul (bottomslope, in->frac) + sightzstart;
|
|
|
|
#endif
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
return true; // keep going
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
=
|
|
|
|
= P_SightCheckLine
|
|
|
|
=
|
|
|
|
===================
|
|
|
|
*/
|
|
|
|
|
2009-01-04 15:00:29 +00:00
|
|
|
bool SightCheck::P_SightCheckLine (line_t *ld)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
divline_t dl;
|
|
|
|
|
|
|
|
if (ld->validcount == validcount)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
ld->validcount = validcount;
|
|
|
|
if (P_PointOnDivlineSide (ld->v1->x, ld->v1->y, &trace) ==
|
|
|
|
P_PointOnDivlineSide (ld->v2->x, ld->v2->y, &trace))
|
|
|
|
{
|
|
|
|
return true; // line isn't crossed
|
|
|
|
}
|
|
|
|
P_MakeDivline (ld, &dl);
|
|
|
|
if (P_PointOnDivlineSide (trace.x, trace.y, &dl) ==
|
|
|
|
P_PointOnDivlineSide (trace.x+trace.dx, trace.y+trace.dy, &dl))
|
|
|
|
{
|
|
|
|
return true; // line isn't crossed
|
|
|
|
}
|
|
|
|
|
2009-01-04 15:00:29 +00:00
|
|
|
// try to early out the check
|
2006-02-24 04:48:15 +00:00
|
|
|
if (!ld->backsector || !(ld->flags & ML_TWOSIDED))
|
|
|
|
return false; // stop checking
|
|
|
|
|
|
|
|
// [RH] don't see past block everything lines
|
|
|
|
if (ld->flags & ML_BLOCKEVERYTHING)
|
|
|
|
{
|
|
|
|
if (!SeePastBlockEverything)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2008-10-19 02:00:00 +00:00
|
|
|
// Pretend the other side is invisible if this is not an impact line
|
|
|
|
// that runs a script on the current map. Used to prevent monsters
|
|
|
|
// from trying to attack through a block everything line unless
|
|
|
|
// there's a chance their attack will make it nonblocking.
|
|
|
|
if (!SeePastShootableLines)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-10-19 02:00:00 +00:00
|
|
|
if (!(ld->activation & SPAC_Impact))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (ld->special != ACS_Execute && ld->special != ACS_ExecuteAlways)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (ld->args[1] != 0 && ld->args[1] != level.levelnum)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sightcounts[3]++;
|
2009-01-04 15:00:29 +00:00
|
|
|
// store the line for later intersection testing
|
2006-02-24 04:48:15 +00:00
|
|
|
intercept_t newintercept;
|
|
|
|
newintercept.isaline = true;
|
|
|
|
newintercept.d.line = ld;
|
|
|
|
intercepts.Push (newintercept);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
=
|
|
|
|
= P_SightBlockLinesIterator
|
|
|
|
=
|
|
|
|
===================
|
|
|
|
*/
|
|
|
|
|
2009-01-04 15:00:29 +00:00
|
|
|
bool SightCheck::P_SightBlockLinesIterator (int x, int y)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
int offset;
|
|
|
|
int *list;
|
|
|
|
|
|
|
|
polyblock_t *polyLink;
|
|
|
|
int i;
|
|
|
|
extern polyblock_t **PolyBlockMap;
|
|
|
|
|
|
|
|
offset = y*bmapwidth+x;
|
|
|
|
|
|
|
|
polyLink = PolyBlockMap[offset];
|
|
|
|
while (polyLink)
|
|
|
|
{
|
|
|
|
if (polyLink->polyobj)
|
|
|
|
{ // only check non-empty links
|
|
|
|
if (polyLink->polyobj->validcount != validcount)
|
|
|
|
{
|
|
|
|
polyLink->polyobj->validcount = validcount;
|
2008-06-03 14:38:42 +00:00
|
|
|
for (i = 0; i < polyLink->polyobj->numlines; i++)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-06-03 14:38:42 +00:00
|
|
|
if (!P_SightCheckLine (polyLink->polyobj->lines[i]))
|
2006-02-24 04:48:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
polyLink = polyLink->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
offset = *(blockmap + offset);
|
|
|
|
|
|
|
|
for (list = blockmaplump + offset + 1; *list != -1; list++)
|
|
|
|
{
|
|
|
|
if (!P_SightCheckLine (&lines[*list]))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true; // everything was checked
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
====================
|
|
|
|
=
|
|
|
|
= P_SightTraverseIntercepts
|
|
|
|
=
|
|
|
|
= Returns true if the traverser function returns true for all lines
|
|
|
|
====================
|
|
|
|
*/
|
|
|
|
|
2009-01-04 15:00:29 +00:00
|
|
|
bool SightCheck::P_SightTraverseIntercepts ()
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-01-04 15:00:29 +00:00
|
|
|
unsigned count;
|
2006-02-24 04:48:15 +00:00
|
|
|
fixed_t dist;
|
|
|
|
intercept_t *scan, *in;
|
2009-01-04 15:00:29 +00:00
|
|
|
unsigned scanpos;
|
2006-02-24 04:48:15 +00:00
|
|
|
divline_t dl;
|
|
|
|
|
|
|
|
count = intercepts.Size ();
|
|
|
|
//
|
|
|
|
// calculate intercept distance
|
|
|
|
//
|
|
|
|
for (scanpos = 0; scanpos < intercepts.Size (); scanpos++)
|
|
|
|
{
|
|
|
|
scan = &intercepts[scanpos];
|
|
|
|
P_MakeDivline (scan->d.line, &dl);
|
|
|
|
scan->frac = P_InterceptVector (&trace, &dl);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// go through in order
|
|
|
|
// [RH] Is it really necessary to go through in order? All we care about is if
|
|
|
|
// the trace is obstructed, not what specifically obstructed it.
|
|
|
|
//
|
|
|
|
in = NULL;
|
|
|
|
|
|
|
|
while (count--)
|
|
|
|
{
|
|
|
|
dist = FIXED_MAX;
|
|
|
|
for (scanpos = 0; scanpos < intercepts.Size (); scanpos++)
|
|
|
|
{
|
|
|
|
scan = &intercepts[scanpos];
|
|
|
|
if (scan->frac < dist)
|
|
|
|
{
|
|
|
|
dist = scan->frac;
|
|
|
|
in = scan;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (in != NULL)
|
|
|
|
{
|
|
|
|
if (!PTR_SightTraverse (in))
|
|
|
|
return false; // don't bother going farther
|
|
|
|
in->frac = FIXED_MAX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-04 15:00:29 +00:00
|
|
|
#ifdef _3DFLOORS
|
|
|
|
if (lastsector==seeingthing->Sector && lastsector->e->XFloor.ffloors.Size())
|
|
|
|
{
|
|
|
|
// we must do one last check whether the trace has crossed a 3D floor in the last sector
|
|
|
|
|
|
|
|
fixed_t topz= topslope + sightzstart;
|
|
|
|
fixed_t bottomz= bottomslope + sightzstart;
|
|
|
|
|
|
|
|
for(unsigned int i=0;i<lastsector->e->XFloor.ffloors.Size();i++)
|
|
|
|
{
|
|
|
|
F3DFloor* rover = lastsector->e->XFloor.ffloors[i];
|
|
|
|
|
|
|
|
if((rover->flags & FF_SOLID) == myseethrough || !(rover->flags & FF_EXISTS)) continue;
|
|
|
|
|
|
|
|
fixed_t ff_bottom=rover->bottom.plane->ZatPoint(seeingthing->x, seeingthing->y);
|
|
|
|
fixed_t ff_top=rover->top.plane->ZatPoint(seeingthing->x, seeingthing->y);
|
|
|
|
|
|
|
|
if (lastztop<=ff_bottom && topz>ff_bottom && lastzbottom<=ff_bottom && bottomz>ff_bottom) return false;
|
|
|
|
if (lastzbottom>=ff_top && bottomz<ff_top && lastztop>=ff_top && topz<ff_top) return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
2006-02-24 04:48:15 +00:00
|
|
|
return true; // everything was traversed
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
=
|
|
|
|
= P_SightPathTraverse
|
|
|
|
=
|
|
|
|
= Traces a line from x1,y1 to x2,y2, calling the traverser function for each block
|
|
|
|
= Returns true if the traverser function returns true for all lines
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
|
2009-01-04 15:00:29 +00:00
|
|
|
bool SightCheck::P_SightPathTraverse (fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
fixed_t xt1,yt1,xt2,yt2;
|
|
|
|
fixed_t xstep,ystep;
|
|
|
|
fixed_t partialx, partialy;
|
|
|
|
fixed_t xintercept, yintercept;
|
|
|
|
int mapx, mapy, mapxstep, mapystep;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
validcount++;
|
|
|
|
intercepts.Clear ();
|
|
|
|
|
2009-01-04 15:00:29 +00:00
|
|
|
#ifdef _3DFLOORS
|
|
|
|
// for FF_SEETHROUGH the following rule applies:
|
|
|
|
// If the viewer is in an area without FF_SEETHROUGH he can only see into areas without this flag
|
|
|
|
// If the viewer is in an area with FF_SEETHROUGH he can only see into areas with this flag
|
|
|
|
for(unsigned int i=0;i<lastsector->e->XFloor.ffloors.Size();i++)
|
|
|
|
{
|
|
|
|
F3DFloor* rover = lastsector->e->XFloor.ffloors[i];
|
|
|
|
|
|
|
|
if(!(rover->flags & FF_EXISTS)) continue;
|
|
|
|
|
|
|
|
fixed_t ff_bottom=rover->bottom.plane->ZatPoint(sightthing->x, sightthing->y);
|
|
|
|
fixed_t ff_top=rover->top.plane->ZatPoint(sightthing->x, sightthing->y);
|
|
|
|
|
|
|
|
if (sightzstart < ff_top && sightzstart >= ff_bottom)
|
|
|
|
{
|
|
|
|
myseethrough = rover->flags & FF_SEETHROUGH;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
if ( ((x1-bmaporgx)&(MAPBLOCKSIZE-1)) == 0)
|
|
|
|
x1 += FRACUNIT; // don't side exactly on a line
|
|
|
|
if ( ((y1-bmaporgy)&(MAPBLOCKSIZE-1)) == 0)
|
|
|
|
y1 += FRACUNIT; // don't side exactly on a line
|
|
|
|
trace.x = x1;
|
|
|
|
trace.y = y1;
|
|
|
|
trace.dx = x2 - x1;
|
|
|
|
trace.dy = y2 - y1;
|
|
|
|
|
|
|
|
x1 -= bmaporgx;
|
|
|
|
y1 -= bmaporgy;
|
|
|
|
xt1 = x1>>MAPBLOCKSHIFT;
|
|
|
|
yt1 = y1>>MAPBLOCKSHIFT;
|
|
|
|
|
|
|
|
x2 -= bmaporgx;
|
|
|
|
y2 -= bmaporgy;
|
|
|
|
xt2 = x2>>MAPBLOCKSHIFT;
|
|
|
|
yt2 = y2>>MAPBLOCKSHIFT;
|
|
|
|
|
|
|
|
// points should never be out of bounds, but check once instead of
|
|
|
|
// each block
|
|
|
|
if (xt1<0 || yt1<0 || xt1>=bmapwidth || yt1>=bmapheight
|
|
|
|
|| xt2<0 || yt2<0 || xt2>=bmapwidth || yt2>=bmapheight)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (xt2 > xt1)
|
|
|
|
{
|
|
|
|
mapxstep = 1;
|
|
|
|
partialx = FRACUNIT - ((x1>>MAPBTOFRAC)&(FRACUNIT-1));
|
|
|
|
ystep = FixedDiv (y2-y1,abs(x2-x1));
|
|
|
|
}
|
|
|
|
else if (xt2 < xt1)
|
|
|
|
{
|
|
|
|
mapxstep = -1;
|
|
|
|
partialx = (x1>>MAPBTOFRAC)&(FRACUNIT-1);
|
|
|
|
ystep = FixedDiv (y2-y1,abs(x2-x1));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mapxstep = 0;
|
|
|
|
partialx = FRACUNIT;
|
|
|
|
ystep = 256*FRACUNIT;
|
|
|
|
}
|
|
|
|
yintercept = (y1>>MAPBTOFRAC) + FixedMul (partialx, ystep);
|
|
|
|
|
|
|
|
|
|
|
|
if (yt2 > yt1)
|
|
|
|
{
|
|
|
|
mapystep = 1;
|
|
|
|
partialy = FRACUNIT - ((y1>>MAPBTOFRAC)&(FRACUNIT-1));
|
|
|
|
xstep = FixedDiv (x2-x1,abs(y2-y1));
|
|
|
|
}
|
|
|
|
else if (yt2 < yt1)
|
|
|
|
{
|
|
|
|
mapystep = -1;
|
|
|
|
partialy = (y1>>MAPBTOFRAC)&(FRACUNIT-1);
|
|
|
|
xstep = FixedDiv (x2-x1,abs(y2-y1));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mapystep = 0;
|
|
|
|
partialy = FRACUNIT;
|
|
|
|
xstep = 256*FRACUNIT;
|
|
|
|
}
|
|
|
|
xintercept = (x1>>MAPBTOFRAC) + FixedMul (partialy, xstep);
|
|
|
|
|
|
|
|
// [RH] Fix for traces that pass only through blockmap corners. In that case,
|
|
|
|
// xintercept and yintercept can both be set ahead of mapx and mapy, so the
|
|
|
|
// for loop would never advance anywhere.
|
|
|
|
|
|
|
|
if (abs(xstep) == FRACUNIT && abs(ystep) == FRACUNIT)
|
|
|
|
{
|
|
|
|
if (ystep < 0)
|
|
|
|
{
|
|
|
|
partialx = FRACUNIT - partialx;
|
|
|
|
}
|
|
|
|
if (xstep < 0)
|
|
|
|
{
|
|
|
|
partialy = FRACUNIT - partialy;
|
|
|
|
}
|
|
|
|
if (partialx == partialy)
|
|
|
|
{
|
|
|
|
xintercept = xt1 << FRACBITS;
|
|
|
|
yintercept = yt1 << FRACBITS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// step through map blocks
|
|
|
|
// Count is present to prevent a round off error from skipping the break
|
|
|
|
mapx = xt1;
|
|
|
|
mapy = yt1;
|
|
|
|
|
|
|
|
for (count = 0 ; count < 100 ; count++)
|
|
|
|
{
|
|
|
|
if (!P_SightBlockLinesIterator (mapx, mapy))
|
|
|
|
{
|
|
|
|
sightcounts[1]++;
|
|
|
|
return false; // early out
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((mapxstep | mapystep) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch ((((yintercept >> FRACBITS) == mapy) << 1) | ((xintercept >> FRACBITS) == mapx))
|
|
|
|
{
|
|
|
|
case 0: // neither xintercept nor yintercept match!
|
|
|
|
sightcounts[5]++;
|
|
|
|
// Continuing won't make things any better, so we might as well stop right here
|
|
|
|
count = 100;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: // xintercept matches
|
|
|
|
xintercept += xstep;
|
|
|
|
mapy += mapystep;
|
|
|
|
if (mapy == yt2)
|
|
|
|
mapystep = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: // yintercept matches
|
|
|
|
yintercept += ystep;
|
|
|
|
mapx += mapxstep;
|
|
|
|
if (mapx == xt2)
|
|
|
|
mapxstep = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3: // xintercept and yintercept both match
|
|
|
|
sightcounts[4]++;
|
|
|
|
// The trace is exiting a block through its corner. Not only does the block
|
|
|
|
// being entered need to be checked (which will happen when this loop
|
|
|
|
// continues), but the other two blocks adjacent to the corner also need to
|
|
|
|
// be checked.
|
|
|
|
if (!P_SightBlockLinesIterator (mapx + mapxstep, mapy) ||
|
|
|
|
!P_SightBlockLinesIterator (mapx, mapy + mapystep))
|
|
|
|
{
|
|
|
|
sightcounts[1]++;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
xintercept += xstep;
|
|
|
|
yintercept += ystep;
|
|
|
|
mapx += mapxstep;
|
|
|
|
mapy += mapystep;
|
|
|
|
if (mapx == xt2)
|
|
|
|
mapxstep = 0;
|
|
|
|
if (mapy == yt2)
|
|
|
|
mapystep = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// couldn't early out, so go through the sorted list
|
|
|
|
//
|
|
|
|
sightcounts[2]++;
|
|
|
|
|
|
|
|
return P_SightTraverseIntercepts ( );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=====================
|
|
|
|
=
|
|
|
|
= P_CheckSight
|
|
|
|
=
|
|
|
|
= Returns true if a straight line between t1 and t2 is unobstructed
|
|
|
|
= look from eyes of t1 to any part of t2
|
|
|
|
=
|
|
|
|
= killough 4/20/98: cleaned up, made to use new LOS struct
|
|
|
|
=
|
|
|
|
=====================
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool P_CheckSight (const AActor *t1, const AActor *t2, int flags)
|
|
|
|
{
|
2008-08-10 03:25:08 +00:00
|
|
|
SightCycles.Clock();
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
bool res;
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
assert (t1 != NULL);
|
|
|
|
assert (t2 != NULL);
|
|
|
|
#else
|
|
|
|
if (t1 == NULL || t2 == NULL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
const sector_t *s1 = t1->Sector;
|
|
|
|
const sector_t *s2 = t2->Sector;
|
|
|
|
int pnum = int(s1 - sectors) * numsectors + int(s2 - sectors);
|
|
|
|
|
|
|
|
//
|
|
|
|
// check for trivial rejection
|
|
|
|
//
|
|
|
|
if (rejectmatrix != NULL &&
|
|
|
|
(rejectmatrix[pnum>>3] & (1 << (pnum & 7))))
|
|
|
|
{
|
|
|
|
sightcounts[0]++;
|
|
|
|
res = false; // can't possibly be connected
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// check precisely
|
|
|
|
//
|
|
|
|
// [RH] Andy Baker's stealth monsters:
|
|
|
|
// Cannot see an invisible object
|
- Updated lempar.c to v1.31.
- Added .txt files to the list of types (wad, zip, and pk3) that can be
loaded without listing them after -file.
- Fonts that are created by the ACS setfont command to wrap a texture now
support animated textures.
- FON2 fonts can now use their full palette for CR_UNTRANSLATED when drawn
with the hardware 2D path instead of being restricted to the game palette.
- Fixed: Toggling vid_vsync would reset the displayed fullscreen gamma to 1
on a Radeon 9000.
- Added back the off-by-one palette handling, but in a much more limited
scope than before. The skipped entry is assumed to always be at 248, and
it is assumed that all Shader Model 1.4 cards suffer from this. That's
because all SM1.4 cards are based on variants of the ATI R200 core, and the
RV250 in a Radeon 9000 craps up like this. I see no reason to assume that
other flavors of the R200 are any different. (Interesting note: With the
Radeon 9000, D3DTADDRESS_CLAMP is an invalid address mode when using the
debug Direct3D 9 runtime, but it works perfectly fine with the retail
Direct3D 9 runtime.) (Insight: The R200 probably uses bytes for all its
math inside pixel shaders. That would explain perfectly why I can't use
constants greater than 1 with PS1.4 and why it can't do an exact mapping to
every entry in the color palette.
- Fixed: The software shaded drawer did not work for 2D, because its selected
"color"map was replaced with the identitymap before being used.
- Fixed: I cannot use Printf to output messages before the framebuffer was
completely setup, meaning that Shader Model 1.4 cards could not change
resolution.
- I have decided to let remap palettes specify variable alpha values for
their colors. D3DFB no longer forces them to 255.
- Updated re2c to version 0.12.3.
- Fixed: A_Wander used threshold as a timer, when it should have used
reactiontime.
- Fixed: A_CustomRailgun would not fire at all for actors without a target
when the aim parameter was disabled.
- Made the warp command work in multiplayer, again courtesy of Karate Chris.
- Fixed: Trying to spawn a bot while not in a game made for a crashing time.
(Patch courtesy of Karate Chris.)
- Removed some floating point math from hu_scores.cpp that somebody's GCC
gave warnings for (not mine, though).
- Fixed: The SBarInfo drawbar command crashed if the sprite image was
unavailable.
- Fixed: FString::operator=(const char *) did not release its old buffer when
being assigned to the null string.
- The scanner no longer has an upper limit on the length of strings it
accepts, though short strings will be faster than long ones.
- Moved all the text scanning functions into a class. Mainly, this means that
multiple script scanner states can be stored without being forced to do so
recursively. I think I might be taking advantage of that in the near
future. Possibly. Maybe.
- Removed some potential buffer overflows from the decal parser.
- Applied Blzut3's SBARINFO update #9:
* Fixed: When using even length values in drawnumber it would cap to a 98
value instead of a 99 as intended.
* The SBarInfo parser can now accept negatives for coordinates. This
doesn't allow much right now, but later I plan to add better fullscreen
hud support in which the negatives will be more useful. This also cleans
up the source a bit since all calls for (x, y) coordinates are with the
function getCoordinates().
- Added support for stencilling actors.
- Added support for non-black colors specified with DTA_ColorOverlay to the
software renderer.
- Fixed: The inverse, gold, red, and green fixed colormaps each allocated
space for 32 different colormaps, even though each only used the first one.
- Added two new blending flags to make reverse subtract blending more useful:
STYLEF_InvertSource and STYLEF_InvertOverlay. These invert the color that
gets blended with the background, since that seems like a good idea for
reverse subtraction. They also work with the other two blending operations.
- Added subtract and reverse subtract blending operations to the renderer.
Since the ERenderStyle enumeration was getting rather unwieldy, I converted
it into a new FRenderStyle structure that lets each parameter of the
blending equation be set separately. This simplified the set up for the
blend quite a bit, and it means a number of new combinations are available
by setting the parameters properly.
SVN r710 (trunk)
2008-01-25 23:57:44 +00:00
|
|
|
if ((flags & 1) == 0 && ((t2->renderflags & RF_INVISIBLE) || !t2->RenderStyle.IsVisible(t2->alpha)))
|
2006-02-24 04:48:15 +00:00
|
|
|
{ // small chance of an attack being made anyway
|
2008-03-28 00:38:17 +00:00
|
|
|
if ((bglobal.m_Thinking ? pr_botchecksight() : pr_checksight()) > 50)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
res = false;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// killough 4/19/98: make fake floors and ceilings block monster view
|
|
|
|
|
|
|
|
if ((s1->heightsec && !(s1->heightsec->MoreFlags & SECF_IGNOREHEIGHTSEC) &&
|
|
|
|
((t1->z + t1->height <= s1->heightsec->floorplane.ZatPoint (t1->x, t1->y) &&
|
|
|
|
t2->z >= s1->heightsec->floorplane.ZatPoint (t2->x, t2->y)) ||
|
|
|
|
(t1->z >= s1->heightsec->ceilingplane.ZatPoint (t1->x, t1->y) &&
|
|
|
|
t2->z + t1->height <= s1->heightsec->ceilingplane.ZatPoint (t2->x, t2->y))))
|
|
|
|
||
|
|
|
|
(s2->heightsec && !(s2->heightsec->MoreFlags & SECF_IGNOREHEIGHTSEC) &&
|
|
|
|
((t2->z + t2->height <= s2->heightsec->floorplane.ZatPoint (t2->x, t2->y) &&
|
|
|
|
t1->z >= s2->heightsec->floorplane.ZatPoint (t1->x, t1->y)) ||
|
|
|
|
(t2->z >= s2->heightsec->ceilingplane.ZatPoint (t2->x, t2->y) &&
|
|
|
|
t1->z + t2->height <= s2->heightsec->ceilingplane.ZatPoint (t1->x, t1->y)))))
|
|
|
|
{
|
|
|
|
res = false;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
// An unobstructed LOS is possible.
|
|
|
|
// Now look from eyes of t1 to any part of t2.
|
|
|
|
|
|
|
|
validcount++;
|
2009-01-04 15:00:29 +00:00
|
|
|
{
|
|
|
|
SightCheck s(t1, t2, flags);
|
|
|
|
res = s.P_SightPathTraverse (t1->x, t1->y, t2->x, t2->y);
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
done:
|
2008-08-10 03:25:08 +00:00
|
|
|
SightCycles.Unclock();
|
2006-02-24 04:48:15 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-09-14 00:02:31 +00:00
|
|
|
ADD_STAT (sight)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-09-14 00:02:31 +00:00
|
|
|
FString out;
|
|
|
|
out.Format ("%04.1f ms (%04.1f max), %5d %2d%4d%4d%4d%4d\n",
|
2008-08-10 03:25:08 +00:00
|
|
|
SightCycles.TimeMS(), MaxSightCycles.TimeMS(),
|
2006-02-24 04:48:15 +00:00
|
|
|
sightcounts[3], sightcounts[0], sightcounts[1], sightcounts[2], sightcounts[4], sightcounts[5]);
|
2006-09-14 00:02:31 +00:00
|
|
|
return out;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void P_ResetSightCounters (bool full)
|
|
|
|
{
|
|
|
|
if (full)
|
|
|
|
{
|
2008-08-10 03:25:08 +00:00
|
|
|
MaxSightCycles.Reset();
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2008-08-10 03:25:08 +00:00
|
|
|
if (SightCycles.Time() > MaxSightCycles.Time())
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
MaxSightCycles = SightCycles;
|
|
|
|
}
|
2008-08-10 03:25:08 +00:00
|
|
|
SightCycles.Reset();
|
2006-02-24 04:48:15 +00:00
|
|
|
memset (sightcounts, 0, sizeof(sightcounts));
|
|
|
|
}
|
2009-01-04 15:00:29 +00:00
|
|
|
|
|
|
|
|