2021-03-15 18:05:08 +00:00
|
|
|
#ifndef __GL_CLIPPER
|
|
|
|
#define __GL_CLIPPER
|
|
|
|
|
|
|
|
#include "xs_Float.h"
|
|
|
|
#include "memarena.h"
|
|
|
|
#include "basics.h"
|
|
|
|
#include "vectors.h"
|
2021-03-22 22:40:25 +00:00
|
|
|
#include "binaryangle.h"
|
|
|
|
#include "intvec.h"
|
2021-03-15 18:05:08 +00:00
|
|
|
|
|
|
|
class ClipNode
|
|
|
|
{
|
|
|
|
friend class Clipper;
|
|
|
|
|
|
|
|
ClipNode *prev, *next;
|
|
|
|
angle_t start, end;
|
|
|
|
|
|
|
|
bool operator== (const ClipNode &other)
|
|
|
|
{
|
|
|
|
return other.start == start && other.end == end;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Clipper
|
|
|
|
{
|
|
|
|
static unsigned starttime;
|
|
|
|
FMemArena nodearena;
|
|
|
|
ClipNode * freelist = nullptr;
|
|
|
|
|
|
|
|
ClipNode * clipnodes = nullptr;
|
|
|
|
ClipNode * cliphead = nullptr;
|
|
|
|
ClipNode * silhouette = nullptr; // will be preserved even when RemoveClipRange is called
|
2021-03-22 22:40:25 +00:00
|
|
|
vec2_t viewpoint;
|
2021-03-15 18:05:08 +00:00
|
|
|
bool blocked = false;
|
|
|
|
|
2021-03-22 22:40:25 +00:00
|
|
|
bool IsRangeVisible(binangle startangle, binangle endangle);
|
2021-03-15 18:05:08 +00:00
|
|
|
void RemoveRange(ClipNode * cn);
|
2021-03-22 22:40:25 +00:00
|
|
|
void AddClipRange(binangle startangle, binangle endangle);
|
|
|
|
void RemoveClipRange(binangle startangle, binangle endangle);
|
2021-03-15 18:05:08 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Clipper();
|
|
|
|
|
|
|
|
void Clear();
|
2021-03-22 22:40:25 +00:00
|
|
|
static binangle AngleToPseudo(binangle ang);
|
2021-03-15 18:05:08 +00:00
|
|
|
|
|
|
|
void Free(ClipNode *node)
|
|
|
|
{
|
|
|
|
node->next = freelist;
|
|
|
|
freelist = node;
|
|
|
|
}
|
|
|
|
|
2021-03-22 22:40:25 +00:00
|
|
|
private:
|
2021-03-15 18:05:08 +00:00
|
|
|
ClipNode * GetNew()
|
|
|
|
{
|
|
|
|
if (freelist)
|
|
|
|
{
|
|
|
|
ClipNode * p = freelist;
|
|
|
|
freelist = p->next;
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
else return (ClipNode*)nodearena.Alloc(sizeof(ClipNode));
|
|
|
|
}
|
|
|
|
|
|
|
|
ClipNode * NewRange(angle_t start, angle_t end)
|
|
|
|
{
|
|
|
|
ClipNode * c = GetNew();
|
|
|
|
|
|
|
|
c->start = start;
|
|
|
|
c->end = end;
|
|
|
|
c->next = c->prev = NULL;
|
|
|
|
return c;
|
|
|
|
}
|
2021-03-22 22:40:25 +00:00
|
|
|
|
|
|
|
void DoRemoveClipRange(angle_t start, angle_t end);
|
|
|
|
|
|
|
|
public:
|
2021-03-15 18:05:08 +00:00
|
|
|
|
2021-03-22 22:40:25 +00:00
|
|
|
void SetViewpoint(const vec2_t &vp)
|
2021-03-15 18:05:08 +00:00
|
|
|
{
|
|
|
|
viewpoint = vp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetSilhouette();
|
|
|
|
|
2021-03-22 22:40:25 +00:00
|
|
|
bool SafeCheckRange(binangle startAngle, binangle endAngle)
|
2021-03-15 18:05:08 +00:00
|
|
|
{
|
2021-03-22 22:40:25 +00:00
|
|
|
if(startAngle.asbam() > endAngle.asbam())
|
2021-03-15 18:05:08 +00:00
|
|
|
{
|
2021-03-22 22:40:25 +00:00
|
|
|
return (IsRangeVisible(startAngle, bamang(ANGLE_MAX)) || IsRangeVisible(bamang(0), endAngle));
|
2021-03-15 18:05:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return IsRangeVisible(startAngle, endAngle);
|
|
|
|
}
|
|
|
|
|
2021-03-22 22:40:25 +00:00
|
|
|
void SafeAddClipRange(binangle startangle, binangle endangle)
|
2021-03-15 18:05:08 +00:00
|
|
|
{
|
2021-03-22 22:40:25 +00:00
|
|
|
if(startangle.asbam() > endangle.asbam())
|
2021-03-15 18:05:08 +00:00
|
|
|
{
|
|
|
|
// The range has to added in two parts.
|
2021-03-22 22:40:25 +00:00
|
|
|
AddClipRange(startangle, bamang(ANGLE_MAX));
|
|
|
|
AddClipRange(bamang(0), endangle);
|
2021-03-15 18:05:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Add the range as usual.
|
|
|
|
AddClipRange(startangle, endangle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-22 22:40:25 +00:00
|
|
|
void SafeAddClipRange(const vec2_t& v1, const vec2_t& v2)
|
2021-03-15 18:05:08 +00:00
|
|
|
{
|
2021-03-22 22:40:25 +00:00
|
|
|
binangle a2 = PointToAngle(v1);
|
|
|
|
binangle a1 = PointToAngle(v2);
|
2021-03-15 18:05:08 +00:00
|
|
|
SafeAddClipRange(a1,a2);
|
|
|
|
}
|
|
|
|
|
2021-03-22 22:40:25 +00:00
|
|
|
void SafeRemoveClipRange(binangle startangle, binangle endangle)
|
2021-03-15 18:05:08 +00:00
|
|
|
{
|
2021-03-22 22:40:25 +00:00
|
|
|
if(startangle.asbam() > endangle.asbam())
|
2021-03-15 18:05:08 +00:00
|
|
|
{
|
|
|
|
// The range has to added in two parts.
|
2021-03-22 22:40:25 +00:00
|
|
|
RemoveClipRange(startangle, bamang(ANGLE_MAX));
|
|
|
|
RemoveClipRange(bamang(0), endangle);
|
2021-03-15 18:05:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Add the range as usual.
|
|
|
|
RemoveClipRange(startangle, endangle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetBlocked(bool on)
|
|
|
|
{
|
|
|
|
blocked = on;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsBlocked() const
|
|
|
|
{
|
|
|
|
return blocked;
|
|
|
|
}
|
2021-03-23 20:23:49 +00:00
|
|
|
|
|
|
|
void DumpClipper();
|
2021-03-15 18:05:08 +00:00
|
|
|
|
2021-03-22 22:40:25 +00:00
|
|
|
binangle PointToAngle(const vec2_t& point);
|
2021-03-15 18:05:08 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|