Rename vissprite_t to VisibleSprite, convert it into a base class and lower all variables if possible. Remove unused fields and unions.

This commit is contained in:
Magnus Norddahl 2017-01-16 05:26:22 +01:00
parent 57d8b0e34c
commit 55131a7a6d
16 changed files with 150 additions and 148 deletions

View file

@ -19,8 +19,6 @@ EXTERN_CVAR(Bool, r_dynlights);
namespace swrenderer namespace swrenderer
{ {
struct vissprite_t;
struct ShadeConstants struct ShadeConstants
{ {
uint16_t light_alpha; uint16_t light_alpha;

View file

@ -90,7 +90,7 @@ namespace swrenderer
} }
} }
bool RenderTranslucentPass::ClipSpriteColumnWithPortals(int x, vissprite_t* spr) bool RenderTranslucentPass::ClipSpriteColumnWithPortals(int x, VisibleSprite *spr)
{ {
RenderPortal *renderportal = RenderPortal::Instance(); RenderPortal *renderportal = RenderPortal::Instance();
@ -118,7 +118,7 @@ namespace swrenderer
return false; return false;
} }
void RenderTranslucentPass::DrawSprite(vissprite_t *spr) void RenderTranslucentPass::DrawSprite(VisibleSprite *spr)
{ {
static short clipbot[MAXWIDTH]; static short clipbot[MAXWIDTH];
static short cliptop[MAXWIDTH]; static short cliptop[MAXWIDTH];
@ -136,12 +136,13 @@ namespace swrenderer
Clip3DFloors *clip3d = Clip3DFloors::Instance(); Clip3DFloors *clip3d = Clip3DFloors::Instance();
// [RH] Check for particles // [RH] Check for particles
if (!spr->bIsVoxel && spr->pic == nullptr) if (spr->IsParticle())
{ {
// kg3D - reject invisible parts // kg3D - reject invisible parts
if ((clip3d->fake3D & FAKE3D_CLIPBOTTOM) && spr->gpos.Z <= clip3d->sclipBottom) return; if ((clip3d->fake3D & FAKE3D_CLIPBOTTOM) && spr->gpos.Z <= clip3d->sclipBottom) return;
if ((clip3d->fake3D & FAKE3D_CLIPTOP) && spr->gpos.Z >= clip3d->sclipTop) return; if ((clip3d->fake3D & FAKE3D_CLIPTOP) && spr->gpos.Z >= clip3d->sclipTop) return;
RenderParticle::Render(spr);
spr->Render(nullptr, nullptr, 0, 0);
return; return;
} }
@ -258,7 +259,7 @@ namespace swrenderer
double scale = InvZtoScale * spr->idepth; double scale = InvZtoScale * spr->idepth;
double hzb = DBL_MIN, hzt = DBL_MAX; double hzb = DBL_MIN, hzt = DBL_MAX;
if (spr->bIsVoxel && spr->floorclip != 0) if (spr->IsVoxel() && spr->floorclip != 0)
{ {
hzb = spr->gzb; hzb = spr->gzb;
} }
@ -272,7 +273,7 @@ namespace swrenderer
if (spr->FakeFlatStat == WaterFakeSide::BelowFloor) if (spr->FakeFlatStat == WaterFakeSide::BelowFloor)
{ // seen below floor: clip top { // seen below floor: clip top
if (!spr->bIsVoxel && h > topclip) if (!spr->IsVoxel() && h > topclip)
{ {
topclip = short(MIN(h, viewheight)); topclip = short(MIN(h, viewheight));
} }
@ -280,7 +281,7 @@ namespace swrenderer
} }
else else
{ // seen in the middle: clip bottom { // seen in the middle: clip bottom
if (!spr->bIsVoxel && h < botclip) if (!spr->IsVoxel() && h < botclip)
{ {
botclip = MAX<short>(0, h); botclip = MAX<short>(0, h);
} }
@ -294,7 +295,7 @@ namespace swrenderer
if (spr->FakeFlatStat == WaterFakeSide::AboveCeiling) if (spr->FakeFlatStat == WaterFakeSide::AboveCeiling)
{ // seen above ceiling: clip bottom { // seen above ceiling: clip bottom
if (!spr->bIsVoxel && h < botclip) if (!spr->IsVoxel() && h < botclip)
{ {
botclip = MAX<short>(0, h); botclip = MAX<short>(0, h);
} }
@ -302,7 +303,7 @@ namespace swrenderer
} }
else else
{ // seen in the middle: clip top { // seen in the middle: clip top
if (!spr->bIsVoxel && h > topclip) if (!spr->IsVoxel() && h > topclip)
{ {
topclip = MIN(h, viewheight); topclip = MIN(h, viewheight);
} }
@ -311,7 +312,7 @@ namespace swrenderer
} }
} }
// killough 3/27/98: end special clipping for deep water / fake ceilings // killough 3/27/98: end special clipping for deep water / fake ceilings
else if (!spr->bIsVoxel && spr->floorclip) else if (!spr->IsVoxel() && spr->floorclip)
{ // [RH] Move floorclip stuff from R_DrawVisSprite to here { // [RH] Move floorclip stuff from R_DrawVisSprite to here
//int clip = ((FLOAT2FIXED(CenterY) - FixedMul (spr->texturemid - (spr->pic->GetHeight() << FRACBITS) + spr->floorclip, spr->yscale)) >> FRACBITS); //int clip = ((FLOAT2FIXED(CenterY) - FixedMul (spr->texturemid - (spr->pic->GetHeight() << FRACBITS) + spr->floorclip, spr->yscale)) >> FRACBITS);
int clip = xs_RoundToInt(CenterY - (spr->texturemid - spr->pic->GetHeight() + spr->floorclip) * spr->yscale); int clip = xs_RoundToInt(CenterY - (spr->texturemid - spr->pic->GetHeight() + spr->floorclip) * spr->yscale);
@ -323,7 +324,7 @@ namespace swrenderer
if (clip3d->fake3D & FAKE3D_CLIPBOTTOM) if (clip3d->fake3D & FAKE3D_CLIPBOTTOM)
{ {
if (!spr->bIsVoxel) if (!spr->IsVoxel())
{ {
double hz = clip3d->sclipBottom; double hz = clip3d->sclipBottom;
if (spr->fakefloor) if (spr->fakefloor)
@ -344,7 +345,7 @@ namespace swrenderer
} }
if (clip3d->fake3D & FAKE3D_CLIPTOP) if (clip3d->fake3D & FAKE3D_CLIPTOP)
{ {
if (!spr->bIsVoxel) if (!spr->IsVoxel())
{ {
double hz = clip3d->sclipTop; double hz = clip3d->sclipTop;
if (spr->fakeceiling != nullptr) if (spr->fakeceiling != nullptr)
@ -411,7 +412,7 @@ namespace swrenderer
r2 = MIN<int>(ds->x2, x2); r2 = MIN<int>(ds->x2, x2);
float neardepth, fardepth; float neardepth, fardepth;
if (!spr->bWallSprite) if (!spr->IsWallSprite())
{ {
if (ds->sz1 < ds->sz2) if (ds->sz1 < ds->sz2)
{ {
@ -425,7 +426,7 @@ namespace swrenderer
// Check if sprite is in front of draw seg: // Check if sprite is in front of draw seg:
if ((!spr->bWallSprite && neardepth > spr->depth) || ((spr->bWallSprite || fardepth > spr->depth) && if ((!spr->IsWallSprite() && neardepth > spr->depth) || ((spr->IsWallSprite() || fardepth > spr->depth) &&
(spr->gpos.Y - ds->curline->v1->fY()) * (ds->curline->v2->fX() - ds->curline->v1->fX()) - (spr->gpos.Y - ds->curline->v1->fY()) * (ds->curline->v2->fX() - ds->curline->v1->fX()) -
(spr->gpos.X - ds->curline->v1->fX()) * (ds->curline->v2->fY() - ds->curline->v1->fY()) <= 0)) (spr->gpos.X - ds->curline->v1->fX()) * (ds->curline->v2->fY() - ds->curline->v1->fY()) <= 0))
{ {
@ -475,16 +476,9 @@ namespace swrenderer
// all clipping has been performed, so draw the sprite // all clipping has been performed, so draw the sprite
if (!spr->bIsVoxel) if (!spr->IsVoxel())
{ {
if (!spr->bWallSprite) spr->Render(clipbot, cliptop, 0, 0);
{
RenderSprite::Render(spr, clipbot, cliptop);
}
else
{
RenderWallSprite::Render(spr, clipbot, cliptop);
}
} }
else else
{ {
@ -517,7 +511,7 @@ namespace swrenderer
} }
int minvoxely = spr->gzt <= hzt ? 0 : xs_RoundToInt((spr->gzt - hzt) / spr->yscale); int minvoxely = spr->gzt <= hzt ? 0 : xs_RoundToInt((spr->gzt - hzt) / spr->yscale);
int maxvoxely = spr->gzb > hzb ? INT_MAX : xs_RoundToInt((spr->gzt - hzb) / spr->yscale); int maxvoxely = spr->gzb > hzb ? INT_MAX : xs_RoundToInt((spr->gzt - hzb) / spr->yscale);
RenderVoxel::Render(spr, minvoxely, maxvoxely, cliptop, clipbot); spr->Render(cliptop, clipbot, minvoxely, maxvoxely);
} }
spr->Style.BaseColormap = colormap; spr->Style.BaseColormap = colormap;
spr->Style.ColormapNum = colormapnum; spr->Style.ColormapNum = colormapnum;

View file

@ -22,7 +22,7 @@ struct FVoxel;
namespace swrenderer namespace swrenderer
{ {
struct vissprite_t; class VisibleSprite;
struct drawseg_t; struct drawseg_t;
class RenderTranslucentPass class RenderTranslucentPass
@ -34,11 +34,11 @@ namespace swrenderer
static bool DrewAVoxel; static bool DrewAVoxel;
static bool ClipSpriteColumnWithPortals(int x, vissprite_t* spr); static bool ClipSpriteColumnWithPortals(int x, VisibleSprite *spr);
private: private:
static void CollectPortals(); static void CollectPortals();
static void DrawSprite(vissprite_t *spr); static void DrawSprite(VisibleSprite *spr);
static void DrawMaskedSingle(bool renew); static void DrawMaskedSingle(bool renew);
static TArray<drawseg_t *> portaldrawsegs; static TArray<drawseg_t *> portaldrawsegs;

View file

@ -178,7 +178,7 @@ namespace swrenderer
return; return;
// store information in a vissprite // store information in a vissprite
vissprite_t *vis = RenderMemory::NewObject<vissprite_t>(); RenderParticle *vis = RenderMemory::NewObject<RenderParticle>();
vis->CurrentPortalUniq = renderportal->CurrentPortalUniq; vis->CurrentPortalUniq = renderportal->CurrentPortalUniq;
vis->heightsec = heightsec; vis->heightsec = heightsec;
vis->xscale = FLOAT2FIXED(xscale); vis->xscale = FLOAT2FIXED(xscale);
@ -194,7 +194,6 @@ namespace swrenderer
vis->Translation = 0; vis->Translation = 0;
vis->startfrac = 255 & (particle->color >> 24); vis->startfrac = 255 & (particle->color >> 24);
vis->pic = NULL; vis->pic = NULL;
vis->bIsVoxel = false;
vis->renderflags = (short)(particle->alpha * 255.0f + 0.5f); vis->renderflags = (short)(particle->alpha * 255.0f + 0.5f);
vis->FakeFlatStat = fakeside; vis->FakeFlatStat = fakeside;
vis->floorclip = 0; vis->floorclip = 0;
@ -226,10 +225,12 @@ namespace swrenderer
VisibleSpriteList::Instance()->Push(vis); VisibleSpriteList::Instance()->Push(vis);
} }
void RenderParticle::Render(vissprite_t *vis) void RenderParticle::Render(short *cliptop, short *clipbottom, int minZ, int maxZ)
{ {
using namespace drawerargs; using namespace drawerargs;
auto vis = this;
int spacing; int spacing;
BYTE color = vis->Style.BaseColormap->Maps[vis->startfrac]; BYTE color = vis->Style.BaseColormap->Maps[vis->startfrac];
int yl = vis->y1; int yl = vis->y1;
@ -240,7 +241,7 @@ namespace swrenderer
if (ycount <= 0 || countbase <= 0) if (ycount <= 0 || countbase <= 0)
return; return;
DrawMaskedSegsBehindParticle(vis); DrawMaskedSegsBehindParticle();
uint32_t fg = LightBgra::shade_pal_index_simple(color, LightBgra::calc_light_multiplier(LIGHTSCALE(0, vis->Style.ColormapNum << FRACBITS))); uint32_t fg = LightBgra::shade_pal_index_simple(color, LightBgra::calc_light_multiplier(LIGHTSCALE(0, vis->Style.ColormapNum << FRACBITS)));
@ -275,11 +276,8 @@ namespace swrenderer
} }
} }
void RenderParticle::DrawMaskedSegsBehindParticle(const vissprite_t *vis) void RenderParticle::DrawMaskedSegsBehindParticle()
{ {
const int x1 = vis->x1;
const int x2 = vis->x2;
// Draw any masked textures behind this particle so that when the // Draw any masked textures behind this particle so that when the
// particle is drawn, it will be in front of them. // particle is drawn, it will be in front of them.
for (unsigned int p = InterestingDrawsegs.Size(); p-- > FirstInterestingDrawseg; ) for (unsigned int p = InterestingDrawsegs.Size(); p-- > FirstInterestingDrawseg; )
@ -291,10 +289,10 @@ namespace swrenderer
{ {
continue; continue;
} }
if ((ds->siz2 - ds->siz1) * ((x2 + x1) / 2 - ds->sx1) / (ds->sx2 - ds->sx1) + ds->siz1 < vis->idepth) if ((ds->siz2 - ds->siz1) * ((x2 + x1) / 2 - ds->sx1) / (ds->sx2 - ds->sx1) + ds->siz1 < idepth)
{ {
// [ZZ] only draw stuff that's inside the same portal as the particle, other portals will care for themselves // [ZZ] only draw stuff that's inside the same portal as the particle, other portals will care for themselves
if (ds->CurrentPortalUniq == vis->CurrentPortalUniq) if (ds->CurrentPortalUniq == CurrentPortalUniq)
R_RenderMaskedSegRange(ds, MAX<int>(ds->x1, x1), MIN<int>(ds->x2, x2)); R_RenderMaskedSegRange(ds, MAX<int>(ds->x1, x1), MIN<int>(ds->x2, x2));
} }
} }

View file

@ -18,13 +18,22 @@
namespace swrenderer namespace swrenderer
{ {
class RenderParticle class RenderParticle : public VisibleSprite
{ {
public: public:
static void Project(particle_t *, const sector_t *sector, int shade, WaterFakeSide fakeside, bool foggy); static void Project(particle_t *, const sector_t *sector, int shade, WaterFakeSide fakeside, bool foggy);
static void Render(vissprite_t *);
bool IsParticle() const override { return true; }
void Render(short *cliptop, short *clipbottom, int minZ, int maxZ) override;
private: private:
static void DrawMaskedSegsBehindParticle(const vissprite_t *vis); void DrawMaskedSegsBehindParticle();
fixed_t xscale;
fixed_t startfrac; // horizontal position of x1
int y1, y2;
uint32_t Translation;
uint32_t FillColor;
}; };
} }

View file

@ -72,7 +72,7 @@ namespace swrenderer
double RenderPlayerSprite::pspritexiscale; double RenderPlayerSprite::pspritexiscale;
double RenderPlayerSprite::pspriteyscale; double RenderPlayerSprite::pspriteyscale;
TArray<vissprite_t> RenderPlayerSprite::avis; TArray<RenderSprite> RenderPlayerSprite::avis;
void RenderPlayerSprite::SetupSpriteScale() void RenderPlayerSprite::SetupSpriteScale()
{ {
@ -205,7 +205,6 @@ namespace swrenderer
FTextureID picnum; FTextureID picnum;
WORD flip; WORD flip;
FTexture* tex; FTexture* tex;
vissprite_t* vis;
bool noaccel; bool noaccel;
double alpha = owner->Alpha; double alpha = owner->Alpha;
@ -273,7 +272,7 @@ namespace swrenderer
return; return;
// store information in a vissprite // store information in a vissprite
vis = &avis[vispspindex]; RenderSprite *vis = &avis[vispspindex];
vis->renderflags = owner->renderflags; vis->renderflags = owner->renderflags;
vis->floorclip = 0; vis->floorclip = 0;
@ -571,16 +570,14 @@ namespace swrenderer
short *mfloorclip = screenheightarray; short *mfloorclip = screenheightarray;
short *mceilingclip = zeroarray; short *mceilingclip = zeroarray;
RenderSprite::Render(vis, mfloorclip, mceilingclip); vis->Render(mfloorclip, mceilingclip, 0, 0);
} }
void RenderPlayerSprite::RenderRemainingPlayerSprites() void RenderPlayerSprite::RenderRemainingPlayerSprites()
{ {
for (unsigned int i = 0; i < vispspindex; i++) for (unsigned int i = 0; i < vispspindex; i++)
{ {
vissprite_t *vis; RenderSprite *vis = vispsprites[i].vis;
vis = vispsprites[i].vis;
FDynamicColormap *colormap = vispsprites[i].basecolormap; FDynamicColormap *colormap = vispsprites[i].basecolormap;
bool flip = vis->xiscale < 0; bool flip = vis->xiscale < 0;
FSpecialColormap *special = NULL; FSpecialColormap *special = NULL;

View file

@ -14,6 +14,7 @@
#pragma once #pragma once
#include "r_visiblesprite.h" #include "r_visiblesprite.h"
#include "r_sprite.h"
class DPSprite; class DPSprite;
@ -36,7 +37,7 @@ namespace swrenderer
// Used to store a psprite's drawing information if it needs to be drawn later. // Used to store a psprite's drawing information if it needs to be drawn later.
struct vispsp_t struct vispsp_t
{ {
vissprite_t *vis; RenderSprite *vis;
FDynamicColormap *basecolormap; FDynamicColormap *basecolormap;
int x1; int x1;
}; };
@ -48,6 +49,6 @@ namespace swrenderer
static double pspritexiscale; static double pspritexiscale;
static double pspriteyscale; static double pspriteyscale;
static TArray<vissprite_t> avis; static TArray<RenderSprite> avis;
}; };
} }

View file

@ -156,7 +156,7 @@ namespace swrenderer
double yscale = spriteScale.Y / tex->Scale.Y; double yscale = spriteScale.Y / tex->Scale.Y;
// store information in a vissprite // store information in a vissprite
vissprite_t *vis = RenderMemory::NewObject<vissprite_t>(); RenderSprite *vis = RenderMemory::NewObject<RenderSprite>();
vis->CurrentPortalUniq = renderportal->CurrentPortalUniq; vis->CurrentPortalUniq = renderportal->CurrentPortalUniq;
vis->xscale = FLOAT2FIXED(xscale); vis->xscale = FLOAT2FIXED(xscale);
@ -166,7 +166,7 @@ namespace swrenderer
vis->texturemid = tex->TopOffset - (ViewPos.Z - pos.Z + thing->Floorclip) / yscale; vis->texturemid = tex->TopOffset - (ViewPos.Z - pos.Z + thing->Floorclip) / yscale;
vis->x1 = x1 < renderportal->WindowLeft ? renderportal->WindowLeft : x1; vis->x1 = x1 < renderportal->WindowLeft ? renderportal->WindowLeft : x1;
vis->x2 = x2 > renderportal->WindowRight ? renderportal->WindowRight : x2; vis->x2 = x2 > renderportal->WindowRight ? renderportal->WindowRight : x2;
vis->Angle = thing->Angles.Yaw; //vis->Angle = thing->Angles.Yaw;
if (renderflags & RF_XFLIP) if (renderflags & RF_XFLIP)
{ {
@ -202,12 +202,10 @@ namespace swrenderer
vis->fakefloor = fakefloor; vis->fakefloor = fakefloor;
vis->fakeceiling = fakeceiling; vis->fakeceiling = fakeceiling;
vis->Style.ColormapNum = 0; vis->Style.ColormapNum = 0;
vis->bInMirror = renderportal->MirrorFlags & RF_XFLIP; //vis->bInMirror = renderportal->MirrorFlags & RF_XFLIP;
vis->bSplitSprite = false; //vis->bSplitSprite = false;
vis->pic = tex; vis->pic = tex;
vis->bIsVoxel = false;
vis->bWallSprite = false;
vis->foggy = foggy; vis->foggy = foggy;
@ -278,8 +276,10 @@ namespace swrenderer
VisibleSpriteList::Instance()->Push(vis); VisibleSpriteList::Instance()->Push(vis);
} }
void RenderSprite::Render(vissprite_t *vis, const short *mfloorclip, const short *mceilingclip) void RenderSprite::Render(short *mfloorclip, short *mceilingclip, int, int)
{ {
auto vis = this;
fixed_t frac; fixed_t frac;
FTexture *tex; FTexture *tex;
int x2; int x2;

View file

@ -17,10 +17,21 @@
namespace swrenderer namespace swrenderer
{ {
class RenderSprite class RenderSprite : public VisibleSprite
{ {
public: public:
static void Project(AActor *thing, const DVector3 &pos, FTexture *tex, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int spriteshade, bool foggy, FDynamicColormap *basecolormap); static void Project(AActor *thing, const DVector3 &pos, FTexture *tex, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int spriteshade, bool foggy, FDynamicColormap *basecolormap);
static void Render(vissprite_t *vis, const short *mfloorclip, const short *mceilingclip);
void Render(short *cliptop, short *clipbottom, int minZ, int maxZ) override;
private:
fixed_t xscale;
fixed_t startfrac; // horizontal position of x1
fixed_t xiscale; // negative if flipped
uint32_t Translation;
uint32_t FillColor;
friend class RenderPlayerSprite; // To do: detach sprite from playersprite!
}; };
} }

View file

@ -24,70 +24,44 @@ struct FVoxel;
namespace swrenderer namespace swrenderer
{ {
struct vissprite_t class VisibleSprite
{ {
struct posang public:
{ virtual bool IsParticle() const { return false; }
FVector3 vpos; // view origin virtual bool IsVoxel() const { return false; }
FAngle vang; // view angle virtual bool IsWallSprite() const { return false; }
};
virtual void Render(short *cliptop, short *clipbottom, int minZ, int maxZ) = 0;
FTexture *pic;
short x1, x2; short x1, x2;
FVector3 gpos; // origin in world coordinates float gzb, gzt; // global bottom / top for silhouette clipping
union
{
struct
{
float gzb, gzt; // global bottom / top for silhouette clipping
};
struct
{
int y1, y2; // top / bottom of particle on screen
};
};
DAngle Angle;
fixed_t xscale;
float yscale;
float depth;
float idepth; // 1/z
float deltax, deltay;
uint32_t FillColor;
double floorclip; double floorclip;
union
{ double texturemid; // floorclip
FTexture *pic; float yscale; // voxel and floorclip
struct FVoxel *voxel;
}; sector_t *heightsec; // height sector for underwater/fake ceiling
union WaterFakeSide FakeFlatStat; // which side of fake/floor ceiling sprite is on
{
// Used by face sprites F3DFloor *fakefloor; // 3d floor clipping
struct
{
double texturemid;
fixed_t startfrac; // horizontal position of x1
fixed_t xiscale; // negative if flipped
};
// Used by wall sprites
FWallCoords wallc;
// Used by voxels
posang pa;
};
sector_t *heightsec; // killough 3/27/98: height sector for underwater/fake ceiling
sector_t *sector; // [RH] sector this sprite is in
F3DFloor *fakefloor;
F3DFloor *fakeceiling; F3DFloor *fakeceiling;
uint8_t bIsVoxel : 1; // [RH] Use voxel instead of pic
uint8_t bWallSprite : 1; // [RH] This is a wall sprite FVector3 gpos; // origin in world coordinates
uint8_t bSplitSprite : 1; // [RH] Sprite was split by a drawseg sector_t *sector; // sector this sprite is in
uint8_t bInMirror : 1; // [RH] Sprite is "inside" a mirror
WaterFakeSide FakeFlatStat; // [RH] which side of fake/floor ceiling sprite is on // Light shared calculation?
short renderflags;
uint32_t Translation; // [RH] for color translation
visstyle_t Style; visstyle_t Style;
int CurrentPortalUniq; // [ZZ] to identify the portal that this thing is in. used for clipping.
bool foggy; bool foggy;
short renderflags;
vissprite_t() {} float depth; // Sort (draw segments), also light
float deltax, deltay; // Sort (2d/voxel version)
float idepth; // Sort (non-voxel version)
int CurrentPortalUniq; // to identify the portal that this thing is in. used for clipping.
}; };
} }

View file

@ -52,15 +52,15 @@ namespace swrenderer
StartIndices.Pop(); StartIndices.Pop();
} }
void VisibleSpriteList::Push(vissprite_t *sprite) void VisibleSpriteList::Push(VisibleSprite *sprite)
{ {
Sprites.Push(sprite); Sprites.Push(sprite);
} }
void VisibleSpriteList::Sort(bool compare2d) void VisibleSpriteList::Sort(bool compare2d)
{ {
size_t first = StartIndices.Size() == 0 ? 0 : StartIndices.Last(); unsigned int first = StartIndices.Size() == 0 ? 0 : StartIndices.Last();
size_t count = Sprites.Size() - first; unsigned int count = Sprites.Size() - first;
SortedSprites.Resize(count); SortedSprites.Resize(count);
@ -69,7 +69,7 @@ namespace swrenderer
if (!(i_compatflags & COMPATF_SPRITESORT)) if (!(i_compatflags & COMPATF_SPRITESORT))
{ {
for (size_t i = 0; i < count; i++) for (unsigned int i = 0; i < count; i++)
SortedSprites[i] = Sprites[first + i]; SortedSprites[i] = Sprites[first + i];
} }
else else
@ -77,7 +77,7 @@ namespace swrenderer
// If the compatibility option is on sprites of equal distance need to // If the compatibility option is on sprites of equal distance need to
// be sorted in inverse order. This is most easily achieved by // be sorted in inverse order. This is most easily achieved by
// filling the sort array backwards before the sort. // filling the sort array backwards before the sort.
for (size_t i = 0; i < count; i++) for (unsigned int i = 0; i < count; i++)
SortedSprites[i] = Sprites[first + count - i - 1]; SortedSprites[i] = Sprites[first + count - i - 1];
} }
@ -87,7 +87,7 @@ namespace swrenderer
// It does a 2D distance test based on whichever one is furthest from // It does a 2D distance test based on whichever one is furthest from
// the viewpoint. // the viewpoint.
std::stable_sort(&SortedSprites[0], &SortedSprites[count], [](vissprite_t *a, vissprite_t *b) -> bool std::stable_sort(&SortedSprites[0], &SortedSprites[count], [](VisibleSprite *a, VisibleSprite *b) -> bool
{ {
return DVector2(a->deltax, a->deltay).LengthSquared() < DVector2(b->deltax, b->deltay).LengthSquared(); return DVector2(a->deltax, a->deltay).LengthSquared() < DVector2(b->deltax, b->deltay).LengthSquared();
}); });
@ -96,7 +96,7 @@ namespace swrenderer
{ {
// This is the standard version, which does a simple test based on depth. // This is the standard version, which does a simple test based on depth.
std::stable_sort(&SortedSprites[0], &SortedSprites[count], [](vissprite_t *a, vissprite_t *b) -> bool std::stable_sort(&SortedSprites[0], &SortedSprites[count], [](VisibleSprite *a, VisibleSprite *b) -> bool
{ {
return a->idepth > b->idepth; return a->idepth > b->idepth;
}); });

View file

@ -16,7 +16,7 @@
namespace swrenderer namespace swrenderer
{ {
struct drawseg_t; struct drawseg_t;
struct vissprite_t; class VisibleSprite;
class VisibleSpriteList class VisibleSpriteList
{ {
@ -26,13 +26,13 @@ namespace swrenderer
void Clear(); void Clear();
void PushPortal(); void PushPortal();
void PopPortal(); void PopPortal();
void Push(vissprite_t *sprite); void Push(VisibleSprite *sprite);
void Sort(bool compare2d); void Sort(bool compare2d);
TArray<vissprite_t *> SortedSprites; TArray<VisibleSprite *> SortedSprites;
private: private:
TArray<vissprite_t *> Sprites; TArray<VisibleSprite *> Sprites;
TArray<size_t> StartIndices; TArray<unsigned int> StartIndices;
}; };
} }

View file

@ -105,7 +105,7 @@ namespace swrenderer
} }
} }
vissprite_t *vis = RenderMemory::NewObject<vissprite_t>(); RenderVoxel *vis = RenderMemory::NewObject<RenderVoxel>();
vis->CurrentPortalUniq = renderportal->CurrentPortalUniq; vis->CurrentPortalUniq = renderportal->CurrentPortalUniq;
vis->xscale = FLOAT2FIXED(xscale); vis->xscale = FLOAT2FIXED(xscale);
@ -150,12 +150,10 @@ namespace swrenderer
vis->fakefloor = fakefloor; vis->fakefloor = fakefloor;
vis->fakeceiling = fakeceiling; vis->fakeceiling = fakeceiling;
vis->Style.ColormapNum = 0; vis->Style.ColormapNum = 0;
vis->bInMirror = renderportal->MirrorFlags & RF_XFLIP; //vis->bInMirror = renderportal->MirrorFlags & RF_XFLIP;
vis->bSplitSprite = false; //vis->bSplitSprite = false;
vis->voxel = voxel->Voxel; vis->voxel = voxel->Voxel;
vis->bIsVoxel = true;
vis->bWallSprite = false;
vis->foggy = foggy; vis->foggy = foggy;
// The software renderer cannot invert the source without inverting the overlay // The software renderer cannot invert the source without inverting the overlay
@ -227,8 +225,10 @@ namespace swrenderer
RenderTranslucentPass::DrewAVoxel = true; RenderTranslucentPass::DrewAVoxel = true;
} }
void RenderVoxel::Render(vissprite_t *sprite, int minZ, int maxZ, short *cliptop, short *clipbottom) void RenderVoxel::Render(short *cliptop, short *clipbottom, int minZ, int maxZ)
{ {
auto sprite = this;
FDynamicColormap *basecolormap = static_cast<FDynamicColormap*>(sprite->Style.BaseColormap); FDynamicColormap *basecolormap = static_cast<FDynamicColormap*>(sprite->Style.BaseColormap);
R_SetColorMapLight(sprite->Style.BaseColormap, 0, sprite->Style.ColormapNum << FRACBITS); R_SetColorMapLight(sprite->Style.BaseColormap, 0, sprite->Style.ColormapNum << FRACBITS);

View file

@ -25,11 +25,10 @@
struct kvxslab_t; struct kvxslab_t;
struct FVoxelMipLevel; struct FVoxelMipLevel;
struct FVoxel;
namespace swrenderer namespace swrenderer
{ {
struct vissprite_t;
// [RH] A c-buffer. Used for keeping track of offscreen voxel spans. // [RH] A c-buffer. Used for keeping track of offscreen voxel spans.
struct FCoverageBuffer struct FCoverageBuffer
{ {
@ -52,15 +51,31 @@ namespace swrenderer
unsigned int NumLists; unsigned int NumLists;
}; };
class RenderVoxel class RenderVoxel : public VisibleSprite
{ {
public: public:
static void Project(AActor *thing, DVector3 pos, FVoxelDef *voxel, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int spriteshade, bool foggy, FDynamicColormap *basecolormap); static void Project(AActor *thing, DVector3 pos, FVoxelDef *voxel, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int spriteshade, bool foggy, FDynamicColormap *basecolormap);
static void Render(vissprite_t *sprite, int minZ, int maxZ, short *cliptop, short *clipbottom);
static void Deinit(); static void Deinit();
bool IsVoxel() const override { return true; }
void Render(short *cliptop, short *clipbottom, int minZ, int maxZ) override;
private: private:
struct posang
{
FVector3 vpos; // view origin
FAngle vang; // view angle
};
posang pa;
DAngle Angle;
fixed_t xscale;
FVoxel *voxel;
uint32_t Translation;
uint32_t FillColor;
enum { DVF_OFFSCREEN = 1, DVF_SPANSONLY = 2, DVF_MIRRORED = 4 }; enum { DVF_OFFSCREEN = 1, DVF_SPANSONLY = 2, DVF_MIRRORED = 4 };
static void FillBox(DVector3 origin, double extentX, double extentY, int color, short *cliptop, short *clipbottom, bool viewspace, bool pixelstretch); static void FillBox(DVector3 origin, double extentX, double extentY, int color, short *cliptop, short *clipbottom, bool viewspace, bool pixelstretch);

View file

@ -104,7 +104,7 @@ namespace swrenderer
gzt = pos.Z + scale.Y * scaled_to; gzt = pos.Z + scale.Y * scaled_to;
gzb = pos.Z + scale.Y * scaled_bo; gzb = pos.Z + scale.Y * scaled_bo;
vissprite_t *vis = RenderMemory::NewObject<vissprite_t>(); RenderWallSprite *vis = RenderMemory::NewObject<RenderWallSprite>();
vis->CurrentPortalUniq = renderportal->CurrentPortalUniq; vis->CurrentPortalUniq = renderportal->CurrentPortalUniq;
vis->x1 = wallc.sx1 < renderportal->WindowLeft ? renderportal->WindowLeft : wallc.sx1; vis->x1 = wallc.sx1 < renderportal->WindowLeft ? renderportal->WindowLeft : wallc.sx1;
vis->x2 = wallc.sx2 >= renderportal->WindowRight ? renderportal->WindowRight : wallc.sx2; vis->x2 = wallc.sx2 >= renderportal->WindowRight ? renderportal->WindowRight : wallc.sx2;
@ -127,12 +127,9 @@ namespace swrenderer
vis->Style.Alpha = float(thing->Alpha); vis->Style.Alpha = float(thing->Alpha);
vis->fakefloor = NULL; vis->fakefloor = NULL;
vis->fakeceiling = NULL; vis->fakeceiling = NULL;
vis->bInMirror = renderportal->MirrorFlags & RF_XFLIP; //vis->bInMirror = renderportal->MirrorFlags & RF_XFLIP;
vis->pic = pic; vis->pic = pic;
vis->bIsVoxel = false; vis->Style.ColormapNum = GETPALOOKUP(r_SpriteVisibility / MAX(tz, MINZ), spriteshade);
vis->bWallSprite = true;
vis->Style.ColormapNum = GETPALOOKUP(
r_SpriteVisibility / MAX(tz, MINZ), spriteshade);
vis->Style.BaseColormap = basecolormap; vis->Style.BaseColormap = basecolormap;
vis->wallc = wallc; vis->wallc = wallc;
vis->foggy = foggy; vis->foggy = foggy;
@ -140,8 +137,10 @@ namespace swrenderer
VisibleSpriteList::Instance()->Push(vis); VisibleSpriteList::Instance()->Push(vis);
} }
void RenderWallSprite::Render(vissprite_t *spr, const short *mfloorclip, const short *mceilingclip) void RenderWallSprite::Render(short *mfloorclip, short *mceilingclip, int, int)
{ {
auto spr = this;
int x1, x2; int x1, x2;
double iyscale; double iyscale;
bool sprflipvert; bool sprflipvert;

View file

@ -17,13 +17,19 @@
namespace swrenderer namespace swrenderer
{ {
class RenderWallSprite class RenderWallSprite : public VisibleSprite
{ {
public: public:
static void Project(AActor *thing, const DVector3 &pos, FTextureID picnum, const DVector2 &scale, int renderflags, int spriteshade, bool foggy, FDynamicColormap *basecolormap); static void Project(AActor *thing, const DVector3 &pos, FTextureID picnum, const DVector2 &scale, int renderflags, int spriteshade, bool foggy, FDynamicColormap *basecolormap);
static void Render(vissprite_t *spr, const short *mfloorclip, const short *mceilingclip);
bool IsWallSprite() const override { return true; }
void Render(short *cliptop, short *clipbottom, int minZ, int maxZ) override;
private: private:
static void DrawColumn(int x, FTexture *WallSpriteTile, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip); static void DrawColumn(int x, FTexture *WallSpriteTile, double texturemid, float maskedScaleY, bool sprflipvert, const short *mfloorclip, const short *mceilingclip);
FWallCoords wallc;
uint32_t Translation;
uint32_t FillColor;
}; };
} }