Remove software renderer internals from F3DFloor

This commit is contained in:
Magnus Norddahl 2017-02-04 19:13:56 +01:00
parent 8ad132b64f
commit cfe4c55973
12 changed files with 86 additions and 57 deletions

View file

@ -129,8 +129,6 @@ static void P_Add3DFloor(sector_t* sec, sector_t* sec2, line_t* master, int flag
ffloor->top.copied = ffloor->bottom.copied = false;
ffloor->top.model = ffloor->bottom.model = ffloor->model = sec2;
ffloor->target = sec;
ffloor->ceilingclip = ffloor->floorclip = NULL;
ffloor->validcount = 0;
if (!(flags&FF_THINFLOOR))
{

View file

@ -95,11 +95,6 @@ struct F3DFloor
int lastlight;
int alpha;
// kg3D - for software
short *floorclip;
short *ceilingclip;
int validcount;
FDynamicColormap *GetColormap();
void UpdateColormap(FDynamicColormap *&map);
PalEntry GetBlend();

View file

@ -89,7 +89,8 @@ namespace swrenderer
return;
}
NetUpdate();
if (Thread->MainThread)
NetUpdate();
frontsector = curline->frontsector;
backsector = curline->backsector;

View file

@ -362,7 +362,8 @@ namespace swrenderer
Draw1Column(x, y1, y2, sampler);
}
NetUpdate();
if (Thread->MainThread)
NetUpdate();
}
void RenderWallPart::ProcessNormalWall(const short *uwal, const short *dwal, double texturemid, float *swal, fixed_t *lwal)

View file

@ -129,6 +129,7 @@ namespace swrenderer
renderer.Render(this, xscale, yscale, alpha, additive, masked, colormap, tex);
}
}
NetUpdate();
if (thread->MainThread)
NetUpdate();
}
}

View file

