2016-09-14 18:01:13 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Copyright(C) 2000-2016 Christoph Oelckers
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with this program. If not, see http://www.gnu.org/licenses/
|
|
|
|
//
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
//
|
2013-06-23 07:49:34 +00:00
|
|
|
/*
|
|
|
|
** gl_bsp.cpp
|
|
|
|
** Main rendering loop / BSP traversal / visibility clipping
|
|
|
|
**
|
2016-09-14 18:01:13 +00:00
|
|
|
**/
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
#include "p_lnspec.h"
|
|
|
|
#include "p_local.h"
|
|
|
|
#include "a_sharedglobal.h"
|
2017-01-13 13:51:31 +00:00
|
|
|
#include "g_levellocals.h"
|
2013-06-23 07:49:34 +00:00
|
|
|
#include "p_effect.h"
|
|
|
|
#include "po_man.h"
|
2018-05-21 22:27:39 +00:00
|
|
|
#include "hwrenderer/scene/hw_fakeflat.h"
|
|
|
|
#include "hwrenderer/scene/hw_clipper.h"
|
|
|
|
#include "hwrenderer/scene/hw_drawstructs.h"
|
|
|
|
#include "hwrenderer/scene/hw_drawinfo.h"
|
|
|
|
#include "hwrenderer/scene/hw_portal.h"
|
|
|
|
#include "hwrenderer/utility/hw_clock.h"
|
2018-05-22 16:48:10 +00:00
|
|
|
#include "hwrenderer/data/flatvertices.h"
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
EXTERN_CVAR(Bool, gl_render_segs)
|
|
|
|
|
|
|
|
CVAR(Bool, gl_render_things, true, 0)
|
|
|
|
CVAR(Bool, gl_render_walls, true, 0)
|
|
|
|
CVAR(Bool, gl_render_flats, true, 0)
|
|
|
|
|
2018-05-21 22:27:39 +00:00
|
|
|
void HWDrawInfo::UnclipSubsector(subsector_t *sub)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
int count = sub->numlines;
|
|
|
|
seg_t * seg = sub->firstline;
|
2018-05-21 22:27:39 +00:00
|
|
|
auto &clipper = *mClipper;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
while (count--)
|
|
|
|
{
|
2017-03-11 23:19:20 +00:00
|
|
|
angle_t startAngle = clipper.GetClipAngle(seg->v2);
|
|
|
|
angle_t endAngle = clipper.GetClipAngle(seg->v1);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
// Back side, i.e. backface culling - read: endAngle >= startAngle!
|
|
|
|
if (startAngle-endAngle >= ANGLE_180)
|
|
|
|
{
|
|
|
|
clipper.SafeRemoveClipRange(startAngle, endAngle);
|
2016-07-23 08:23:34 +00:00
|
|
|
clipper.SetBlocked(false);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
seg++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// R_AddLine
|
|
|
|
// Clips the given segment
|
|
|
|
// and adds any visible pieces to the line list.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2018-05-21 22:27:39 +00:00
|
|
|
void HWDrawInfo::AddLine (seg_t *seg, bool portalclip)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
#ifdef _DEBUG
|
2017-01-08 13:39:16 +00:00
|
|
|
if (seg->linedef->Index() == 38)
|
2014-05-08 07:48:39 +00:00
|
|
|
{
|
|
|
|
int a = 0;
|
|
|
|
}
|
2013-06-23 07:49:34 +00:00
|
|
|
#endif
|
|
|
|
|
2018-05-21 22:27:39 +00:00
|
|
|
sector_t * backsector = nullptr;
|
2013-06-23 07:49:34 +00:00
|
|
|
sector_t bs;
|
|
|
|
|
2016-04-17 13:46:04 +00:00
|
|
|
if (portalclip)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2018-06-19 21:16:22 +00:00
|
|
|
int clipres = mClipPortal->ClipSeg(seg, Viewpoint.Pos);
|
2018-04-28 22:09:44 +00:00
|
|
|
if (clipres == PClip_InFront) return;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
2018-05-21 22:27:39 +00:00
|
|
|
auto &clipper = *mClipper;
|
2017-03-11 23:19:20 +00:00
|
|
|
angle_t startAngle = clipper.GetClipAngle(seg->v2);
|
|
|
|
angle_t endAngle = clipper.GetClipAngle(seg->v1);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
// Back side, i.e. backface culling - read: endAngle >= startAngle!
|
|
|
|
if (startAngle-endAngle<ANGLE_180)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-21 22:27:39 +00:00
|
|
|
if (seg->sidedef == nullptr)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2018-05-01 09:29:29 +00:00
|
|
|
if (!(currentsubsector->flags & SSECMF_DRAWN))
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
if (clipper.SafeCheckRange(startAngle, endAngle))
|
|
|
|
{
|
2018-05-01 09:29:29 +00:00
|
|
|
currentsubsector->flags |= SSECMF_DRAWN;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!clipper.SafeCheckRange(startAngle, endAngle))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2018-05-01 09:29:29 +00:00
|
|
|
currentsubsector->flags |= SSECMF_DRAWN;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2017-03-09 18:54:41 +00:00
|
|
|
uint8_t ispoly = uint8_t(seg->sidedef->Flags & WALLF_POLYOBJ);
|
2016-04-20 11:18:53 +00:00
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
if (!seg->backsector)
|
|
|
|
{
|
|
|
|
clipper.SafeAddClipRange(startAngle, endAngle);
|
|
|
|
}
|
2016-04-20 11:18:53 +00:00
|
|
|
else if (!ispoly) // Two-sided polyobjects never obstruct the view
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
if (currentsector->sectornum == seg->backsector->sectornum)
|
|
|
|
{
|
2016-11-17 22:13:17 +00:00
|
|
|
if (!seg->linedef->isVisualPortal())
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-11-17 22:13:17 +00:00
|
|
|
FTexture * tex = TexMan(seg->sidedef->GetTexture(side_t::mid));
|
2018-03-25 18:26:16 +00:00
|
|
|
if (!tex || tex->UseType==ETextureType::Null)
|
2016-11-17 22:13:17 +00:00
|
|
|
{
|
|
|
|
// nothing to do here!
|
|
|
|
seg->linedef->validcount=validcount;
|
|
|
|
return;
|
|
|
|
}
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
backsector=currentsector;
|
|
|
|
}
|
2018-05-01 09:29:29 +00:00
|
|
|
else
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
// clipping checks are only needed when the backsector is not the same as the front sector
|
2018-05-21 22:27:39 +00:00
|
|
|
if (in_area == area_default) in_area = hw_CheckViewArea(seg->v1, seg->v2, seg->frontsector, seg->backsector);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2018-05-21 22:27:39 +00:00
|
|
|
backsector = hw_FakeFlat(seg->backsector, &bs, in_area, true);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2018-04-24 15:52:35 +00:00
|
|
|
if (hw_CheckClip(seg->sidedef, currentsector, backsector))
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
clipper.SafeAddClipRange(startAngle, endAngle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Backsector for polyobj segs is always the containing sector itself
|
|
|
|
backsector = currentsector;
|
|
|
|
}
|
|
|
|
|
|
|
|
seg->linedef->flags |= ML_MAPPED;
|
|
|
|
|
2016-04-20 11:18:53 +00:00
|
|
|
if (ispoly || seg->linedef->validcount!=validcount)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-04-20 11:18:53 +00:00
|
|
|
if (!ispoly) seg->linedef->validcount=validcount;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
if (gl_render_walls)
|
|
|
|
{
|
|
|
|
SetupWall.Clock();
|
|
|
|
|
2018-04-26 22:22:00 +00:00
|
|
|
GLWall wall;
|
2014-08-23 16:54:24 +00:00
|
|
|
wall.sub = currentsubsector;
|
2018-05-21 22:27:39 +00:00
|
|
|
wall.Process(this, seg, currentsector, backsector);
|
2013-06-23 07:49:34 +00:00
|
|
|
rendered_lines++;
|
|
|
|
|
|
|
|
SetupWall.Unclock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// R_Subsector
|
|
|
|
// Determine floor/ceiling planes.
|
|
|
|
// Add sprites of things in sector.
|
|
|
|
// Draw one or more line segments.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2018-05-21 22:27:39 +00:00
|
|
|
void HWDrawInfo::PolySubsector(subsector_t * sub)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
int count = sub->numlines;
|
|
|
|
seg_t * line = sub->firstline;
|
|
|
|
|
|
|
|
while (count--)
|
|
|
|
{
|
|
|
|
if (line->linedef)
|
|
|
|
{
|
2018-05-21 22:27:39 +00:00
|
|
|
AddLine (line, mClipPortal != nullptr);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
line++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// RenderBSPNode
|
|
|
|
// Renders all subsectors below a given node,
|
|
|
|
// traversing subtree recursively.
|
|
|
|
// Just call with BSP root.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2018-05-21 22:27:39 +00:00
|
|
|
void HWDrawInfo::RenderPolyBSPNode (void *node)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
while (!((size_t)node & 1)) // Keep going until found a subsector
|
|
|
|
{
|
|
|
|
node_t *bsp = (node_t *)node;
|
|
|
|
|
|
|
|
// Decide which side the view point is on.
|
|
|
|
int side = R_PointOnSide(viewx, viewy, bsp);
|
|
|
|
|
|
|
|
// Recursively divide front space (toward the viewer).
|
|
|
|
RenderPolyBSPNode (bsp->children[side]);
|
|
|
|
|
|
|
|
// Possibly divide back space (away from the viewer).
|
|
|
|
side ^= 1;
|
|
|
|
|
|
|
|
// It is not necessary to use the slower precise version here
|
2018-05-21 22:27:39 +00:00
|
|
|
if (!mClipper->CheckBox(bsp->bbox[side]))
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
node = bsp->children[side];
|
|
|
|
}
|
2017-03-09 18:54:41 +00:00
|
|
|
PolySubsector ((subsector_t *)((uint8_t *)node - 1));
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Unlilke the software renderer this function will only draw the walls,
|
|
|
|
// not the flats. Those are handled as a whole by the parent subsector.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2018-05-21 22:27:39 +00:00
|
|
|
void HWDrawInfo::AddPolyobjs(subsector_t *sub)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2018-05-21 22:27:39 +00:00
|
|
|
if (sub->BSP == nullptr || sub->BSP->bDirty)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
sub->BuildPolyBSP();
|
2014-10-14 06:54:08 +00:00
|
|
|
for (unsigned i = 0; i < sub->BSP->Segs.Size(); i++)
|
|
|
|
{
|
|
|
|
sub->BSP->Segs[i].Subsector = sub;
|
2018-05-21 22:27:39 +00:00
|
|
|
sub->BSP->Segs[i].PartnerSeg = nullptr;
|
2014-10-14 06:54:08 +00:00
|
|
|
}
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
if (sub->BSP->Nodes.Size() == 0)
|
|
|
|
{
|
|
|
|
PolySubsector(&sub->BSP->Subsectors[0]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RenderPolyBSPNode(&sub->BSP->Nodes.Last());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2018-05-21 22:27:39 +00:00
|
|
|
void HWDrawInfo::AddLines(subsector_t * sub, sector_t * sector)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
currentsector = sector;
|
|
|
|
currentsubsector = sub;
|
|
|
|
|
|
|
|
ClipWall.Clock();
|
2018-05-21 22:27:39 +00:00
|
|
|
if (sub->polys != nullptr)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
AddPolyobjs(sub);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int count = sub->numlines;
|
|
|
|
seg_t * seg = sub->firstline;
|
|
|
|
|
|
|
|
while (count--)
|
|
|
|
{
|
2018-05-21 22:27:39 +00:00
|
|
|
if (seg->linedef == nullptr)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2018-05-21 22:27:39 +00:00
|
|
|
if (!(sub->flags & SSECMF_DRAWN)) AddLine (seg, mClipPortal != nullptr);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
else if (!(seg->sidedef->Flags & WALLF_POLYOBJ))
|
|
|
|
{
|
2018-05-21 22:27:39 +00:00
|
|
|
AddLine (seg, mClipPortal != nullptr);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
seg++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ClipWall.Unclock();
|
|
|
|
}
|
|
|
|
|
2016-04-17 13:46:04 +00:00
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Adds lines that lie directly on the portal boundary.
|
|
|
|
// Only two-sided lines will be handled here, and no polyobjects
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
inline bool PointOnLine(const DVector2 &pos, const line_t *line)
|
|
|
|
{
|
|
|
|
double v = (pos.Y - line->v1->fY()) * line->Delta().X + (line->v1->fX() - pos.X) * line->Delta().Y;
|
|
|
|
return fabs(v) <= EQUAL_EPSILON;
|
|
|
|
}
|
|
|
|
|
2018-05-21 22:27:39 +00:00
|
|
|
void HWDrawInfo::AddSpecialPortalLines(subsector_t * sub, sector_t * sector, line_t *line)
|
2016-04-17 13:46:04 +00:00
|
|
|
{
|
|
|
|
currentsector = sector;
|
|
|
|
currentsubsector = sub;
|
|
|
|
|
|
|
|
ClipWall.Clock();
|
|
|
|
int count = sub->numlines;
|
|
|
|
seg_t * seg = sub->firstline;
|
|
|
|
|
|
|
|
while (count--)
|
|
|
|
{
|
2018-05-21 22:27:39 +00:00
|
|
|
if (seg->linedef != nullptr && seg->PartnerSeg != nullptr)
|
2016-04-17 13:46:04 +00:00
|
|
|
{
|
|
|
|
if (PointOnLine(seg->v1->fPos(), line) && PointOnLine(seg->v2->fPos(), line))
|
|
|
|
AddLine(seg, false);
|
|
|
|
}
|
|
|
|
seg++;
|
|
|
|
}
|
|
|
|
ClipWall.Unclock();
|
|
|
|
}
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// R_RenderThings
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2018-05-21 22:27:39 +00:00
|
|
|
void HWDrawInfo::RenderThings(subsector_t * sub, sector_t * sector)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
SetupSprite.Clock();
|
|
|
|
sector_t * sec=sub->sector;
|
2016-04-18 21:52:15 +00:00
|
|
|
// Handle all things in sector.
|
2018-06-19 21:16:22 +00:00
|
|
|
const auto &vp = Viewpoint;
|
2016-12-26 11:11:55 +00:00
|
|
|
for (auto p = sec->touching_renderthings; p != nullptr; p = p->m_snext)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-12-26 11:11:55 +00:00
|
|
|
auto thing = p->m_thing;
|
|
|
|
if (thing->validcount == validcount) continue;
|
|
|
|
thing->validcount = validcount;
|
2016-12-25 22:23:05 +00:00
|
|
|
|
2017-04-11 22:07:41 +00:00
|
|
|
FIntCVar *cvar = thing->GetInfo()->distancecheck;
|
2018-05-21 22:27:39 +00:00
|
|
|
if (cvar != nullptr && *cvar >= 0)
|
2016-12-26 11:11:55 +00:00
|
|
|
{
|
2018-06-19 09:21:13 +00:00
|
|
|
double dist = (thing->Pos() - vp.Pos).LengthSquared();
|
2016-12-26 11:11:55 +00:00
|
|
|
double check = (double)**cvar;
|
|
|
|
if (dist >= check * check)
|
2016-04-12 17:50:29 +00:00
|
|
|
{
|
2016-12-26 11:11:55 +00:00
|
|
|
continue;
|
2016-04-12 17:50:29 +00:00
|
|
|
}
|
2016-12-25 22:23:05 +00:00
|
|
|
}
|
2018-04-28 18:02:17 +00:00
|
|
|
// If this thing is in a map section that's not in view it can't possibly be visible
|
2018-05-21 22:27:39 +00:00
|
|
|
if (CurrentMapSections[thing->subsector->mapsection])
|
2018-04-28 18:02:17 +00:00
|
|
|
{
|
|
|
|
GLSprite sprite;
|
2018-05-21 22:27:39 +00:00
|
|
|
sprite.Process(this, thing, sector, in_area, false);
|
2018-04-28 18:02:17 +00:00
|
|
|
}
|
2016-04-18 21:52:15 +00:00
|
|
|
}
|
2016-12-26 11:11:55 +00:00
|
|
|
|
2017-01-06 10:56:17 +00:00
|
|
|
for (msecnode_t *node = sec->sectorportal_thinglist; node; node = node->m_snext)
|
2016-04-18 21:52:15 +00:00
|
|
|
{
|
|
|
|
AActor *thing = node->m_thing;
|
2017-04-11 22:07:41 +00:00
|
|
|
FIntCVar *cvar = thing->GetInfo()->distancecheck;
|
2018-05-21 22:27:39 +00:00
|
|
|
if (cvar != nullptr && *cvar >= 0)
|
2016-04-18 21:52:15 +00:00
|
|
|
{
|
2018-06-19 09:21:13 +00:00
|
|
|
double dist = (thing->Pos() - vp.Pos).LengthSquared();
|
2016-04-18 21:52:15 +00:00
|
|
|
double check = (double)**cvar;
|
|
|
|
if (dist >= check * check)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
2016-04-18 21:52:15 +00:00
|
|
|
|
2018-04-28 18:02:17 +00:00
|
|
|
GLSprite sprite;
|
2018-05-21 22:27:39 +00:00
|
|
|
sprite.Process(this, thing, sector, in_area, true);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
SetupSprite.Unclock();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// R_Subsector
|
|
|
|
// Determine floor/ceiling planes.
|
|
|
|
// Add sprites of things in sector.
|
|
|
|
// Draw one or more line segments.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2018-05-21 22:27:39 +00:00
|
|
|
void HWDrawInfo::DoSubsector(subsector_t * sub)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
sector_t * sector;
|
|
|
|
sector_t * fakesector;
|
|
|
|
sector_t fake;
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
2017-01-07 18:32:24 +00:00
|
|
|
if (sub->sector->sectornum==931)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2014-05-08 07:48:39 +00:00
|
|
|
int a = 0;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
sector=sub->sector;
|
|
|
|
if (!sector) return;
|
|
|
|
|
|
|
|
// If the mapsections differ this subsector can't possibly be visible from the current view point
|
2018-05-21 22:27:39 +00:00
|
|
|
if (!CurrentMapSections[sub->mapsection]) return;
|
2016-04-03 09:40:14 +00:00
|
|
|
if (sub->flags & SSECF_POLYORG) return; // never render polyobject origin subsectors because their vertices no longer are where one may expect.
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2018-05-21 22:27:39 +00:00
|
|
|
if (ss_renderflags[sub->Index()] & SSRF_SEEN)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
// This means that we have reached a subsector in a portal that has been marked 'seen'
|
|
|
|
// from the other side of the portal. This means we must clear the clipper for the
|
|
|
|
// range this subsector spans before going on.
|
|
|
|
UnclipSubsector(sub);
|
|
|
|
}
|
2018-05-21 22:27:39 +00:00
|
|
|
if (mClipper->IsBlocked()) return; // if we are inside a stacked sector portal which hasn't unclipped anything yet.
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2018-05-21 22:27:39 +00:00
|
|
|
fakesector=hw_FakeFlat(sector, &fake, in_area, false);
|
2016-04-17 13:46:04 +00:00
|
|
|
|
2018-05-21 22:27:39 +00:00
|
|
|
if (mClipPortal)
|
2016-01-27 11:02:43 +00:00
|
|
|
{
|
2018-05-21 22:27:39 +00:00
|
|
|
int clipres = mClipPortal->ClipSubsector(sub);
|
2018-04-28 22:09:44 +00:00
|
|
|
if (clipres == PClip_InFront)
|
2016-04-17 13:46:04 +00:00
|
|
|
{
|
2018-05-21 22:27:39 +00:00
|
|
|
line_t *line = mClipPortal->ClipLine();
|
2016-04-17 13:46:04 +00:00
|
|
|
// The subsector is out of range, but we still have to check lines that lie directly on the boundary and may expose their upper or lower parts.
|
|
|
|
if (line) AddSpecialPortalLines(sub, fakesector, line);
|
|
|
|
return;
|
|
|
|
}
|
2016-01-27 11:02:43 +00:00
|
|
|
}
|
|
|
|
|
2013-06-23 07:49:34 +00:00
|
|
|
if (sector->validcount != validcount)
|
|
|
|
{
|
2018-05-23 22:01:56 +00:00
|
|
|
if (sector->Index() == 62)
|
|
|
|
{
|
|
|
|
int a = 0;
|
|
|
|
}
|
2018-05-22 16:48:10 +00:00
|
|
|
mVBO->CheckUpdate(sector);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// [RH] Add particles
|
|
|
|
//int shade = LIGHT2SHADE((floorlightlevel + ceilinglightlevel)/2 + r_actualextralight);
|
|
|
|
if (gl_render_things)
|
|
|
|
{
|
|
|
|
SetupSprite.Clock();
|
|
|
|
|
2017-03-16 23:22:52 +00:00
|
|
|
for (i = ParticlesInSubsec[sub->Index()]; i != NO_PARTICLE; i = Particles[i].snext)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2018-05-21 22:27:39 +00:00
|
|
|
if (mClipPortal)
|
2018-04-28 22:09:44 +00:00
|
|
|
{
|
2018-05-21 22:27:39 +00:00
|
|
|
int clipres = mClipPortal->ClipPoint(Particles[i].Pos);
|
2018-04-28 22:09:44 +00:00
|
|
|
if (clipres == PClip_InFront) continue;
|
|
|
|
}
|
|
|
|
|
2018-04-28 18:02:17 +00:00
|
|
|
GLSprite sprite;
|
2018-05-21 22:27:39 +00:00
|
|
|
sprite.ProcessParticle(this, &Particles[i], fakesector);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
SetupSprite.Unclock();
|
|
|
|
}
|
|
|
|
|
|
|
|
AddLines(sub, fakesector);
|
|
|
|
|
|
|
|
// BSP is traversed by subsector.
|
|
|
|
// A sector might have been split into several
|
|
|
|
// subsectors during BSP building.
|
|
|
|
// Thus we check whether it was already added.
|
|
|
|
if (sector->validcount != validcount)
|
|
|
|
{
|
|
|
|
// Well, now it will be done.
|
|
|
|
sector->validcount = validcount;
|
|
|
|
|
|
|
|
if (gl_render_things)
|
|
|
|
{
|
|
|
|
RenderThings(sub, fakesector);
|
|
|
|
}
|
2018-05-01 09:29:29 +00:00
|
|
|
sector->MoreFlags |= SECMF_DRAWN;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (gl_render_flats)
|
|
|
|
{
|
2016-04-20 09:39:41 +00:00
|
|
|
// Subsectors with only 2 lines cannot have any area
|
2013-06-23 07:49:34 +00:00
|
|
|
if (sub->numlines>2 || (sub->hacked&1))
|
|
|
|
{
|
|
|
|
// Exclude the case when it tries to render a sector with a heightsec
|
|
|
|
// but undetermined heightsec state. This can only happen if the
|
|
|
|
// subsector is obstructed but not excluded due to a large bounding box.
|
|
|
|
// Due to the way a BSP works such a subsector can never be visible
|
2018-05-21 22:27:39 +00:00
|
|
|
if (!sector->GetHeightSec() || in_area!=area_default)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
if (sector != sub->render_sector)
|
|
|
|
{
|
|
|
|
sector = sub->render_sector;
|
|
|
|
// the planes of this subsector are faked to belong to another sector
|
|
|
|
// This means we need the heightsec parts and light info of the render sector, not the actual one.
|
2018-05-21 22:27:39 +00:00
|
|
|
fakesector = hw_FakeFlat(sector, &fake, in_area, false);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
2018-05-21 22:27:39 +00:00
|
|
|
uint8_t &srf = sectorrenderflags[sub->render_sector->sectornum];
|
2013-06-23 07:49:34 +00:00
|
|
|
if (!(srf & SSRF_PROCESSED))
|
|
|
|
{
|
|
|
|
srf |= SSRF_PROCESSED;
|
|
|
|
|
|
|
|
SetupFlat.Clock();
|
2018-04-28 10:34:09 +00:00
|
|
|
GLFlat flat;
|
2018-05-21 22:27:39 +00:00
|
|
|
flat.ProcessSector(this, fakesector);
|
2013-06-23 07:49:34 +00:00
|
|
|
SetupFlat.Unclock();
|
|
|
|
}
|
|
|
|
// mark subsector as processed - but mark for rendering only if it has an actual area.
|
2018-05-21 22:27:39 +00:00
|
|
|
ss_renderflags[sub->Index()] =
|
2013-06-23 07:49:34 +00:00
|
|
|
(sub->numlines > 2) ? SSRF_PROCESSED|SSRF_RENDERALL : SSRF_PROCESSED;
|
2018-05-21 22:27:39 +00:00
|
|
|
if (sub->hacked & 1) AddHackedSubsector(sub);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2018-04-01 20:26:57 +00:00
|
|
|
FSectorPortalGroup *portal;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2018-04-01 20:26:57 +00:00
|
|
|
portal = fakesector->GetPortalGroup(sector_t::ceiling);
|
2018-05-21 22:27:39 +00:00
|
|
|
if (portal != nullptr)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2018-05-21 22:27:39 +00:00
|
|
|
portal->AddSubsector(sub);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-01 20:26:57 +00:00
|
|
|
portal = fakesector->GetPortalGroup(sector_t::floor);
|
2018-05-21 22:27:39 +00:00
|
|
|
if (portal != nullptr)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2018-05-21 22:27:39 +00:00
|
|
|
portal->AddSubsector(sub);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// RenderBSPNode
|
|
|
|
// Renders all subsectors below a given node,
|
|
|
|
// traversing subtree recursively.
|
|
|
|
// Just call with BSP root.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2018-05-21 22:27:39 +00:00
|
|
|
void HWDrawInfo::RenderBSPNode (void *node)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-03-17 00:42:37 +00:00
|
|
|
if (level.nodes.Size() == 0)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-03-16 23:22:52 +00:00
|
|
|
DoSubsector (&level.subsectors[0]);
|
2013-06-23 07:49:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
while (!((size_t)node & 1)) // Keep going until found a subsector
|
|
|
|
{
|
|
|
|
node_t *bsp = (node_t *)node;
|
|
|
|
|
|
|
|
// Decide which side the view point is on.
|
|
|
|
int side = R_PointOnSide(viewx, viewy, bsp);
|
|
|
|
|
|
|
|
// Recursively divide front space (toward the viewer).
|
2017-03-11 23:19:20 +00:00
|
|
|
RenderBSPNode (bsp->children[side]);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
// Possibly divide back space (away from the viewer).
|
|
|
|
side ^= 1;
|
|
|
|
|
|
|
|
// It is not necessary to use the slower precise version here
|
2018-05-21 22:27:39 +00:00
|
|
|
if (!mClipper->CheckBox(bsp->bbox[side]))
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2018-05-21 22:27:39 +00:00
|
|
|
if (!(no_renderflags[bsp->Index()] & SSRF_SEEN))
|
2013-06-23 07:49:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
node = bsp->children[side];
|
|
|
|
}
|
2017-03-09 18:54:41 +00:00
|
|
|
DoSubsector ((subsector_t *)((uint8_t *)node - 1));
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|