Move r_bsp into a class

This commit is contained in:
Magnus Norddahl 2017-01-04 15:39:47 +01:00
parent c396e7f949
commit 28732d63d2
12 changed files with 758 additions and 777 deletions

View file

@ -134,7 +134,7 @@ namespace swrenderer
// kg3D - its fake, no transfer_heights // kg3D - its fake, no transfer_heights
if (!(fake3D & FAKE3D_FAKEBACK)) if (!(fake3D & FAKE3D_FAKEBACK))
{ // killough 3/8/98, 4/4/98: hack for invisible ceilings / deep water { // killough 3/8/98, 4/4/98: hack for invisible ceilings / deep water
backsector = R_FakeFlat(backsector, &tempsec, nullptr, nullptr, curline, WallC.sx1, WallC.sx2, rw_frontcz1, rw_frontcz2); backsector = RenderBSP::Instance()->FakeFlat(backsector, &tempsec, nullptr, nullptr, curline, WallC.sx1, WallC.sx2, rw_frontcz1, rw_frontcz2);
} }
doorclosed = false; // killough 4/16/98 doorclosed = false; // killough 4/16/98
@ -447,7 +447,7 @@ namespace swrenderer
// kg3D - backup for mid and fake walls // kg3D - backup for mid and fake walls
draw_segment->bkup = R_NewOpening(stop - start); draw_segment->bkup = R_NewOpening(stop - start);
memcpy(openings + draw_segment->bkup, &ceilingclip[start], sizeof(short)*(stop - start)); memcpy(openings + draw_segment->bkup, &RenderBSP::Instance()->ceilingclip[start], sizeof(short)*(stop - start));
draw_segment->bFogBoundary = IsFogBoundary(frontsector, backsector); draw_segment->bFogBoundary = IsFogBoundary(frontsector, backsector);
if (sidedef->GetTexture(side_t::mid).isValid() || draw_segment->bFakeBoundary) if (sidedef->GetTexture(side_t::mid).isValid() || draw_segment->bFakeBoundary)
@ -559,13 +559,13 @@ namespace swrenderer
if (((draw_segment->silhouette & SIL_TOP) || maskedtexture) && draw_segment->sprtopclip == -1) if (((draw_segment->silhouette & SIL_TOP) || maskedtexture) && draw_segment->sprtopclip == -1)
{ {
draw_segment->sprtopclip = R_NewOpening(stop - start); draw_segment->sprtopclip = R_NewOpening(stop - start);
memcpy(openings + draw_segment->sprtopclip, &ceilingclip[start], sizeof(short)*(stop - start)); memcpy(openings + draw_segment->sprtopclip, &RenderBSP::Instance()->ceilingclip[start], sizeof(short)*(stop - start));
} }
if (((draw_segment->silhouette & SIL_BOTTOM) || maskedtexture) && draw_segment->sprbottomclip == -1) if (((draw_segment->silhouette & SIL_BOTTOM) || maskedtexture) && draw_segment->sprbottomclip == -1)
{ {
draw_segment->sprbottomclip = R_NewOpening(stop - start); draw_segment->sprbottomclip = R_NewOpening(stop - start);
memcpy(openings + draw_segment->sprbottomclip, &floorclip[start], sizeof(short)*(stop - start)); memcpy(openings + draw_segment->sprbottomclip, &RenderBSP::Instance()->floorclip[start], sizeof(short)*(stop - start));
} }
if (maskedtexture && curline->sidedef->GetTexture(side_t::mid).isValid()) if (maskedtexture && curline->sidedef->GetTexture(side_t::mid).isValid())
@ -960,6 +960,8 @@ namespace swrenderer
R_SetColorMapLight(fixedcolormap, 0, 0); R_SetColorMapLight(fixedcolormap, 0, 0);
// clip wall to the floor and ceiling // clip wall to the floor and ceiling
auto ceilingclip = RenderBSP::Instance()->ceilingclip;
auto floorclip = RenderBSP::Instance()->floorclip;
for (x = x1; x < x2; ++x) for (x = x1; x < x2; ++x)
{ {
if (walltop[x] < ceilingclip[x]) if (walltop[x] < ceilingclip[x])

View file

@ -474,12 +474,7 @@ namespace swrenderer
if (pl->left >= pl->right) if (pl->left >= pl->right)
return; return;
if (r_drawflat) // no texture mapping if (pl->picnum == skyflatnum) // sky flat
{
drawerargs::ds_color += 4;
R_DrawColoredPlane(pl);
}
else if (pl->picnum == skyflatnum) // sky flat
{ {
R_DrawSkyPlane(pl); R_DrawSkyPlane(pl);
} }
@ -506,7 +501,7 @@ namespace swrenderer
basecolormap = pl->colormap; basecolormap = pl->colormap;
if (r_drawflat || (!pl->height.isSlope() && !tilt)) if (!pl->height.isSlope() && !tilt)
{ {
R_DrawNormalPlane(pl, xscale, yscale, alpha, additive, masked); R_DrawNormalPlane(pl, xscale, yscale, alpha, additive, masked);
} }

View file

@ -103,9 +103,7 @@ static void R_ShutdownRenderer();
// EXTERNAL DATA DECLARATIONS ---------------------------------------------- // EXTERNAL DATA DECLARATIONS ----------------------------------------------
extern short *openings; extern short *openings;
extern bool r_fakingunderwater;
extern int fuzzviewheight; extern int fuzzviewheight;
extern subsector_t *InSubsector;
// PRIVATE DATA DECLARATIONS ----------------------------------------------- // PRIVATE DATA DECLARATIONS -----------------------------------------------
@ -555,24 +553,13 @@ void R_RenderActorView (AActor *actor, bool dontmaplines)
R_ClearSprites (); R_ClearSprites ();
// opening / clipping determination // opening / clipping determination
// [RH] clip ceiling to console bottom RenderBSP::Instance()->ClearClip();
fillshort(floorclip, viewwidth, viewheight);
fillshort(ceilingclip, viewwidth, !screen->Accel2D && ConBottom > viewwindowy && !bRenderingToCanvas ? (ConBottom - viewwindowy) : 0);
R_FreeOpenings(); R_FreeOpenings();
NetUpdate (); NetUpdate ();
// [RH] Show off segs if r_drawflat is 1 colfunc = basecolfunc;
if (r_drawflat) spanfunc = &SWPixelFormatDrawers::DrawSpan;
{
colfunc = &SWPixelFormatDrawers::FillColumn;
spanfunc = &SWPixelFormatDrawers::FillSpan;
}
else
{
colfunc = basecolfunc;
spanfunc = &SWPixelFormatDrawers::DrawSpan;
}
WindowLeft = 0; WindowLeft = 0;
WindowRight = viewwidth; WindowRight = viewwidth;
@ -583,7 +570,7 @@ void R_RenderActorView (AActor *actor, bool dontmaplines)
r_dontmaplines = dontmaplines; r_dontmaplines = dontmaplines;
// [RH] Hack to make windows into underwater areas possible // [RH] Hack to make windows into underwater areas possible
r_fakingunderwater = false; RenderBSP::Instance()->ResetFakingUnderwater();
// [RH] Setup particles for this frame // [RH] Setup particles for this frame
P_FindParticleSubsectors (); P_FindParticleSubsectors ();
@ -597,7 +584,7 @@ void R_RenderActorView (AActor *actor, bool dontmaplines)
} }
// Link the polyobjects right before drawing the scene to reduce the amounts of calls to this function // Link the polyobjects right before drawing the scene to reduce the amounts of calls to this function
PO_LinkToSubsectors(); PO_LinkToSubsectors();
R_RenderScene(); RenderBSP::Instance()->RenderScene();
R_3D_ResetClip(); // reset clips (floor/ceiling) R_3D_ResetClip(); // reset clips (floor/ceiling)
camera->renderflags = savedflags; camera->renderflags = savedflags;
WallCycles.Unclock(); WallCycles.Unclock();

