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->mVBO = GLRenderer->mVBO;
di->mClipper = &staticClipper;
di->mClipper->SetViewpoint(r_viewpoint);
staticClipper.Clear();
di->FixedColormap = drawer->FixedColormap;
di->StartScene();

View file

@ -941,9 +941,7 @@ void GLMirrorPortal::DrawContents(FDrawInfo *di)
angle_t af = drawer->FrustumAngle();
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();
angle_t a1 = linedef->v2->GetClipAngle();
di->mClipper->SafeAddClipRange(a1,a2);
di->mClipper->SafeAddClipRange(linedef->v1, linedef->v2);
gl_RenderState.SetClipLine(linedef);
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 vecy = y - r_viewpoint.Pos.Y;
double vecx = x - viewpoint->Pos.X;
double vecy = y - viewpoint->Pos.Y;
if (vecx == 0 && vecy == 0)
{
@ -427,14 +427,15 @@ bool Clipper::CheckBox(const float *bspcoord)
// Find the corners of the box
// that define the edges from current viewpoint.
boxpos = (r_viewpoint.Pos.X <= bspcoord[BOXLEFT] ? 0 : r_viewpoint.Pos.X < bspcoord[BOXRIGHT ] ? 1 : 2) +
(r_viewpoint.Pos.Y >= bspcoord[BOXTOP ] ? 0 : r_viewpoint.Pos.Y > bspcoord[BOXBOTTOM] ? 4 : 8);
auto &vp = viewpoint;
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;
check = checkcoord[boxpos];
angle1 = R_PointToPseudoAngle (bspcoord[check[0]], bspcoord[check[1]]);
angle2 = R_PointToPseudoAngle (bspcoord[check[2]], bspcoord[check[3]]);
angle1 = PointToPseudoAngle (bspcoord[check[0]], bspcoord[check[1]]);
angle2 = PointToPseudoAngle (bspcoord[check[2]], bspcoord[check[3]]);
return SafeCheckRange(angle2, angle1);
}

View file

@ -6,14 +6,6 @@
#include "r_utility.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
{
friend class Clipper;
@ -37,6 +29,7 @@ class Clipper
ClipNode * clipnodes = nullptr;
ClipNode * cliphead = nullptr;
ClipNode * silhouette = nullptr; // will be preserved even when RemoveClipRange is called
const FRenderViewpoint *viewpoint = nullptr;
bool blocked = false;
static angle_t AngleToPseudo(angle_t ang);
@ -78,6 +71,11 @@ public:
c->next = c->prev = NULL;
return c;
}
void SetViewpoint(const FRenderViewpoint &vp)
{
viewpoint = &vp;
}
void SetSilhouette();
@ -105,6 +103,13 @@ public:
AddClipRange(startangle, endangle);
}
}
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)
{
@ -141,13 +146,15 @@ public:
{
return blocked;
}
angle_t PointToPseudoAngle(double x, double y);
bool CheckBox(const float *bspcoord);
// Used to speed up angle calculations during clipping
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();
}
angle_t GetClipAngle();
};
// Forward of LineDefs, for Sectors.