@ -14,6 +14,7 @@
#include "r_3dfloors.h"
#include "r_utility.h"
#include "swrenderer/r_renderthread.h"
#include "swrenderer/r_memory.h"
CVAR(Int, r_3dfloors, true, 0);
@ -24,8 +25,20 @@ namespace swrenderer
Thread = thread;
}
void Clip3DFloors::SetFakeFloor(F3DFloor *newFakeFloor)
{
auto &clip = FakeFloors[newFakeFloor];
if (clip == nullptr)
{
clip = Thread->FrameMemory->NewObject<FakeFloorClip>(newFakeFloor);
}
fakeFloor = clip;
}
void Clip3DFloors::Cleanup()
{
FakeFloors.clear();
fakeActive = false;
fake3D = 0;
while (CurrentSkybox)

View file

@ -2,12 +2,14 @@
#pragma once
#include "p_3dfloors.h"
#include <unordered_map>
EXTERN_CVAR(Int, r_3dfloors);
namespace swrenderer
{
class RenderThread;
class FakeFloorClip;
struct HeightLevel
{
@ -27,7 +29,7 @@ namespace swrenderer
{
short floorclip[MAXWIDTH];
short ceilingclip[MAXWIDTH];
F3DFloor *ffloor;
FakeFloorClip *ffloor;
ClipStack *next;
};
@ -51,6 +53,17 @@ namespace swrenderer
FAKE3D_DOWN2UP = 8, // rendering from down to up (floors)
};
class FakeFloorClip
{
public:
FakeFloorClip(F3DFloor *fakeFloor) : fakeFloor(fakeFloor) { }
F3DFloor *fakeFloor = nullptr;
short *floorclip = nullptr;
short *ceilingclip = nullptr;
int validcount = -1;
};
class Clip3DFloors
{
public:
@ -64,12 +77,13 @@ namespace swrenderer
void ResetClip();
void EnterSkybox();
void LeaveSkybox();
void SetFakeFloor(F3DFloor *fakeFloor);
RenderThread *Thread = nullptr;
int fake3D = 0;
F3DFloor *fakeFloor = nullptr;
FakeFloorClip *fakeFloor = nullptr;
fixed_t fakeAlpha = 0;
bool fakeActive = false;
double sclipBottom = 0;
@ -83,5 +97,7 @@ namespace swrenderer
TArray<HeightStack> toplist;
ClipStack *clip_top = nullptr;
ClipStack *clip_cur = nullptr;
std::unordered_map<F3DFloor *, FakeFloorClip *> FakeFloors;
};
}

View file

@ -573,32 +573,32 @@ namespace swrenderer
// first check all floors
for (int i = 0; i < (int)frontsector->e->XFloor.ffloors.Size(); i++)
{
clip3d->fakeFloor = frontsector->e->XFloor.ffloors[i];
if (!(clip3d->fakeFloor->flags & FF_EXISTS)) continue;
if (!clip3d->fakeFloor->model) continue;
if (clip3d->fakeFloor->bottom.plane->isSlope()) continue;
if (!(clip3d->fakeFloor->flags & FF_NOSHADE) || (clip3d->fakeFloor->flags & (FF_RENDERPLANES | FF_RENDERSIDES)))
clip3d->SetFakeFloor(frontsector->e->XFloor.ffloors[i]);
if (!(clip3d->fakeFloor->fakeFloor->flags & FF_EXISTS)) continue;
if (!clip3d->fakeFloor->fakeFloor->model) continue;
if (clip3d->fakeFloor->fakeFloor->bottom.plane->isSlope()) continue;
if (!(clip3d->fakeFloor->fakeFloor->flags & FF_NOSHADE) || (clip3d->fakeFloor->fakeFloor->flags & (FF_RENDERPLANES | FF_RENDERSIDES)))
{
clip3d->AddHeight(clip3d->fakeFloor->top.plane, frontsector);
clip3d->AddHeight(clip3d->fakeFloor->fakeFloor->top.plane, frontsector);
}
if (!(clip3d->fakeFloor->flags & FF_RENDERPLANES)) continue;
if (clip3d->fakeFloor->alpha == 0) continue;
if (clip3d->fakeFloor->flags & FF_THISINSIDE && clip3d->fakeFloor->flags & FF_INVERTSECTOR) continue;
clip3d->fakeAlpha = MIN<fixed_t>(Scale(clip3d->fakeFloor->alpha, OPAQUE, 255), OPAQUE);
if (!(clip3d->fakeFloor->fakeFloor->flags & FF_RENDERPLANES)) continue;
if (clip3d->fakeFloor->fakeFloor->alpha == 0) continue;
if (clip3d->fakeFloor->fakeFloor->flags & FF_THISINSIDE && clip3d->fakeFloor->fakeFloor->flags & FF_INVERTSECTOR) continue;
clip3d->fakeAlpha = MIN<fixed_t>(Scale(clip3d->fakeFloor->fakeFloor->alpha, OPAQUE, 255), OPAQUE);
if (clip3d->fakeFloor->validcount != validcount)
{
clip3d->fakeFloor->validcount = validcount;
clip3d->NewClip();
}
double fakeHeight = clip3d->fakeFloor->top.plane->ZatPoint(frontsector->centerspot);
double fakeHeight = clip3d->fakeFloor->fakeFloor->top.plane->ZatPoint(frontsector->centerspot);
if (fakeHeight < ViewPos.Z &&
fakeHeight > frontsector->floorplane.ZatPoint(frontsector->centerspot))
{
clip3d->fake3D = FAKE3D_FAKEFLOOR;
tempsec = *clip3d->fakeFloor->model;
tempsec.floorplane = *clip3d->fakeFloor->top.plane;
tempsec.ceilingplane = *clip3d->fakeFloor->bottom.plane;
if (!(clip3d->fakeFloor->flags & FF_THISINSIDE) && !(clip3d->fakeFloor->flags & FF_INVERTSECTOR))
tempsec = *clip3d->fakeFloor->fakeFloor->model;
tempsec.floorplane = *clip3d->fakeFloor->fakeFloor->top.plane;
tempsec.ceilingplane = *clip3d->fakeFloor->fakeFloor->bottom.plane;
if (!(clip3d->fakeFloor->fakeFloor->flags & FF_THISINSIDE) && !(clip3d->fakeFloor->fakeFloor->flags & FF_INVERTSECTOR))
{
tempsec.SetTexture(sector_t::floor, tempsec.GetTexture(sector_t::ceiling));
position = sector_t::ceiling;
@ -618,7 +618,7 @@ namespace swrenderer
frontsector->GetTexture(sector_t::floor),
floorlightlevel + R_ActualExtraLight(foggy), // killough 3/16/98
frontsector->GetAlpha(sector_t::floor),
!!(clip3d->fakeFloor->flags & FF_ADDITIVETRANS),
!!(clip3d->fakeFloor->fakeFloor->flags & FF_ADDITIVETRANS),
frontsector->planes[position].xform,
frontsector->sky,
nullptr,
@ -635,34 +635,34 @@ namespace swrenderer
// and now ceilings
for (unsigned int i = 0; i < frontsector->e->XFloor.ffloors.Size(); i++)
{
clip3d->fakeFloor = frontsector->e->XFloor.ffloors[i];
if (!(clip3d->fakeFloor->flags & FF_EXISTS)) continue;
if (!clip3d->fakeFloor->model) continue;
if (clip3d->fakeFloor->top.plane->isSlope()) continue;
if (!(clip3d->fakeFloor->flags & FF_NOSHADE) || (clip3d->fakeFloor->flags & (FF_RENDERPLANES | FF_RENDERSIDES)))
clip3d->SetFakeFloor(frontsector->e->XFloor.ffloors[i]);
if (!(clip3d->fakeFloor->fakeFloor->flags & FF_EXISTS)) continue;
if (!clip3d->fakeFloor->fakeFloor->model) continue;
if (clip3d->fakeFloor->fakeFloor->top.plane->isSlope()) continue;
if (!(clip3d->fakeFloor->fakeFloor->flags & FF_NOSHADE) || (clip3d->fakeFloor->fakeFloor->flags & (FF_RENDERPLANES | FF_RENDERSIDES)))
{
clip3d->AddHeight(clip3d->fakeFloor->bottom.plane, frontsector);
clip3d->AddHeight(clip3d->fakeFloor->fakeFloor->bottom.plane, frontsector);
}
if (!(clip3d->fakeFloor->flags & FF_RENDERPLANES)) continue;
if (clip3d->fakeFloor->alpha == 0) continue;
if (!(clip3d->fakeFloor->flags & FF_THISINSIDE) && (clip3d->fakeFloor->flags & (FF_SWIMMABLE | FF_INVERTSECTOR)) == (FF_SWIMMABLE | FF_INVERTSECTOR)) continue;
clip3d->fakeAlpha = MIN<fixed_t>(Scale(clip3d->fakeFloor->alpha, OPAQUE, 255), OPAQUE);
if (!(clip3d->fakeFloor->fakeFloor->flags & FF_RENDERPLANES)) continue;
if (clip3d->fakeFloor->fakeFloor->alpha == 0) continue;
if (!(clip3d->fakeFloor->fakeFloor->flags & FF_THISINSIDE) && (clip3d->fakeFloor->fakeFloor->flags & (FF_SWIMMABLE | FF_INVERTSECTOR)) == (FF_SWIMMABLE | FF_INVERTSECTOR)) continue;
clip3d->fakeAlpha = MIN<fixed_t>(Scale(clip3d->fakeFloor->fakeFloor->alpha, OPAQUE, 255), OPAQUE);
if (clip3d->fakeFloor->validcount != validcount)
{
clip3d->fakeFloor->validcount = validcount;
clip3d->NewClip();
}
double fakeHeight = clip3d->fakeFloor->bottom.plane->ZatPoint(frontsector->centerspot);
double fakeHeight = clip3d->fakeFloor->fakeFloor->bottom.plane->ZatPoint(frontsector->centerspot);
if (fakeHeight > ViewPos.Z &&
fakeHeight < frontsector->ceilingplane.ZatPoint(frontsector->centerspot))
{
clip3d->fake3D = FAKE3D_FAKECEILING;
tempsec = *clip3d->fakeFloor->model;
tempsec.floorplane = *clip3d->fakeFloor->top.plane;
tempsec.ceilingplane = *clip3d->fakeFloor->bottom.plane;
if ((!(clip3d->fakeFloor->flags & FF_THISINSIDE) && !(clip3d->fakeFloor->flags & FF_INVERTSECTOR)) ||
(clip3d->fakeFloor->flags & FF_THISINSIDE && clip3d->fakeFloor->flags & FF_INVERTSECTOR))
tempsec = *clip3d->fakeFloor->fakeFloor->model;
tempsec.floorplane = *clip3d->fakeFloor->fakeFloor->top.plane;
tempsec.ceilingplane = *clip3d->fakeFloor->fakeFloor->bottom.plane;
if ((!(clip3d->fakeFloor->fakeFloor->flags & FF_THISINSIDE) && !(clip3d->fakeFloor->fakeFloor->flags & FF_INVERTSECTOR)) ||
(clip3d->fakeFloor->fakeFloor->flags & FF_THISINSIDE && clip3d->fakeFloor->fakeFloor->flags & FF_INVERTSECTOR))
{
tempsec.SetTexture(sector_t::ceiling, tempsec.GetTexture(sector_t::floor));
position = sector_t::floor;
@ -684,7 +684,7 @@ namespace swrenderer
frontsector->GetTexture(sector_t::ceiling),
ceilinglightlevel + R_ActualExtraLight(foggy), // killough 4/11/98
frontsector->GetAlpha(sector_t::ceiling),
!!(clip3d->fakeFloor->flags & FF_ADDITIVETRANS),
!!(clip3d->fakeFloor->fakeFloor->flags & FF_ADDITIVETRANS),
frontsector->planes[position].xform,
frontsector->sky,
nullptr,
@ -741,14 +741,14 @@ namespace swrenderer
Clip3DFloors *clip3d = Thread->Clip3DFloors.get();
for (unsigned int i = 0; i < line->backsector->e->XFloor.ffloors.Size(); i++)
{
clip3d->fakeFloor = line->backsector->e->XFloor.ffloors[i];
if (!(clip3d->fakeFloor->flags & FF_EXISTS)) continue;
if (!(clip3d->fakeFloor->flags & FF_RENDERPLANES)) continue;
if (!clip3d->fakeFloor->model) continue;
clip3d->SetFakeFloor(line->backsector->e->XFloor.ffloors[i]);
if (!(clip3d->fakeFloor->fakeFloor->flags & FF_EXISTS)) continue;
if (!(clip3d->fakeFloor->fakeFloor->flags & FF_RENDERPLANES)) continue;
if (!clip3d->fakeFloor->fakeFloor->model) continue;
clip3d->fake3D = FAKE3D_FAKEBACK;
tempsec = *clip3d->fakeFloor->model;
tempsec.floorplane = *clip3d->fakeFloor->top.plane;
tempsec.ceilingplane = *clip3d->fakeFloor->bottom.plane;
tempsec = *clip3d->fakeFloor->fakeFloor->model;
tempsec.floorplane = *clip3d->fakeFloor->fakeFloor->top.plane;
tempsec.ceilingplane = *clip3d->fakeFloor->fakeFloor->bottom.plane;
if (clip3d->fakeFloor->validcount != validcount)
{
clip3d->fakeFloor->validcount = validcount;

View file

@ -441,13 +441,15 @@ namespace swrenderer
int prevuniq2 = CurrentPortalUniq;
CurrentPortalUniq = prevuniq;
NetUpdate();
if (Thread->MainThread)
NetUpdate();
MaskedCycles.Clock(); // [ZZ] count sprites in portals/mirrors along with normal ones.
Thread->TranslucentPass->Render(); // this is required since with portals there often will be cases when more than 80% of the view is inside a portal.
MaskedCycles.Unclock();
NetUpdate();
if (Thread->MainThread)
NetUpdate();
Thread->Clip3DFloors->LeaveSkybox(); // pop 3D floor height map
CurrentPortalUniq = prevuniq2;

View file

@ -267,7 +267,7 @@ namespace swrenderer
{
while (Threads.size() < (size_t)numThreads)
{
auto thread = std::make_unique<RenderThread>(this);
auto thread = std::make_unique<RenderThread>(this, false);
auto renderthread = thread.get();
int start_run_id = run_id;
thread->thread = std::thread([=]()

View file

@ -630,6 +630,7 @@ namespace swrenderer
frac += xiscale;
}
NetUpdate();
if (thread->MainThread)
NetUpdate();
}
}

View file

@ -298,6 +298,7 @@ namespace swrenderer
}
}
NetUpdate();
if (thread->MainThread)
NetUpdate();
}
}