Give the clipper a reference to the current viewpoint

This is both for efficiency and encapsulation. At last on MSVC in 64 bit, accessing global variables is very inefficient and the clipper was doing it repeatedly in its worker functions.

It is also one less place where the global viewpoint gets checked.
This commit is contained in:
Christoph Oelckers 2018-06-19 09:37:49 +02:00
parent 46d73e7b4b
commit 74d8c929cc
5 changed files with 26 additions and 21 deletions

View file

@ -201,6 +201,7 @@ FDrawInfo *FDrawInfo::StartDrawInfo(GLSceneDrawer *drawer)
di->mDrawer = drawer; di->mDrawer = drawer;
di->mVBO = GLRenderer->mVBO; di->mVBO = GLRenderer->mVBO;
di->mClipper = &staticClipper; di->mClipper = &staticClipper;
di->mClipper->SetViewpoint(r_viewpoint);
staticClipper.Clear(); staticClipper.Clear();
di->FixedColormap = drawer->FixedColormap; di->FixedColormap = drawer->FixedColormap;
di->StartScene(); di->StartScene();

View file

@ -941,9 +941,7 @@ void GLMirrorPortal::DrawContents(FDrawInfo *di)
angle_t af = drawer->FrustumAngle(); angle_t af = drawer->FrustumAngle();
if (af<ANGLE_180) di->mClipper->SafeAddClipRangeRealAngles(r_viewpoint.Angles.Yaw.BAMs()+af, r_viewpoint.Angles.Yaw.BAMs()-af); if (af<ANGLE_180) di->mClipper->SafeAddClipRangeRealAngles(r_viewpoint.Angles.Yaw.BAMs()+af, r_viewpoint.Angles.Yaw.BAMs()-af);
angle_t a2 = linedef->v1->GetClipAngle(); di->mClipper->SafeAddClipRange(linedef->v1, linedef->v2);
angle_t a1 = linedef->v2->GetClipAngle();
di->mClipper->SafeAddClipRange(a1,a2);
gl_RenderState.SetClipLine(linedef); gl_RenderState.SetClipLine(linedef);
gl_RenderState.EnableClipLine(true); gl_RenderState.EnableClipLine(true);

View file

@ -373,10 +373,10 @@ angle_t Clipper::AngleToPseudo(angle_t ang)
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
angle_t R_PointToPseudoAngle(double x, double y) angle_t Clipper::PointToPseudoAngle(double x, double y)
{ {
double vecx = x - r_viewpoint.Pos.X; double vecx = x - viewpoint->Pos.X;
double vecy = y - r_viewpoint.Pos.Y; double vecy = y - viewpoint->Pos.Y;
if (vecx == 0 && vecy == 0) if (vecx == 0 && vecy == 0)
{ {
@ -427,14 +427,15 @@ bool Clipper::CheckBox(const float *bspcoord)
// Find the corners of the box // Find the corners of the box
// that define the edges from current viewpoint. // that define the edges from current viewpoint.
boxpos = (r_viewpoint.Pos.X <= bspcoord[BOXLEFT] ? 0 : r_viewpoint.Pos.X < bspcoord[BOXRIGHT ] ? 1 : 2) + auto &vp = viewpoint;
(r_viewpoint.Pos.Y >= bspcoord[BOXTOP ] ? 0 : r_viewpoint.Pos.Y > bspcoord[BOXBOTTOM] ? 4 : 8); boxpos = (vp->Pos.X <= bspcoord[BOXLEFT] ? 0 : vp->Pos.X < bspcoord[BOXRIGHT ] ? 1 : 2) +
(vp->Pos.Y >= bspcoord[BOXTOP ] ? 0 : vp->Pos.Y > bspcoord[BOXBOTTOM] ? 4 : 8);
if (boxpos == 5) return true; if (boxpos == 5) return true;
check = checkcoord[boxpos]; check = checkcoord[boxpos];
angle1 = R_PointToPseudoAngle (bspcoord[check[0]], bspcoord[check[1]]); angle1 = PointToPseudoAngle (bspcoord[check[0]], bspcoord[check[1]]);
angle2 = R_PointToPseudoAngle (bspcoord[check[2]], bspcoord[check[3]]); angle2 = PointToPseudoAngle (bspcoord[check[2]], bspcoord[check[3]]);
return SafeCheckRange(angle2, angle1); return SafeCheckRange(angle2, angle1);
} }

View file

@ -6,14 +6,6 @@
#include "r_utility.h" #include "r_utility.h"
#include "memarena.h" #include "memarena.h"
angle_t R_PointToPseudoAngle(double x, double y);
// Used to speed up angle calculations during clipping
inline angle_t vertex_t::GetClipAngle()
{
return R_PointToPseudoAngle(p.X, p.Y);
}
class ClipNode class ClipNode
{ {
friend class Clipper; friend class Clipper;
@ -37,6 +29,7 @@ class Clipper
ClipNode * clipnodes = nullptr; ClipNode * clipnodes = nullptr;
ClipNode * cliphead = nullptr; ClipNode * cliphead = nullptr;
ClipNode * silhouette = nullptr; // will be preserved even when RemoveClipRange is called ClipNode * silhouette = nullptr; // will be preserved even when RemoveClipRange is called
const FRenderViewpoint *viewpoint = nullptr;
bool blocked = false; bool blocked = false;
static angle_t AngleToPseudo(angle_t ang); static angle_t AngleToPseudo(angle_t ang);
@ -79,6 +72,11 @@ public:
return c; return c;
} }
void SetViewpoint(const FRenderViewpoint &vp)
{
viewpoint = &vp;
}
void SetSilhouette(); void SetSilhouette();
bool SafeCheckRange(angle_t startAngle, angle_t endAngle) bool SafeCheckRange(angle_t startAngle, angle_t endAngle)
@ -106,6 +104,13 @@ public:
} }
} }
void SafeAddClipRange(const vertex_t *v1, const vertex_t *v2)
{
angle_t a2 = PointToPseudoAngle(v1->p.X, v1->p.Y);
angle_t a1 = PointToPseudoAngle(v2->p.X, v2->p.Y);
SafeAddClipRange(a1,a2);
}
void SafeAddClipRangeRealAngles(angle_t startangle, angle_t endangle) void SafeAddClipRangeRealAngles(angle_t startangle, angle_t endangle)
{ {
SafeAddClipRange(AngleToPseudo(startangle), AngleToPseudo(endangle)); SafeAddClipRange(AngleToPseudo(startangle), AngleToPseudo(endangle));
@ -142,12 +147,14 @@ public:
return blocked; return blocked;
} }
angle_t PointToPseudoAngle(double x, double y);
bool CheckBox(const float *bspcoord); bool CheckBox(const float *bspcoord);
// Used to speed up angle calculations during clipping // Used to speed up angle calculations during clipping
inline angle_t GetClipAngle(vertex_t *v) inline angle_t GetClipAngle(vertex_t *v)
{ {
return unsigned(v->angletime) == starttime ? v->viewangle : (v->angletime = starttime, v->viewangle = R_PointToPseudoAngle(v->p.X, v->p.Y)); return unsigned(v->angletime) == starttime ? v->viewangle : (v->angletime = starttime, v->viewangle = PointToPseudoAngle(v->p.X, v->p.Y));
} }
}; };

View file

@ -180,8 +180,6 @@ struct vertex_t
{ {
p.Zero(); p.Zero();
} }
angle_t GetClipAngle();
}; };
// Forward of LineDefs, for Sectors. // Forward of LineDefs, for Sectors.