View file

@ -484,6 +484,6 @@ void FSoftwareRenderer::RenderTextureView (FCanvasTexture *tex, AActor *viewpoin
sector_t *FSoftwareRenderer::FakeFlat(sector_t *sec, sector_t *tempsec, int *floorlightlevel, int *ceilinglightlevel) sector_t *FSoftwareRenderer::FakeFlat(sector_t *sec, sector_t *tempsec, int *floorlightlevel, int *ceilinglightlevel)
{ {
return R_FakeFlat(sec, tempsec, floorlightlevel, ceilinglightlevel, nullptr, 0, 0, 0, 0); return RenderBSP::Instance()->FakeFlat(sec, tempsec, floorlightlevel, ceilinglightlevel, nullptr, 0, 0, 0, 0);
} }

View file

@ -98,8 +98,8 @@ void R_3D_NewClip()
curr = (ClipStack*)M_Malloc(sizeof(ClipStack)); curr = (ClipStack*)M_Malloc(sizeof(ClipStack));
curr->next = 0; curr->next = 0;
memcpy(curr->floorclip, floorclip, sizeof(short) * MAXWIDTH); memcpy(curr->floorclip, RenderBSP::Instance()->floorclip, sizeof(short) * MAXWIDTH);
memcpy(curr->ceilingclip, ceilingclip, sizeof(short) * MAXWIDTH); memcpy(curr->ceilingclip, RenderBSP::Instance()->ceilingclip, sizeof(short) * MAXWIDTH);
curr->ffloor = fakeFloor; curr->ffloor = fakeFloor;
assert(fakeFloor->floorclip == NULL); assert(fakeFloor->floorclip == NULL);
assert(fakeFloor->ceilingclip == NULL); assert(fakeFloor->ceilingclip == NULL);

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,3 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
// $Id:$
// //
// Copyright (C) 1993-1996 by id Software, Inc. // Copyright (C) 1993-1996 by id Software, Inc.
// //
@ -14,47 +10,57 @@
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
// for more details. // for more details.
// //
// DESCRIPTION:
// Refresh module, BSP traversal and handling.
//
//-----------------------------------------------------------------------------
#pragma once
#ifndef __R_BSP__
#define __R_BSP__
#include "tarray.h" #include "tarray.h"
#include <stddef.h> #include <stddef.h>
#include "r_defs.h" #include "r_defs.h"
#include "swrenderer/line/r_line.h"
EXTERN_CVAR (Bool, r_drawflat) // [RH] Don't texture segs?
namespace swrenderer namespace swrenderer
{ {
struct visplane_t;
struct visplane_t; // The 3072 below is just an arbitrary value picked to avoid
// drawing lines the player is too close to that would overflow
// the texture calculations.
#define TOO_CLOSE_Z (3072.0 / (1<<12))
// The 3072 below is just an arbitrary value picked to avoid enum
// drawing lines the player is too close to that would overflow {
// the texture calculations. FAKED_Center,
#define TOO_CLOSE_Z (3072.0 / (1<<12)) FAKED_BelowFloor,
FAKED_AboveCeiling
};
enum class RenderBSP
{ {
FAKED_Center, public:
FAKED_BelowFloor, static RenderBSP *Instance();
FAKED_AboveCeiling
};
void R_RenderScene(); void ClearClip();
void R_RenderBSPNode (void *node); void RenderScene();
// killough 4/13/98: fake floors/ceilings for deep water / fake ceilings: void ResetFakingUnderwater() { r_fakingunderwater = false; }
sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, int *floorlightlevel, int *ceilinglightlevel, seg_t *backline, int backx1, int backx2, double frontcz1, double frontcz2); sector_t *FakeFlat(sector_t *sec, sector_t *tempsec, int *floorlightlevel, int *ceilinglightlevel, seg_t *backline, int backx1, int backx2, double frontcz1, double frontcz2);
extern short floorclip[MAXWIDTH]; short floorclip[MAXWIDTH];
extern short ceilingclip[MAXWIDTH]; short ceilingclip[MAXWIDTH];
private:
void RenderBSPNode(void *node);
void RenderSubsector(subsector_t *sub);
bool CheckBBox(float *bspcoord);
void AddPolyobjs(subsector_t *sub);
void FakeDrawLoop(subsector_t *sub, visplane_t *floorplane, visplane_t *ceilingplane);
subsector_t *InSubsector;
sector_t *frontsector;
uint8_t FakeSide;
bool r_fakingunderwater;
SWRenderLine renderline;
};
} }
#endif

