Mark FWallTmapVals members as private and make FWallTmapVals part of wallsetup

This commit is contained in:
Magnus Norddahl 2019-11-09 02:41:37 +01:00
parent 7fae5ea905
commit 370c185415
4 changed files with 64 additions and 69 deletions

View file

@ -109,21 +109,7 @@ namespace swrenderer
if (!renderportal->CurrentPortalInSkybox && renderportal->CurrentPortal && P_ClipLineToPortal(line->linedef, renderportal->CurrentPortal->dst, Thread->Viewport->viewpoint.Pos)) if (!renderportal->CurrentPortalInSkybox && renderportal->CurrentPortal && P_ClipLineToPortal(line->linedef, renderportal->CurrentPortal->dst, Thread->Viewport->viewpoint.Pos))
return; return;
vertex_t *v1 = line->linedef->v1; WallT.InitFromLine(Thread, line);
vertex_t *v2 = line->linedef->v2;
if ((v1 == line->v1 && v2 == line->v2) || (v2 == line->v1 && v1 == line->v2))
{ // The seg is the entire wall.
WallT.InitFromWallCoords(Thread, &WallC);
}
else
{ // The seg is only part of the wall.
if (line->linedef->sidedef[0] != line->sidedef)
{
swapvalues(v1, v2);
}
WallT.InitFromLine(Thread, v1->fPos() - Thread->Viewport->viewpoint.Pos, v2->fPos() - Thread->Viewport->viewpoint.Pos);
}
mFrontCeilingZ1 = mFrontSector->ceilingplane.ZatPoint(line->v1); mFrontCeilingZ1 = mFrontSector->ceilingplane.ZatPoint(line->v1);
mFrontFloorZ1 = mFrontSector->floorplane.ZatPoint(line->v1); mFrontFloorZ1 = mFrontSector->floorplane.ZatPoint(line->v1);
@ -1253,48 +1239,4 @@ namespace swrenderer
return sx2 <= sx1; return sx2 <= sx1;
} }
/////////////////////////////////////////////////////////////////////////
void FWallTmapVals::InitFromWallCoords(RenderThread *thread, const FWallCoords *wallc)
{
const FVector2 *left = &wallc->tleft;
const FVector2 *right = &wallc->tright;
RenderPortal *renderportal = thread->Portal.get();
if (renderportal->MirrorFlags & RF_XFLIP)
{
swapvalues(left, right);
}
UoverZorg = left->X * thread->Viewport->CenterX;
UoverZstep = -left->Y;
InvZorg = (left->X - right->X) * thread->Viewport->CenterX;
InvZstep = right->Y - left->Y;
}
void FWallTmapVals::InitFromLine(RenderThread *thread, const DVector2 &left, const DVector2 &right)
{
// Coordinates should have already had viewx,viewy subtracted
auto viewport = thread->Viewport.get();
double fullx1 = left.X * viewport->viewpoint.Sin - left.Y * viewport->viewpoint.Cos;
double fullx2 = right.X * viewport->viewpoint.Sin - right.Y * viewport->viewpoint.Cos;
double fully1 = left.X * viewport->viewpoint.TanCos + left.Y * viewport->viewpoint.TanSin;
double fully2 = right.X * viewport->viewpoint.TanCos + right.Y * viewport->viewpoint.TanSin;
RenderPortal *renderportal = thread->Portal.get();
if (renderportal->MirrorFlags & RF_XFLIP)
{
fullx1 = -fullx1;
fullx2 = -fullx2;
}
UoverZorg = float(fullx1 * viewport->CenterX);
UoverZstep = float(-fully1);
InvZorg = float((fullx1 - fullx2) * viewport->CenterX);
InvZstep = float(fully2 - fully1);
}
} }

View file

