mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-10 23:02:08 +00:00
- removed volatile type punning for clipping against line portals.
This now uses a common base for line_t and HWLinePortal.
This commit is contained in:
parent
fbd604b725
commit
2c7761926e
8 changed files with 32 additions and 39 deletions
|
@ -1456,10 +1456,24 @@ enum AutomapLineStyle : int
|
||||||
AMLS_COUNT
|
AMLS_COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
struct line_t
|
struct linebase_t
|
||||||
{
|
{
|
||||||
vertex_t *v1, *v2; // vertices, from v1 to v2
|
vertex_t* v1, * v2; // vertices, from v1 to v2
|
||||||
DVector2 delta; // precalculated v2 - v1 for side checking
|
DVector2 delta; // precalculated v2 - v1 for side checking
|
||||||
|
|
||||||
|
DVector2 Delta() const
|
||||||
|
{
|
||||||
|
return delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDelta(double x, double y)
|
||||||
|
{
|
||||||
|
delta = { x, y };
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct line_t : public linebase_t
|
||||||
|
{
|
||||||
uint32_t flags, flags2;
|
uint32_t flags, flags2;
|
||||||
uint32_t activation; // activation type
|
uint32_t activation; // activation type
|
||||||
int special;
|
int special;
|
||||||
|
@ -1477,16 +1491,6 @@ struct line_t
|
||||||
int healthgroup; // [ZZ] this is the "destructible object" id
|
int healthgroup; // [ZZ] this is the "destructible object" id
|
||||||
int linenum;
|
int linenum;
|
||||||
|
|
||||||
DVector2 Delta() const
|
|
||||||
{
|
|
||||||
return delta;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDelta(double x, double y)
|
|
||||||
{
|
|
||||||
delta = { x, y };
|
|
||||||
}
|
|
||||||
|
|
||||||
void setAlpha(double a)
|
void setAlpha(double a)
|
||||||
{
|
{
|
||||||
alpha = a;
|
alpha = a;
|
||||||
|
|
|
@ -39,12 +39,12 @@ struct intercept_t
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
inline int P_PointOnLineSidePrecise(double x, double y, const line_t *line)
|
inline int P_PointOnLineSidePrecise(double x, double y, const linebase_t *line)
|
||||||
{
|
{
|
||||||
return (y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - x) * line->Delta().Y > EQUAL_EPSILON;
|
return (y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - x) * line->Delta().Y > EQUAL_EPSILON;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int P_PointOnLineSidePrecise(const DVector2 &pt, const line_t *line)
|
inline int P_PointOnLineSidePrecise(const DVector2 &pt, const linebase_t *line)
|
||||||
{
|
{
|
||||||
return (pt.Y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - pt.X) * line->Delta().Y > EQUAL_EPSILON;
|
return (pt.Y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - pt.X) * line->Delta().Y > EQUAL_EPSILON;
|
||||||
}
|
}
|
||||||
|
|
|
@ -388,13 +388,13 @@ bool FLevelLocals::ChangePortal(line_t *ln, int thisid, int destid)
|
||||||
//
|
//
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
inline int P_GetLineSide(const DVector2 &pos, const line_t *line)
|
inline int P_GetLineSide(const DVector2 &pos, const linebase_t *line)
|
||||||
{
|
{
|
||||||
double v = (pos.Y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - pos.X) * line->Delta().Y;
|
double v = (pos.Y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - pos.X) * line->Delta().Y;
|
||||||
return v < -1. / 65536. ? -1 : v > 1. / 65536 ? 1 : 0;
|
return v < -1. / 65536. ? -1 : v > 1. / 65536 ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool P_ClipLineToPortal(line_t* line, line_t* portal, DVector2 view, bool partial, bool samebehind)
|
bool P_ClipLineToPortal(linebase_t* line, linebase_t* portal, DVector2 view, bool partial, bool samebehind)
|
||||||
{
|
{
|
||||||
int behind1 = P_GetLineSide(line->v1->fPos(), portal);
|
int behind1 = P_GetLineSide(line->v1->fPos(), portal);
|
||||||
int behind2 = P_GetLineSide(line->v2->fPos(), portal);
|
int behind2 = P_GetLineSide(line->v2->fPos(), portal);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "basics.h"
|
#include "basics.h"
|
||||||
#include "m_bbox.h"
|
#include "m_bbox.h"
|
||||||
|
|
||||||
|
struct linebase_t;
|
||||||
struct line_t;
|
struct line_t;
|
||||||
struct sector_t;
|
struct sector_t;
|
||||||
|
|
||||||
|
@ -278,7 +279,7 @@ struct FSectorPortalGroup
|
||||||
|
|
||||||
|
|
||||||
/* code ported from prototype */
|
/* code ported from prototype */
|
||||||
bool P_ClipLineToPortal(line_t* line, line_t* portal, DVector2 view, bool partial = true, bool samebehind = true);
|
bool P_ClipLineToPortal(linebase_t* line, linebase_t* portal, DVector2 view, bool partial = true, bool samebehind = true);
|
||||||
void P_TranslatePortalXY(line_t* src, double& vx, double& vy);
|
void P_TranslatePortalXY(line_t* src, double& vx, double& vy);
|
||||||
void P_TranslatePortalVXVY(line_t* src, double &velx, double &vely);
|
void P_TranslatePortalVXVY(line_t* src, double &velx, double &vely);
|
||||||
void P_TranslatePortalAngle(line_t* src, DAngle& angle);
|
void P_TranslatePortalAngle(line_t* src, DAngle& angle);
|
||||||
|
|
|
@ -485,13 +485,13 @@ void HWDrawInfo::AddLines(subsector_t * sub, sector_t * sector)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
inline bool PointOnLine(const DVector2 &pos, const line_t *line)
|
inline bool PointOnLine(const DVector2 &pos, const linebase_t *line)
|
||||||
{
|
{
|
||||||
double v = (pos.Y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - pos.X) * line->Delta().Y;
|
double v = (pos.Y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - pos.X) * line->Delta().Y;
|
||||||
return fabs(v) <= EQUAL_EPSILON;
|
return fabs(v) <= EQUAL_EPSILON;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HWDrawInfo::AddSpecialPortalLines(subsector_t * sub, sector_t * sector, line_t *line)
|
void HWDrawInfo::AddSpecialPortalLines(subsector_t * sub, sector_t * sector, linebase_t *line)
|
||||||
{
|
{
|
||||||
currentsector = sector;
|
currentsector = sector;
|
||||||
currentsubsector = sub;
|
currentsubsector = sub;
|
||||||
|
@ -653,7 +653,7 @@ void HWDrawInfo::DoSubsector(subsector_t * sub)
|
||||||
int clipres = mClipPortal->ClipSubsector(sub);
|
int clipres = mClipPortal->ClipSubsector(sub);
|
||||||
if (clipres == PClip_InFront)
|
if (clipres == PClip_InFront)
|
||||||
{
|
{
|
||||||
line_t *line = mClipPortal->ClipLine();
|
auto line = mClipPortal->ClipLine();
|
||||||
// The subsector is out of range, but we still have to check lines that lie directly on the boundary and may expose their upper or lower parts.
|
// The subsector is out of range, but we still have to check lines that lie directly on the boundary and may expose their upper or lower parts.
|
||||||
if (line) AddSpecialPortalLines(sub, fakesector, line);
|
if (line) AddSpecialPortalLines(sub, fakesector, line);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -197,7 +197,7 @@ private:
|
||||||
void RenderPolyBSPNode(void *node);
|
void RenderPolyBSPNode(void *node);
|
||||||
void AddPolyobjs(subsector_t *sub);
|
void AddPolyobjs(subsector_t *sub);
|
||||||
void AddLines(subsector_t * sub, sector_t * sector);
|
void AddLines(subsector_t * sub, sector_t * sector);
|
||||||
void AddSpecialPortalLines(subsector_t * sub, sector_t * sector, line_t *line);
|
void AddSpecialPortalLines(subsector_t * sub, sector_t * sector, linebase_t *line);
|
||||||
public:
|
public:
|
||||||
void RenderThings(subsector_t * sub, sector_t * sector);
|
void RenderThings(subsector_t * sub, sector_t * sector);
|
||||||
void RenderParticles(subsector_t *sub, sector_t *front);
|
void RenderParticles(subsector_t *sub, sector_t *front);
|
||||||
|
|
|
@ -447,7 +447,7 @@ int HWLinePortal::ClipSeg(seg_t *seg, const DVector3 &viewpos)
|
||||||
{
|
{
|
||||||
return PClip_Inside; // should be handled properly.
|
return PClip_Inside; // should be handled properly.
|
||||||
}
|
}
|
||||||
return P_ClipLineToPortal(linedef, line(), viewpos) ? PClip_InFront : PClip_Inside;
|
return P_ClipLineToPortal(linedef, this, viewpos) ? PClip_InFront : PClip_Inside;
|
||||||
}
|
}
|
||||||
|
|
||||||
int HWLinePortal::ClipSubsector(subsector_t *sub)
|
int HWLinePortal::ClipSubsector(subsector_t *sub)
|
||||||
|
@ -455,14 +455,14 @@ int HWLinePortal::ClipSubsector(subsector_t *sub)
|
||||||
// this seg is completely behind the mirror
|
// this seg is completely behind the mirror
|
||||||
for (unsigned int i = 0; i<sub->numlines; i++)
|
for (unsigned int i = 0; i<sub->numlines; i++)
|
||||||
{
|
{
|
||||||
if (P_PointOnLineSidePrecise(sub->firstline[i].v1->fPos(), line()) == 0) return PClip_Inside;
|
if (P_PointOnLineSidePrecise(sub->firstline[i].v1->fPos(), this) == 0) return PClip_Inside;
|
||||||
}
|
}
|
||||||
return PClip_InFront;
|
return PClip_InFront;
|
||||||
}
|
}
|
||||||
|
|
||||||
int HWLinePortal::ClipPoint(const DVector2 &pos)
|
int HWLinePortal::ClipPoint(const DVector2 &pos)
|
||||||
{
|
{
|
||||||
if (P_PointOnLineSidePrecise(pos, line()))
|
if (P_PointOnLineSidePrecise(pos, this))
|
||||||
{
|
{
|
||||||
return PClip_InFront;
|
return PClip_InFront;
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ public:
|
||||||
virtual int ClipSeg(seg_t *seg, const DVector3 &viewpos) { return PClip_Inside; }
|
virtual int ClipSeg(seg_t *seg, const DVector3 &viewpos) { return PClip_Inside; }
|
||||||
virtual int ClipSubsector(subsector_t *sub) { return PClip_Inside; }
|
virtual int ClipSubsector(subsector_t *sub) { return PClip_Inside; }
|
||||||
virtual int ClipPoint(const DVector2 &pos) { return PClip_Inside; }
|
virtual int ClipPoint(const DVector2 &pos) { return PClip_Inside; }
|
||||||
virtual line_t *ClipLine() { return nullptr; }
|
virtual linebase_t *ClipLine() { return nullptr; }
|
||||||
virtual void * GetSource() const = 0; // GetSource MUST be implemented!
|
virtual void * GetSource() const = 0; // GetSource MUST be implemented!
|
||||||
virtual const char *GetName() = 0;
|
virtual const char *GetName() = 0;
|
||||||
virtual bool AllowSSAO() { return true; }
|
virtual bool AllowSSAO() { return true; }
|
||||||
|
@ -156,14 +156,8 @@ public:
|
||||||
virtual void Shutdown(HWDrawInfo *di, FRenderState &rstate) {}
|
virtual void Shutdown(HWDrawInfo *di, FRenderState &rstate) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct HWLinePortal : public HWScenePortalBase
|
struct HWLinePortal : public HWScenePortalBase, public linebase_t
|
||||||
{
|
{
|
||||||
uint32_t PAD; // This fixes walls not being drawn in portals in 32bit machines..seems to be OK this is here for 64bit also..
|
|
||||||
|
|
||||||
// this must be the same as at the start of line_t, so that we can pass in this structure directly to P_ClipLineToPortal.
|
|
||||||
vertex_t *v1, *v2; // vertices, from v1 to v2
|
|
||||||
DVector2 delta; // precalculated v2 - v1 for side checking
|
|
||||||
|
|
||||||
angle_t angv1, angv2; // for quick comparisons with a line or subsector
|
angle_t angv1, angv2; // for quick comparisons with a line or subsector
|
||||||
|
|
||||||
HWLinePortal(FPortalSceneState *state, line_t *line) : HWScenePortalBase(state)
|
HWLinePortal(FPortalSceneState *state, line_t *line) : HWScenePortalBase(state)
|
||||||
|
@ -196,12 +190,6 @@ struct HWLinePortal : public HWScenePortalBase
|
||||||
delta = v2->fPos() - v1->fPos();
|
delta = v2->fPos() - v1->fPos();
|
||||||
}
|
}
|
||||||
|
|
||||||
line_t *line()
|
|
||||||
{
|
|
||||||
vertex_t **pv = &v1;
|
|
||||||
return reinterpret_cast<line_t*>(pv);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ClipSeg(seg_t *seg, const DVector3 &viewpos) override;
|
int ClipSeg(seg_t *seg, const DVector3 &viewpos) override;
|
||||||
int ClipSubsector(subsector_t *sub) override;
|
int ClipSubsector(subsector_t *sub) override;
|
||||||
int ClipPoint(const DVector2 &pos);
|
int ClipPoint(const DVector2 &pos);
|
||||||
|
@ -236,7 +224,7 @@ protected:
|
||||||
bool Setup(HWDrawInfo *di, FRenderState &rstate, Clipper *clipper) override;
|
bool Setup(HWDrawInfo *di, FRenderState &rstate, Clipper *clipper) override;
|
||||||
virtual void * GetSource() const override { return glport; }
|
virtual void * GetSource() const override { return glport; }
|
||||||
virtual const char *GetName() override;
|
virtual const char *GetName() override;
|
||||||
virtual line_t *ClipLine() override { return line(); }
|
virtual linebase_t *ClipLine() override { return this; }
|
||||||
virtual void RenderAttached(HWDrawInfo *di) override;
|
virtual void RenderAttached(HWDrawInfo *di) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in a new issue