View file

@ -204,6 +204,8 @@ namespace swrenderer
WindowLeft = pl->left; WindowLeft = pl->left;
WindowRight = pl->right; WindowRight = pl->right;
auto ceilingclip = RenderBSP::Instance()->ceilingclip;
auto floorclip = RenderBSP::Instance()->floorclip;
for (i = pl->left; i < pl->right; i++) for (i = pl->left; i < pl->right; i++)
{ {
if (pl->top[i] == 0x7fff) if (pl->top[i] == 0x7fff)
@ -249,7 +251,7 @@ namespace swrenderer
viewposStack.Push(ViewPos); viewposStack.Push(ViewPos);
visplaneStack.Push(pl); visplaneStack.Push(pl);
R_RenderScene(); RenderBSP::Instance()->RenderScene();
R_3D_ResetClip(); // reset clips (floor/ceiling) R_3D_ResetClip(); // reset clips (floor/ceiling)
R_DrawPlanes(); R_DrawPlanes();
@ -464,11 +466,13 @@ namespace swrenderer
R_3D_EnterSkybox(); // push 3D floor height map R_3D_EnterSkybox(); // push 3D floor height map
CurrentPortalInSkybox = false; // first portal in a skybox should set this variable to false for proper clipping in skyboxes. CurrentPortalInSkybox = false; // first portal in a skybox should set this variable to false for proper clipping in skyboxes.
// first pass, set clipping // first pass, set clipping
auto ceilingclip = RenderBSP::Instance()->ceilingclip;
auto floorclip = RenderBSP::Instance()->floorclip;
memcpy(ceilingclip + pds->x1, &pds->ceilingclip[0], pds->len * sizeof(*ceilingclip)); memcpy(ceilingclip + pds->x1, &pds->ceilingclip[0], pds->len * sizeof(*ceilingclip));
memcpy(floorclip + pds->x1, &pds->floorclip[0], pds->len * sizeof(*floorclip)); memcpy(floorclip + pds->x1, &pds->floorclip[0], pds->len * sizeof(*floorclip));
R_RenderScene(); RenderBSP::Instance()->RenderScene();
R_3D_ResetClip(); // reset clips (floor/ceiling) R_3D_ResetClip(); // reset clips (floor/ceiling)
if (!savedvisibility && camera) camera->renderflags &= ~RF_INVISIBLE; if (!savedvisibility && camera) camera->renderflags &= ~RF_INVISIBLE;

View file

@ -162,7 +162,7 @@ namespace swrenderer
} }
// killough 4/13/98: get correct lightlevel for 2s normal textures // killough 4/13/98: get correct lightlevel for 2s normal textures
sec = R_FakeFlat(frontsector, &tempsec, nullptr, nullptr, nullptr, 0, 0, 0, 0); sec = RenderBSP::Instance()->FakeFlat(frontsector, &tempsec, nullptr, nullptr, nullptr, 0, 0, 0, 0);
basecolormap = sec->ColorMap; // [RH] Set basecolormap basecolormap = sec->ColorMap; // [RH] Set basecolormap

View file

@ -170,7 +170,7 @@ namespace swrenderer
else if (pass == 0) else if (pass == 0)
{ {
mceilingclip = walltop; mceilingclip = walltop;
mfloorclip = ceilingclip; mfloorclip = RenderBSP::Instance()->ceilingclip;
needrepeat = 1; needrepeat = 1;
} }
else else
@ -186,7 +186,7 @@ namespace swrenderer
goto done; goto done;
} }
mceilingclip = walltop; mceilingclip = walltop;
mfloorclip = ceilingclip; mfloorclip = RenderBSP::Instance()->ceilingclip;
break; break;
case RF_CLIPMID: case RF_CLIPMID:
@ -203,7 +203,7 @@ namespace swrenderer
{ {
goto done; goto done;
} }
mceilingclip = floorclip; mceilingclip = RenderBSP::Instance()->floorclip;
mfloorclip = wallbottom; mfloorclip = wallbottom;
break; break;
} }
@ -296,7 +296,7 @@ namespace swrenderer
// If this sprite is RF_CLIPFULL on a two-sided line, needrepeat will // If this sprite is RF_CLIPFULL on a two-sided line, needrepeat will
// be set 1 if we need to draw on the lower wall. In all other cases, // be set 1 if we need to draw on the lower wall. In all other cases,
// needrepeat will be 0, and the while will fail. // needrepeat will be 0, and the while will fail.
mceilingclip = floorclip; mceilingclip = RenderBSP::Instance()->floorclip;
mfloorclip = wallbottom; mfloorclip = wallbottom;
R_FinishSetPatchStyle(); R_FinishSetPatchStyle();
} while (needrepeat--); } while (needrepeat--);

View file

@ -114,6 +114,8 @@ namespace swrenderer
// entered, we don't need to clip it to drawsegs like a normal sprite. // entered, we don't need to clip it to drawsegs like a normal sprite.
// Clip particles behind walls. // Clip particles behind walls.
auto ceilingclip = RenderBSP::Instance()->ceilingclip;
auto floorclip = RenderBSP::Instance()->floorclip;
if (y1 < ceilingclip[x1]) y1 = ceilingclip[x1]; if (y1 < ceilingclip[x1]) y1 = ceilingclip[x1];
if (y1 < ceilingclip[x2 - 1]) y1 = ceilingclip[x2 - 1]; if (y1 < ceilingclip[x2 - 1]) y1 = ceilingclip[x2 - 1];
if (y2 >= floorclip[x1]) y2 = floorclip[x1] - 1; if (y2 >= floorclip[x1]) y2 = floorclip[x1] - 1;

View file

@ -123,7 +123,7 @@ namespace swrenderer
else else
{ // This used to use camera->Sector but due to interpolation that can be incorrect { // This used to use camera->Sector but due to interpolation that can be incorrect
// when the interpolated viewpoint is in a different sector than the camera. // when the interpolated viewpoint is in a different sector than the camera.
sec = R_FakeFlat(viewsector, &tempsec, &floorlight, &ceilinglight, nullptr, 0, 0, 0, 0); sec = RenderBSP::Instance()->FakeFlat(viewsector, &tempsec, &floorlight, &ceilinglight, nullptr, 0, 0, 0, 0);
// [RH] set basecolormap // [RH] set basecolormap
basecolormap = sec->ColorMap; basecolormap = sec->ColorMap;