@ -50,15 +50,6 @@ namespace swrenderer
bool Init(RenderThread *thread, const DVector2 &pt1, const DVector2 &pt2, double too_close); bool Init(RenderThread *thread, const DVector2 &pt1, const DVector2 &pt2, double too_close);
}; };
struct FWallTmapVals
{
float UoverZorg, UoverZstep;
float InvZorg, InvZstep;
void InitFromWallCoords(RenderThread *thread, const FWallCoords *wallc);
void InitFromLine(RenderThread *thread, const DVector2 &left, const DVector2 &right);
};
struct WallPartTexture struct WallPartTexture
{ {
fixed_t TextureOffsetU; fixed_t TextureOffsetU;

View file

@ -170,6 +170,57 @@ namespace swrenderer
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
void FWallTmapVals::InitFromWallCoords(RenderThread* thread, const FWallCoords* wallc)
{
const FVector2* left = &wallc->tleft;
const FVector2* right = &wallc->tright;
if (thread->Portal->MirrorFlags & RF_XFLIP)
{
swapvalues(left, right);
}
UoverZorg = left->X * thread->Viewport->CenterX;
UoverZstep = -left->Y;
InvZorg = (left->X - right->X) * thread->Viewport->CenterX;
InvZstep = right->Y - left->Y;
}
void FWallTmapVals::InitFromLine(RenderThread* thread, seg_t* line)
{
auto viewport = thread->Viewport.get();
auto renderportal = thread->Portal.get();
vertex_t* v1 = line->linedef->v1;
vertex_t* v2 = line->linedef->v2;
if (line->linedef->sidedef[0] != line->sidedef)
{
swapvalues(v1, v2);
}
DVector2 left = v1->fPos() - viewport->viewpoint.Pos;
DVector2 right = v2->fPos() - viewport->viewpoint.Pos;
double viewspaceX1 = left.X * viewport->viewpoint.Sin - left.Y * viewport->viewpoint.Cos;
double viewspaceX2 = right.X * viewport->viewpoint.Sin - right.Y * viewport->viewpoint.Cos;
double viewspaceY1 = left.X * viewport->viewpoint.TanCos + left.Y * viewport->viewpoint.TanSin;
double viewspaceY2 = right.X * viewport->viewpoint.TanCos + right.Y * viewport->viewpoint.TanSin;
if (renderportal->MirrorFlags & RF_XFLIP)
{
viewspaceX1 = -viewspaceX1;
viewspaceX2 = -viewspaceX2;
}
UoverZorg = float(viewspaceX1 * viewport->CenterX);
UoverZstep = float(-viewspaceY1);
InvZorg = float((viewspaceX1 - viewspaceX2) * viewport->CenterX);
InvZstep = float(viewspaceY2 - viewspaceY1);
}
/////////////////////////////////////////////////////////////////////////
void ProjectedWallTexcoords::Project(RenderViewport *viewport, double walxrepeat, int x1, int x2, const FWallTmapVals &WallT, bool flipx) void ProjectedWallTexcoords::Project(RenderViewport *viewport, double walxrepeat, int x1, int x2, const FWallTmapVals &WallT, bool flipx)
{ {
float uOverZ = WallT.UoverZorg + WallT.UoverZstep * (float)(x1 + 0.5 - viewport->CenterX); float uOverZ = WallT.UoverZorg + WallT.UoverZstep * (float)(x1 + 0.5 - viewport->CenterX);

View file

@ -28,7 +28,6 @@
namespace swrenderer namespace swrenderer
{ {
struct FWallCoords; struct FWallCoords;
struct FWallTmapVals;
enum class ProjectedWallCull enum class ProjectedWallCull
{ {
@ -47,6 +46,18 @@ namespace swrenderer
ProjectedWallCull Project(RenderViewport *viewport, double z, const FWallCoords *wallc); ProjectedWallCull Project(RenderViewport *viewport, double z, const FWallCoords *wallc);
}; };
struct FWallTmapVals
{
void InitFromWallCoords(RenderThread* thread, const FWallCoords* wallc);
void InitFromLine(RenderThread* thread, seg_t* line);
private:
float UoverZorg, UoverZstep;
float InvZorg, InvZstep;
friend class ProjectedWallTexcoords;
};
class ProjectedWallTexcoords class ProjectedWallTexcoords
{ {
public: public: