2016-02-15 01:14:34 +00:00
|
|
|
#ifndef __P_MAPUTL_H
|
|
|
|
#define __P_MAPUTL_H
|
|
|
|
|
2016-03-28 20:47:45 +00:00
|
|
|
#include <float.h>
|
2016-02-15 01:14:34 +00:00
|
|
|
#include "r_defs.h"
|
|
|
|
#include "doomstat.h"
|
2016-02-19 13:08:41 +00:00
|
|
|
#include "m_bbox.h"
|
2016-02-15 01:14:34 +00:00
|
|
|
|
|
|
|
extern int validcount;
|
2017-03-10 01:22:42 +00:00
|
|
|
struct FBlockNode;
|
2016-02-15 01:14:34 +00:00
|
|
|
|
2016-03-21 23:06:58 +00:00
|
|
|
struct divline_t
|
2016-03-21 21:20:10 +00:00
|
|
|
{
|
2016-03-21 23:06:58 +00:00
|
|
|
double x;
|
|
|
|
double y;
|
|
|
|
double dx;
|
|
|
|
double dy;
|
2016-03-21 21:20:10 +00:00
|
|
|
};
|
|
|
|
|
2016-02-15 01:14:34 +00:00
|
|
|
struct intercept_t
|
|
|
|
{
|
2016-03-31 14:52:25 +00:00
|
|
|
double frac;
|
2016-02-15 01:14:34 +00:00
|
|
|
bool isaline;
|
|
|
|
bool done;
|
|
|
|
union {
|
|
|
|
AActor *thing;
|
|
|
|
line_t *line;
|
|
|
|
} d;
|
|
|
|
};
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// P_PointOnLineSide
|
|
|
|
//
|
|
|
|
// Returns 0 (front/on) or 1 (back)
|
|
|
|
// [RH] inlined, stripped down, and made more precise
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2016-03-31 19:13:32 +00:00
|
|
|
inline int P_PointOnLineSidePrecise(double x, double y, const line_t *line)
|
2016-02-15 01:14:34 +00:00
|
|
|
{
|
2016-06-30 09:30:32 +00:00
|
|
|
return (y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - x) * line->Delta().Y > EQUAL_EPSILON;
|
2016-02-15 01:14:34 +00:00
|
|
|
}
|
|
|
|
|
2016-03-31 19:13:32 +00:00
|
|
|
inline int P_PointOnLineSidePrecise(const DVector2 &pt, const line_t *line)
|
2016-02-15 01:14:34 +00:00
|
|
|
{
|
2016-06-30 09:30:32 +00:00
|
|
|
return (pt.Y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - pt.X) * line->Delta().Y > EQUAL_EPSILON;
|
2016-02-15 01:14:34 +00:00
|
|
|
}
|
|
|
|
|
2016-03-31 19:13:32 +00:00
|
|
|
inline int P_PointOnLineSide (double x, double y, const line_t *line)
|
2016-03-25 17:19:54 +00:00
|
|
|
{
|
2016-03-31 19:13:32 +00:00
|
|
|
extern int P_VanillaPointOnLineSide(double x, double y, const line_t* line);
|
|
|
|
return i_compatflags2 & COMPATF2_POINTONLINE
|
|
|
|
? P_VanillaPointOnLineSide(x, y, line) : P_PointOnLineSidePrecise(x, y, line);
|
2016-03-25 17:19:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline int P_PointOnLineSide(const DVector2 & p, const line_t *line)
|
|
|
|
{
|
2016-03-31 19:13:32 +00:00
|
|
|
return P_PointOnLineSide(p.X, p.Y, line);
|
2016-03-25 17:19:54 +00:00
|
|
|
}
|
|
|
|
|
2016-03-20 09:52:10 +00:00
|
|
|
|
|
|
|
|
2016-02-15 01:14:34 +00:00
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
2016-03-31 14:52:25 +00:00
|
|
|
// P_PointOnDivlineSideCompat
|
2016-02-15 01:14:34 +00:00
|
|
|
//
|
|
|
|
// Same as P_PointOnLineSide except it uses divlines
|
|
|
|
// [RH] inlined, stripped down, and made more precise
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2016-03-31 14:52:25 +00:00
|
|
|
inline int P_PointOnDivlineSide(double x, double y, const divline_t *line)
|
2016-02-15 01:14:34 +00:00
|
|
|
{
|
2016-06-30 09:30:32 +00:00
|
|
|
return (y - line->y) * line->dx + (line->x - x) * line->dy > EQUAL_EPSILON;
|
2016-02-15 01:14:34 +00:00
|
|
|
}
|
|
|
|
|
2016-03-31 14:52:25 +00:00
|
|
|
inline int P_PointOnDivlineSide(const DVector2 &pos, const divline_t *line)
|
2016-03-21 23:06:58 +00:00
|
|
|
{
|
2016-06-30 09:30:32 +00:00
|
|
|
return (pos.Y - line->y) * line->dx + (line->x - pos.X) * line->dy > EQUAL_EPSILON;
|
2016-03-28 14:22:21 +00:00
|
|
|
}
|
2016-02-15 01:14:34 +00:00
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// P_MakeDivline
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2016-03-27 11:29:58 +00:00
|
|
|
inline void P_MakeDivline(const line_t *li, divline_t *dl)
|
|
|
|
{
|
|
|
|
dl->x = li->v1->fX();
|
|
|
|
dl->y = li->v1->fY();
|
|
|
|
dl->dx = li->Delta().X;
|
|
|
|
dl->dy = li->Delta().Y;
|
|
|
|
}
|
|
|
|
|
2016-02-15 01:14:34 +00:00
|
|
|
struct FLineOpening
|
|
|
|
{
|
2016-03-25 17:19:54 +00:00
|
|
|
double top;
|
|
|
|
double bottom;
|
|
|
|
double range;
|
|
|
|
double lowfloor;
|
2016-02-15 01:14:34 +00:00
|
|
|
sector_t *bottomsec;
|
|
|
|
sector_t *topsec;
|
|
|
|
FTextureID ceilingpic;
|
|
|
|
FTextureID floorpic;
|
2016-02-21 15:56:21 +00:00
|
|
|
secplane_t frontfloorplane;
|
|
|
|
secplane_t backfloorplane;
|
2016-02-15 01:14:34 +00:00
|
|
|
int floorterrain;
|
|
|
|
bool touchmidtex;
|
|
|
|
bool abovemidtex;
|
|
|
|
};
|
|
|
|
|
2016-03-25 17:19:54 +00:00
|
|
|
static const double LINEOPEN_MIN = -FLT_MAX;
|
|
|
|
static const double LINEOPEN_MAX = FLT_MAX;
|
|
|
|
|
|
|
|
void P_LineOpening(FLineOpening &open, AActor *thing, const line_t *linedef, const DVector2 &xy, const DVector2 *ref = NULL, int flags = 0);
|
2016-03-27 11:29:58 +00:00
|
|
|
inline void P_LineOpening(FLineOpening &open, AActor *thing, const line_t *linedef, const DVector2 &xy, const DVector3 *ref, int flags = 0)
|
2016-03-26 22:19:38 +00:00
|
|
|
{
|
|
|
|
P_LineOpening(open, thing, linedef, xy, reinterpret_cast<const DVector2*>(ref), flags);
|
|
|
|
}
|
2016-03-25 17:19:54 +00:00
|
|
|
|
2016-02-15 01:14:34 +00:00
|
|
|
class FBoundingBox;
|
|
|
|
struct polyblock_t;
|
|
|
|
|
2016-02-19 09:39:40 +00:00
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// This is a dynamic array which holds its first MAX_STATIC entries in normal
|
|
|
|
// variables to avoid constant allocations which this would otherwise
|
|
|
|
// require.
|
|
|
|
//
|
|
|
|
// When collecting touched portal groups the normal cases are either
|
|
|
|
// no portals == one group or
|
|
|
|
// two portals = two groups
|
|
|
|
//
|
|
|
|
// Anything with more can happen but far less infrequently, so this
|
|
|
|
// organization helps avoiding the overhead from heap allocations
|
|
|
|
// in the vast majority of situations.
|
|
|
|
//
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
struct FPortalGroupArray
|
|
|
|
{
|
2016-02-28 22:08:32 +00:00
|
|
|
// Controls how groups are connected
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PGA_NoSectorPortals,// only collect line portals
|
|
|
|
PGA_CheckPosition, // only collects sector portals at the actual position
|
|
|
|
PGA_Full3d, // Goes up and down sector portals at any linedef within the bounding box (this is a lot slower and should only be done if really needed.)
|
|
|
|
};
|
|
|
|
|
2016-02-19 09:39:40 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
LOWER = 0x4000,
|
|
|
|
UPPER = 0x8000,
|
|
|
|
FLAT = 0xc000,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
MAX_STATIC = 4
|
|
|
|
};
|
|
|
|
|
2016-02-28 22:08:32 +00:00
|
|
|
FPortalGroupArray(int collectionmethod = PGA_CheckPosition)
|
2016-02-19 09:39:40 +00:00
|
|
|
{
|
2016-02-28 22:08:32 +00:00
|
|
|
method = collectionmethod;
|
2016-02-19 09:39:40 +00:00
|
|
|
varused = 0;
|
2016-02-19 13:08:41 +00:00
|
|
|
inited = false;
|
2016-02-19 09:39:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
data.Clear();
|
|
|
|
varused = 0;
|
2016-02-19 13:08:41 +00:00
|
|
|
inited = false;
|
2016-02-19 09:39:40 +00:00
|
|
|
}
|
|
|
|
|
2017-03-08 14:20:00 +00:00
|
|
|
void Add(uint32_t num)
|
2016-02-19 09:39:40 +00:00
|
|
|
{
|
2017-03-08 14:20:00 +00:00
|
|
|
if (varused < MAX_STATIC) entry[varused++] = (uint16_t)num;
|
|
|
|
else data.Push((uint16_t)num);
|
2016-02-19 09:39:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned Size()
|
|
|
|
{
|
|
|
|
return varused + data.Size();
|
|
|
|
}
|
|
|
|
|
2017-03-08 14:20:00 +00:00
|
|
|
uint32_t operator[](unsigned index)
|
2016-02-19 09:39:40 +00:00
|
|
|
{
|
|
|
|
return index < MAX_STATIC ? entry[index] : data[index - MAX_STATIC];
|
|
|
|
}
|
|
|
|
|
2016-02-19 13:08:41 +00:00
|
|
|
bool inited;
|
2016-02-28 22:08:32 +00:00
|
|
|
int method;
|
2016-02-19 13:08:41 +00:00
|
|
|
|
2016-02-19 09:39:40 +00:00
|
|
|
private:
|
2017-03-08 14:20:00 +00:00
|
|
|
uint16_t entry[MAX_STATIC];
|
|
|
|
uint8_t varused;
|
|
|
|
TArray<uint16_t> data;
|
2016-02-19 09:39:40 +00:00
|
|
|
};
|
|
|
|
|
2016-02-15 01:14:34 +00:00
|
|
|
class FBlockLinesIterator
|
|
|
|
{
|
2016-02-19 09:39:40 +00:00
|
|
|
friend class FMultiBlockLinesIterator;
|
2016-02-15 01:14:34 +00:00
|
|
|
int minx, maxx;
|
|
|
|
int miny, maxy;
|
|
|
|
|
|
|
|
int curx, cury;
|
|
|
|
polyblock_t *polyLink;
|
|
|
|
int polyIndex;
|
|
|
|
int *list;
|
|
|
|
|
|
|
|
void StartBlock(int x, int y);
|
|
|
|
|
2016-02-19 09:39:40 +00:00
|
|
|
FBlockLinesIterator() {}
|
|
|
|
void init(const FBoundingBox &box);
|
2016-02-15 01:14:34 +00:00
|
|
|
public:
|
|
|
|
FBlockLinesIterator(int minx, int miny, int maxx, int maxy, bool keepvalidcount = false);
|
|
|
|
FBlockLinesIterator(const FBoundingBox &box);
|
|
|
|
line_t *Next();
|
|
|
|
void Reset() { StartBlock(minx, miny); }
|
|
|
|
};
|
|
|
|
|
2016-02-19 09:39:40 +00:00
|
|
|
class FMultiBlockLinesIterator
|
|
|
|
{
|
2016-02-19 13:08:41 +00:00
|
|
|
FPortalGroupArray &checklist;
|
2016-03-31 14:52:25 +00:00
|
|
|
DVector3 checkpoint;
|
|
|
|
DVector2 offset;
|
2016-03-10 13:22:18 +00:00
|
|
|
sector_t *startsector;
|
|
|
|
sector_t *cursector;
|
2016-02-19 09:39:40 +00:00
|
|
|
short basegroup;
|
2016-02-19 13:08:41 +00:00
|
|
|
short portalflags;
|
2016-02-20 01:19:09 +00:00
|
|
|
short index;
|
2016-02-19 09:39:40 +00:00
|
|
|
bool continueup;
|
|
|
|
bool continuedown;
|
|
|
|
FBlockLinesIterator blockIterator;
|
2016-02-19 13:08:41 +00:00
|
|
|
FBoundingBox bbox;
|
2016-02-19 09:39:40 +00:00
|
|
|
|
2016-03-31 14:52:25 +00:00
|
|
|
bool GoUp(double x, double y);
|
|
|
|
bool GoDown(double x, double y);
|
2016-02-19 09:39:40 +00:00
|
|
|
void startIteratorForGroup(int group);
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
struct CheckResult
|
|
|
|
{
|
|
|
|
line_t *line;
|
2016-03-26 22:19:38 +00:00
|
|
|
DVector3 Position;
|
2016-02-19 13:08:41 +00:00
|
|
|
int portalflags;
|
2016-02-19 09:39:40 +00:00
|
|
|
};
|
|
|
|
|
2016-03-31 14:52:25 +00:00
|
|
|
FMultiBlockLinesIterator(FPortalGroupArray &check, AActor *origin, double checkradius = -1);
|
|
|
|
FMultiBlockLinesIterator(FPortalGroupArray &check, double checkx, double checky, double checkz, double checkh, double checkradius, sector_t *newsec);
|
2016-03-26 22:19:38 +00:00
|
|
|
|
2016-02-19 09:39:40 +00:00
|
|
|
bool Next(CheckResult *item);
|
|
|
|
void Reset();
|
|
|
|
// for stopping group traversal through portals. Only the calling code can decide whether this is needed so this needs to be set from the outside.
|
|
|
|
void StopUp()
|
|
|
|
{
|
|
|
|
continueup = false;
|
|
|
|
}
|
|
|
|
void StopDown()
|
|
|
|
{
|
|
|
|
continuedown = false;
|
|
|
|
}
|
2016-02-19 13:08:41 +00:00
|
|
|
const FBoundingBox &Box() const
|
|
|
|
{
|
|
|
|
return bbox;
|
|
|
|
}
|
2016-02-19 09:39:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-02-15 01:14:34 +00:00
|
|
|
class FBlockThingsIterator
|
|
|
|
{
|
|
|
|
int minx, maxx;
|
|
|
|
int miny, maxy;
|
|
|
|
|
|
|
|
int curx, cury;
|
|
|
|
|
|
|
|
FBlockNode *block;
|
|
|
|
|
|
|
|
int Buckets[32];
|
|
|
|
|
|
|
|
struct HashEntry
|
|
|
|
{
|
|
|
|
AActor *Actor;
|
|
|
|
int Next;
|
|
|
|
};
|
|
|
|
HashEntry FixedHash[10];
|
|
|
|
int NumFixedHash;
|
|
|
|
TArray<HashEntry> DynHash;
|
|
|
|
|
|
|
|
HashEntry *GetHashEntry(int i) { return i < (int)countof(FixedHash) ? &FixedHash[i] : &DynHash[i - countof(FixedHash)]; }
|
|
|
|
|
|
|
|
void StartBlock(int x, int y);
|
|
|
|
void SwitchBlock(int x, int y);
|
|
|
|
void ClearHash();
|
|
|
|
|
|
|
|
// The following is only for use in the path traverser
|
|
|
|
// and therefore declared private.
|
|
|
|
FBlockThingsIterator();
|
|
|
|
|
|
|
|
friend class FPathTraverse;
|
2016-02-20 19:36:45 +00:00
|
|
|
friend class FMultiBlockThingsIterator;
|
2016-02-15 01:14:34 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
FBlockThingsIterator(int minx, int miny, int maxx, int maxy);
|
2016-02-20 19:36:45 +00:00
|
|
|
FBlockThingsIterator(const FBoundingBox &box)
|
|
|
|
{
|
|
|
|
init(box);
|
|
|
|
}
|
|
|
|
void init(const FBoundingBox &box);
|
2016-02-15 01:14:34 +00:00
|
|
|
AActor *Next(bool centeronly = false);
|
|
|
|
void Reset() { StartBlock(minx, miny); }
|
|
|
|
};
|
|
|
|
|
2016-02-20 19:36:45 +00:00
|
|
|
class FMultiBlockThingsIterator
|
|
|
|
{
|
|
|
|
FPortalGroupArray &checklist;
|
2016-03-31 14:52:25 +00:00
|
|
|
DVector3 checkpoint;
|
2016-02-20 19:36:45 +00:00
|
|
|
short basegroup;
|
|
|
|
short portalflags;
|
|
|
|
short index;
|
|
|
|
FBlockThingsIterator blockIterator;
|
|
|
|
FBoundingBox bbox;
|
|
|
|
|
|
|
|
void startIteratorForGroup(int group);
|
|
|
|
|
2017-01-29 17:23:09 +00:00
|
|
|
protected:
|
|
|
|
FMultiBlockThingsIterator(FPortalGroupArray &check) : checklist(check) {}
|
2016-02-20 19:36:45 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
struct CheckResult
|
|
|
|
{
|
|
|
|
AActor *thing;
|
2016-03-21 21:20:10 +00:00
|
|
|
DVector3 Position;
|
2016-02-20 19:36:45 +00:00
|
|
|
int portalflags;
|
|
|
|
};
|
|
|
|
|
2016-03-31 14:52:25 +00:00
|
|
|
FMultiBlockThingsIterator(FPortalGroupArray &check, AActor *origin, double checkradius = -1, bool ignorerestricted = false);
|
|
|
|
FMultiBlockThingsIterator(FPortalGroupArray &check, double checkx, double checky, double checkz, double checkh, double checkradius, bool ignorerestricted, sector_t *newsec);
|
2016-02-20 19:36:45 +00:00
|
|
|
bool Next(CheckResult *item);
|
|
|
|
void Reset();
|
|
|
|
const FBoundingBox &Box() const
|
|
|
|
{
|
|
|
|
return bbox;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-15 01:14:34 +00:00
|
|
|
class FPathTraverse
|
|
|
|
{
|
2016-02-25 08:54:09 +00:00
|
|
|
protected:
|
2016-02-15 01:14:34 +00:00
|
|
|
static TArray<intercept_t> intercepts;
|
|
|
|
|
2016-03-31 14:52:25 +00:00
|
|
|
divline_t trace;
|
|
|
|
double Startfrac;
|
2016-02-15 01:14:34 +00:00
|
|
|
unsigned int intercept_index;
|
|
|
|
unsigned int intercept_count;
|
|
|
|
unsigned int count;
|
|
|
|
|
2016-02-25 08:54:09 +00:00
|
|
|
virtual void AddLineIntercepts(int bx, int by);
|
|
|
|
virtual void AddThingIntercepts(int bx, int by, FBlockThingsIterator &it, bool compatible);
|
|
|
|
FPathTraverse() {}
|
2016-02-15 01:14:34 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
intercept_t *Next();
|
|
|
|
|
2016-03-25 23:34:56 +00:00
|
|
|
FPathTraverse(double x1, double y1, double x2, double y2, int flags, double startfrac = 0)
|
|
|
|
{
|
2016-03-31 14:52:25 +00:00
|
|
|
init(x1, y1, x2, y2, flags, startfrac);
|
2016-03-25 23:34:56 +00:00
|
|
|
}
|
2016-03-31 14:52:25 +00:00
|
|
|
void init(double x1, double y1, double x2, double y2, int flags, double startfrac = 0);
|
2016-03-27 18:58:01 +00:00
|
|
|
int PortalRelocate(intercept_t *in, int flags, DVector3 *optpos = NULL);
|
2016-04-20 17:20:11 +00:00
|
|
|
void PortalRelocate(const DVector2 &disp, int flags, double hitfrac);
|
2016-02-25 08:54:09 +00:00
|
|
|
virtual ~FPathTraverse();
|
2016-03-31 14:52:25 +00:00
|
|
|
const divline_t &Trace() const { return trace; }
|
2016-03-02 23:58:25 +00:00
|
|
|
|
2016-03-25 23:34:56 +00:00
|
|
|
inline DVector2 InterceptPoint(const intercept_t *in)
|
|
|
|
{
|
|
|
|
return
|
|
|
|
{
|
2016-03-31 14:52:25 +00:00
|
|
|
trace.x + trace.dx * in->frac,
|
|
|
|
trace.y + trace.dy * in->frac
|
2016-03-25 23:34:56 +00:00
|
|
|
};
|
|
|
|
}
|
2016-03-02 23:58:25 +00:00
|
|
|
|
2016-02-15 01:14:34 +00:00
|
|
|
};
|
|
|
|
|
2016-02-25 12:00:23 +00:00
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// A traverser that uses the portal blockmap
|
|
|
|
// This should be in portal.h but that'd create circular dependencies.
|
|
|
|
//
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
class FLinePortalTraverse : public FPathTraverse
|
|
|
|
{
|
|
|
|
void AddLineIntercepts(int bx, int by);
|
|
|
|
|
|
|
|
public:
|
|
|
|
FLinePortalTraverse()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-02-15 01:14:34 +00:00
|
|
|
//
|
|
|
|
// P_MAPUTL
|
|
|
|
//
|
|
|
|
|
|
|
|
typedef bool(*traverser_t) (intercept_t *in);
|
|
|
|
|
2016-03-31 14:52:25 +00:00
|
|
|
int P_AproxDistance (int dx, int dy);
|
2016-03-26 22:19:38 +00:00
|
|
|
double P_InterceptVector(const divline_t *v2, const divline_t *v1);
|
2016-02-15 01:14:34 +00:00
|
|
|
|
|
|
|
#define PT_ADDLINES 1
|
|
|
|
#define PT_ADDTHINGS 2
|
|
|
|
#define PT_COMPATIBLE 4
|
|
|
|
#define PT_DELTA 8 // x2,y2 is passed as a delta, not as an endpoint
|
|
|
|
|
|
|
|
#endif
|