mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-23 20:43:15 +00:00
- moved all code not specific to the software renderer out of r_bsp.cpp.
SVN r3250 (trunk)
This commit is contained in:
parent
b57a39dd86
commit
06d280f00a
4 changed files with 113 additions and 119 deletions
|
@ -165,6 +165,7 @@ void FNodeBuilder::ExtractMini (FMiniBSP *bsp)
|
|||
{
|
||||
unsigned int i;
|
||||
|
||||
bsp->bDirty = false;
|
||||
bsp->Verts.Resize(Vertices.Size());
|
||||
for (i = 0; i < Vertices.Size(); ++i)
|
||||
{
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include "c_cvars.h"
|
||||
#include "doomstat.h"
|
||||
#include "r_main.h"
|
||||
#include "nodebuild.h"
|
||||
#include "po_man.h"
|
||||
#include "resources/colormaps.h"
|
||||
|
||||
|
||||
|
@ -774,6 +776,61 @@ bool sector_t::PlaneMoving(int pos)
|
|||
}
|
||||
|
||||
|
||||
int sector_t::GetFloorLight () const
|
||||
{
|
||||
if (GetFlags(sector_t::floor) & PLANEF_ABSLIGHTING)
|
||||
{
|
||||
return GetPlaneLight(floor);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ClampLight(lightlevel + GetPlaneLight(floor));
|
||||
}
|
||||
}
|
||||
|
||||
int sector_t::GetCeilingLight () const
|
||||
{
|
||||
if (GetFlags(ceiling) & PLANEF_ABSLIGHTING)
|
||||
{
|
||||
return GetPlaneLight(ceiling);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ClampLight(lightlevel + GetPlaneLight(ceiling));
|
||||
}
|
||||
}
|
||||
|
||||
bool secplane_t::CopyPlaneIfValid (secplane_t *dest, const secplane_t *opp) const
|
||||
{
|
||||
bool copy = false;
|
||||
|
||||
// If the planes do not have matching slopes, then always copy them
|
||||
// because clipping would require creating new sectors.
|
||||
if (a != dest->a || b != dest->b || c != dest->c)
|
||||
{
|
||||
copy = true;
|
||||
}
|
||||
else if (opp->a != -dest->a || opp->b != -dest->b || opp->c != -dest->c)
|
||||
{
|
||||
if (d < dest->d)
|
||||
{
|
||||
copy = true;
|
||||
}
|
||||
}
|
||||
else if (d < dest->d && d > -opp->d)
|
||||
{
|
||||
copy = true;
|
||||
}
|
||||
|
||||
if (copy)
|
||||
{
|
||||
*dest = *this;
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// P_AlignFlat
|
||||
|
@ -805,3 +862,40 @@ bool P_AlignFlat (int linenum, int side, int fc)
|
|||
sec->SetBase(fc, dist & ((1<<(FRACBITS+8))-1), 0-angle);
|
||||
return true;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// P_BuildPolyBSP
|
||||
//
|
||||
//==========================================================================
|
||||
static FNodeBuilder::FLevel PolyNodeLevel;
|
||||
static FNodeBuilder PolyNodeBuilder(PolyNodeLevel);
|
||||
|
||||
void subsector_t::BuildPolyBSP()
|
||||
{
|
||||
assert((BSP == NULL || BSP->bDirty) && "BSP computed more than once");
|
||||
|
||||
// Set up level information for the node builder.
|
||||
PolyNodeLevel.Sides = sides;
|
||||
PolyNodeLevel.NumSides = numsides;
|
||||
PolyNodeLevel.Lines = lines;
|
||||
PolyNodeLevel.NumLines = numlines;
|
||||
|
||||
// Feed segs to the nodebuilder and build the nodes.
|
||||
PolyNodeBuilder.Clear();
|
||||
PolyNodeBuilder.AddSegs(firstline, numlines);
|
||||
for (FPolyNode *pn = polys; pn != NULL; pn = pn->pnext)
|
||||
{
|
||||
PolyNodeBuilder.AddPolySegs(&pn->segs[0], (int)pn->segs.Size());
|
||||
}
|
||||
PolyNodeBuilder.BuildMini(false);
|
||||
if (BSP == NULL)
|
||||
{
|
||||
BSP = new FMiniBSP;
|
||||
}
|
||||
PolyNodeBuilder.ExtractMini(BSP);
|
||||
for (unsigned int i = 0; i < BSP->Subsectors.Size(); ++i)
|
||||
{
|
||||
BSP->Subsectors[i].sector = sector;
|
||||
}
|
||||
}
|
||||
|
|
128
src/r_bsp.cpp
128
src/r_bsp.cpp
|
@ -45,7 +45,6 @@
|
|||
#include "r_3dfloors.h"
|
||||
#include "a_sharedglobal.h"
|
||||
#include "g_level.h"
|
||||
#include "nodebuild.h"
|
||||
|
||||
// State.
|
||||
#include "doomstat.h"
|
||||
|
@ -112,9 +111,6 @@ WORD MirrorFlags;
|
|||
seg_t *ActiveWallMirror;
|
||||
TArray<size_t> WallMirrors;
|
||||
|
||||
static FNodeBuilder::FLevel PolyNodeLevel;
|
||||
static FNodeBuilder PolyNodeBuilder(PolyNodeLevel);
|
||||
|
||||
static subsector_t *InSubsector;
|
||||
|
||||
CVAR (Bool, r_drawflat, false, 0) // [RH] Don't texture segs?
|
||||
|
@ -313,59 +309,6 @@ void R_ClearClipSegs (short left, short right)
|
|||
newend = solidsegs+2;
|
||||
}
|
||||
|
||||
int GetFloorLight (const sector_t *sec)
|
||||
{
|
||||
if (sec->GetFlags(sector_t::floor) & PLANEF_ABSLIGHTING)
|
||||
{
|
||||
return sec->GetPlaneLight(sector_t::floor);
|
||||
}
|
||||
else
|
||||
{
|
||||
return sector_t::ClampLight(sec->lightlevel + sec->GetPlaneLight(sector_t::floor));
|
||||
}
|
||||
}
|
||||
|
||||
int GetCeilingLight (const sector_t *sec)
|
||||
{
|
||||
if (sec->GetFlags(sector_t::ceiling) & PLANEF_ABSLIGHTING)
|
||||
{
|
||||
return sec->GetPlaneLight(sector_t::ceiling);
|
||||
}
|
||||
else
|
||||
{
|
||||
return sector_t::ClampLight(sec->lightlevel + sec->GetPlaneLight(sector_t::ceiling));
|
||||
}
|
||||
}
|
||||
|
||||
bool CopyPlaneIfValid (secplane_t *dest, const secplane_t *source, const secplane_t *opp)
|
||||
{
|
||||
bool copy = false;
|
||||
|
||||
// If the planes do not have matching slopes, then always copy them
|
||||
// because clipping would require creating new sectors.
|
||||
if (source->a != dest->a || source->b != dest->b || source->c != dest->c)
|
||||
{
|
||||
copy = true;
|
||||
}
|
||||
else if (opp->a != -dest->a || opp->b != -dest->b || opp->c != -dest->c)
|
||||
{
|
||||
if (source->d < dest->d)
|
||||
{
|
||||
copy = true;
|
||||
}
|
||||
}
|
||||
else if (source->d < dest->d && source->d > -opp->d)
|
||||
{
|
||||
copy = true;
|
||||
}
|
||||
|
||||
if (copy)
|
||||
{
|
||||
*dest = *source;
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
//
|
||||
// killough 3/7/98: Hack floor/ceiling heights for deep water etc.
|
||||
|
@ -387,12 +330,12 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec,
|
|||
// [RH] allow per-plane lighting
|
||||
if (floorlightlevel != NULL)
|
||||
{
|
||||
*floorlightlevel = GetFloorLight (sec);
|
||||
*floorlightlevel = sec->GetFloorLight ();
|
||||
}
|
||||
|
||||
if (ceilinglightlevel != NULL)
|
||||
{
|
||||
*ceilinglightlevel = GetCeilingLight (sec);
|
||||
*ceilinglightlevel = sec->GetCeilingLight ();
|
||||
}
|
||||
|
||||
FakeSide = FAKED_Center;
|
||||
|
@ -412,7 +355,7 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec,
|
|||
// Replace floor and ceiling height with control sector's heights.
|
||||
if (diffTex)
|
||||
{
|
||||
if (CopyPlaneIfValid (&tempsec->floorplane, &s->floorplane, &sec->ceilingplane))
|
||||
if (s->floorplane.CopyPlaneIfValid (&tempsec->floorplane, &sec->ceilingplane))
|
||||
{
|
||||
tempsec->SetTexture(sector_t::floor, s->GetTexture(sector_t::floor), false);
|
||||
}
|
||||
|
@ -427,12 +370,12 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec,
|
|||
|
||||
if (floorlightlevel != NULL)
|
||||
{
|
||||
*floorlightlevel = GetFloorLight (s);
|
||||
*floorlightlevel = s->GetFloorLight ();
|
||||
}
|
||||
|
||||
if (ceilinglightlevel != NULL)
|
||||
{
|
||||
*ceilinglightlevel = GetCeilingLight (s);
|
||||
*ceilinglightlevel = s->GetCeilingLight ();
|
||||
}
|
||||
}
|
||||
FakeSide = FAKED_BelowFloor;
|
||||
|
@ -450,7 +393,7 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec,
|
|||
{
|
||||
if (diffTex)
|
||||
{
|
||||
if (CopyPlaneIfValid (&tempsec->ceilingplane, &s->ceilingplane, &sec->floorplane))
|
||||
if (s->ceilingplane.CopyPlaneIfValid (&tempsec->ceilingplane, &sec->floorplane))
|
||||
{
|
||||
tempsec->SetTexture(sector_t::ceiling, s->GetTexture(sector_t::ceiling), false);
|
||||
}
|
||||
|
@ -528,12 +471,12 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec,
|
|||
|
||||
if (floorlightlevel != NULL)
|
||||
{
|
||||
*floorlightlevel = GetFloorLight (s);
|
||||
*floorlightlevel = s->GetFloorLight ();
|
||||
}
|
||||
|
||||
if (ceilinglightlevel != NULL)
|
||||
{
|
||||
*ceilinglightlevel = GetCeilingLight (s);
|
||||
*ceilinglightlevel = s->GetCeilingLight ();
|
||||
}
|
||||
}
|
||||
FakeSide = FAKED_BelowFloor;
|
||||
|
@ -565,12 +508,12 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec,
|
|||
|
||||
if (floorlightlevel != NULL)
|
||||
{
|
||||
*floorlightlevel = GetFloorLight (s);
|
||||
*floorlightlevel = s->GetFloorLight ();
|
||||
}
|
||||
|
||||
if (ceilinglightlevel != NULL)
|
||||
{
|
||||
*ceilinglightlevel = GetCeilingLight (s);
|
||||
*ceilinglightlevel = s->GetCeilingLight ();
|
||||
}
|
||||
}
|
||||
FakeSide = FAKED_AboveCeiling;
|
||||
|
@ -1021,62 +964,13 @@ static bool R_CheckBBox (fixed_t *bspcoord) // killough 1/28/98: static
|
|||
return true;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// FMiniBSP Constructor
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
FMiniBSP::FMiniBSP()
|
||||
{
|
||||
bDirty = false;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// P_BuildPolyBSP
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void R_BuildPolyBSP(subsector_t *sub)
|
||||
{
|
||||
assert((sub->BSP == NULL || sub->BSP->bDirty) && "BSP computed more than once");
|
||||
|
||||
// Set up level information for the node builder.
|
||||
PolyNodeLevel.Sides = sides;
|
||||
PolyNodeLevel.NumSides = numsides;
|
||||
PolyNodeLevel.Lines = lines;
|
||||
PolyNodeLevel.NumLines = numlines;
|
||||
|
||||
// Feed segs to the nodebuilder and build the nodes.
|
||||
PolyNodeBuilder.Clear();
|
||||
PolyNodeBuilder.AddSegs(sub->firstline, sub->numlines);
|
||||
for (FPolyNode *pn = sub->polys; pn != NULL; pn = pn->pnext)
|
||||
{
|
||||
PolyNodeBuilder.AddPolySegs(&pn->segs[0], (int)pn->segs.Size());
|
||||
}
|
||||
PolyNodeBuilder.BuildMini(false);
|
||||
if (sub->BSP == NULL)
|
||||
{
|
||||
sub->BSP = new FMiniBSP;
|
||||
}
|
||||
else
|
||||
{
|
||||
sub->BSP->bDirty = false;
|
||||
}
|
||||
PolyNodeBuilder.ExtractMini(sub->BSP);
|
||||
for (unsigned int i = 0; i < sub->BSP->Subsectors.Size(); ++i)
|
||||
{
|
||||
sub->BSP->Subsectors[i].sector = sub->sector;
|
||||
}
|
||||
}
|
||||
|
||||
void R_Subsector (subsector_t *sub);
|
||||
static void R_AddPolyobjs(subsector_t *sub)
|
||||
{
|
||||
if (sub->BSP == NULL || sub->BSP->bDirty)
|
||||
{
|
||||
R_BuildPolyBSP(sub);
|
||||
sub->BuildPolyBSP();
|
||||
}
|
||||
if (sub->BSP->Nodes.Size() == 0)
|
||||
{
|
||||
|
|
|
@ -304,6 +304,9 @@ struct secplane_t
|
|||
{
|
||||
return -TMulScale16 (a, v->x, b, v->y, z, c);
|
||||
}
|
||||
|
||||
bool CopyPlaneIfValid (secplane_t *dest, const secplane_t *opp) const;
|
||||
|
||||
};
|
||||
|
||||
inline FArchive &operator<< (FArchive &arc, secplane_t &plane)
|
||||
|
@ -442,6 +445,8 @@ struct sector_t
|
|||
void SetColor(int r, int g, int b, int desat);
|
||||
void SetFade(int r, int g, int b);
|
||||
void ClosestPoint(fixed_t x, fixed_t y, fixed_t &ox, fixed_t &oy) const;
|
||||
int GetFloorLight () const;
|
||||
int GetCeilingLight () const;
|
||||
|
||||
DInterpolation *SetInterpolation(int position, bool attach);
|
||||
void StopInterpolation(int position);
|
||||
|
@ -990,6 +995,8 @@ struct subsector_t
|
|||
sector_t *render_sector;
|
||||
DWORD numlines;
|
||||
int flags;
|
||||
|
||||
void BuildPolyBSP();
|
||||
};
|
||||
|
||||
|
||||
|
@ -1019,8 +1026,6 @@ struct node_t
|
|||
|
||||
struct FMiniBSP
|
||||
{
|
||||
FMiniBSP();
|
||||
|
||||
bool bDirty;
|
||||
|
||||
TArray<node_t> Nodes;
|
||||
|
|
Loading…
Reference in a new issue