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
|
|
|
/*
|
2016-09-14 18:01:13 +00:00
|
|
|
** gl_renderhacks.cpp
|
2013-06-23 07:49:34 +00:00
|
|
|
** Handles missing upper and lower textures and self referencing sector hacks
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "a_sharedglobal.h"
|
|
|
|
#include "r_utility.h"
|
|
|
|
#include "r_defs.h"
|
|
|
|
#include "r_sky.h"
|
|
|
|
#include "g_level.h"
|
2017-01-08 17:45:30 +00:00
|
|
|
#include "g_levellocals.h"
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
#include "gl/renderer/gl_renderer.h"
|
|
|
|
#include "gl/data/gl_data.h"
|
|
|
|
#include "gl/dynlights/gl_glow.h"
|
|
|
|
#include "gl/scene/gl_drawinfo.h"
|
|
|
|
#include "gl/scene/gl_portal.h"
|
2017-03-12 22:13:07 +00:00
|
|
|
#include "gl/scene/gl_scenedrawer.h"
|
2013-06-23 07:49:34 +00:00
|
|
|
#include "gl/utility/gl_clock.h"
|
|
|
|
#include "gl/utility/gl_templates.h"
|
|
|
|
|
|
|
|
|
|
|
|
// This is for debugging maps.
|
|
|
|
|
|
|
|
FreeList<gl_subsectorrendernode> SSR_List;
|
|
|
|
|
|
|
|
// profiling data
|
|
|
|
static int totalupper, totallower;
|
|
|
|
static int lowershcount, uppershcount;
|
|
|
|
static glcycle_t totalms, showtotalms;
|
|
|
|
static glcycle_t totalssms;
|
|
|
|
static sector_t fakesec;
|
|
|
|
|
|
|
|
void FDrawInfo::ClearBuffers()
|
|
|
|
{
|
|
|
|
for(unsigned int i=0;i< otherfloorplanes.Size();i++)
|
|
|
|
{
|
|
|
|
gl_subsectorrendernode * node = otherfloorplanes[i];
|
|
|
|
while (node)
|
|
|
|
{
|
|
|
|
gl_subsectorrendernode * n = node;
|
|
|
|
node = node->next;
|
|
|
|
SSR_List.Release(n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
otherfloorplanes.Clear();
|
|
|
|
|
|
|
|
for(unsigned int i=0;i< otherceilingplanes.Size();i++)
|
|
|
|
{
|
|
|
|
gl_subsectorrendernode * node = otherceilingplanes[i];
|
|
|
|
while (node)
|
|
|
|
{
|
|
|
|
gl_subsectorrendernode * n = node;
|
|
|
|
node = node->next;
|
|
|
|
SSR_List.Release(n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
otherceilingplanes.Clear();
|
|
|
|
|
|
|
|
// clear all the lists that might not have been cleared already
|
|
|
|
MissingUpperTextures.Clear();
|
|
|
|
MissingLowerTextures.Clear();
|
|
|
|
MissingUpperSegs.Clear();
|
|
|
|
MissingLowerSegs.Clear();
|
|
|
|
SubsectorHacks.Clear();
|
|
|
|
CeilingStacks.Clear();
|
|
|
|
FloorStacks.Clear();
|
|
|
|
HandledSubsectors.Clear();
|
|
|
|
|
|
|
|
}
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Adds a subsector plane to a sector's render list
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void FDrawInfo::AddOtherFloorPlane(int sector, gl_subsectorrendernode * node)
|
|
|
|
{
|
|
|
|
int oldcnt = otherfloorplanes.Size();
|
|
|
|
|
|
|
|
if (oldcnt<=sector)
|
|
|
|
{
|
|
|
|
otherfloorplanes.Resize(sector+1);
|
|
|
|
for(int i=oldcnt;i<=sector;i++) otherfloorplanes[i]=NULL;
|
|
|
|
}
|
|
|
|
node->next = otherfloorplanes[sector];
|
|
|
|
otherfloorplanes[sector] = node;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FDrawInfo::AddOtherCeilingPlane(int sector, gl_subsectorrendernode * node)
|
|
|
|
{
|
|
|
|
int oldcnt = otherceilingplanes.Size();
|
|
|
|
|
|
|
|
if (oldcnt<=sector)
|
|
|
|
{
|
|
|
|
otherceilingplanes.Resize(sector+1);
|
|
|
|
for(int i=oldcnt;i<=sector;i++) otherceilingplanes[i]=NULL;
|
|
|
|
}
|
|
|
|
node->next = otherceilingplanes[sector];
|
|
|
|
otherceilingplanes[sector] = node;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Collects all sectors that might need a fake ceiling
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2016-04-07 23:42:43 +00:00
|
|
|
void FDrawInfo::AddUpperMissingTexture(side_t * side, subsector_t *sub, float Backheight)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
if (!side->segs[0]->backsector) return;
|
|
|
|
|
|
|
|
totalms.Clock();
|
2016-04-07 23:42:43 +00:00
|
|
|
for (int i = 0; i < side->numsegs; i++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
seg_t *seg = side->segs[i];
|
|
|
|
|
|
|
|
// we need find the seg belonging to the passed subsector
|
|
|
|
if (seg->Subsector == sub)
|
|
|
|
{
|
|
|
|
MissingTextureInfo mti = {};
|
|
|
|
MissingSegInfo msi;
|
|
|
|
|
|
|
|
|
2016-04-07 23:42:43 +00:00
|
|
|
if (sub->render_sector != sub->sector || seg->frontsector != sub->sector)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
totalms.Unclock();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-07 23:42:43 +00:00
|
|
|
for (unsigned int i = 0; i < MissingUpperTextures.Size(); i++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
if (MissingUpperTextures[i].sub == sub)
|
|
|
|
{
|
|
|
|
// Use the lowest adjoining height to draw a fake ceiling if necessary
|
2016-04-07 23:42:43 +00:00
|
|
|
if (Backheight < MissingUpperTextures[i].Planez)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-04-07 23:42:43 +00:00
|
|
|
MissingUpperTextures[i].Planez = Backheight;
|
2013-06-23 07:49:34 +00:00
|
|
|
MissingUpperTextures[i].seg = seg;
|
|
|
|
}
|
|
|
|
|
|
|
|
msi.MTI_Index = i;
|
2016-04-07 23:42:43 +00:00
|
|
|
msi.seg = seg;
|
2013-06-23 07:49:34 +00:00
|
|
|
MissingUpperSegs.Push(msi);
|
|
|
|
totalms.Unclock();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-04-07 23:42:43 +00:00
|
|
|
mti.seg = seg;
|
|
|
|
mti.sub = sub;
|
|
|
|
mti.Planez = Backheight;
|
2013-06-23 07:49:34 +00:00
|
|
|
msi.MTI_Index = MissingUpperTextures.Push(mti);
|
2016-04-07 23:42:43 +00:00
|
|
|
msi.seg = seg;
|
2013-06-23 07:49:34 +00:00
|
|
|
MissingUpperSegs.Push(msi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
totalms.Unclock();
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Collects all sectors that might need a fake floor
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2016-04-07 23:42:43 +00:00
|
|
|
void FDrawInfo::AddLowerMissingTexture(side_t * side, subsector_t *sub, float Backheight)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
sector_t *backsec = side->segs[0]->backsector;
|
|
|
|
if (!backsec) return;
|
|
|
|
if (backsec->transdoor)
|
|
|
|
{
|
|
|
|
// Transparent door hacks alter the backsector's floor height so we should not
|
|
|
|
// process the missing texture for them.
|
|
|
|
if (backsec->transdoorheight == backsec->GetPlaneTexZ(sector_t::floor)) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
totalms.Clock();
|
|
|
|
// we need to check all segs of this sidedef
|
2016-04-07 23:42:43 +00:00
|
|
|
for (int i = 0; i < side->numsegs; i++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
seg_t *seg = side->segs[i];
|
|
|
|
|
|
|
|
// we need find the seg belonging to the passed subsector
|
|
|
|
if (seg->Subsector == sub)
|
|
|
|
{
|
|
|
|
MissingTextureInfo mti = {};
|
|
|
|
MissingSegInfo msi;
|
|
|
|
|
|
|
|
subsector_t * sub = seg->Subsector;
|
|
|
|
|
2016-04-07 23:42:43 +00:00
|
|
|
if (sub->render_sector != sub->sector || seg->frontsector != sub->sector)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
totalms.Unclock();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore FF_FIX's because they are designed to abuse missing textures
|
2016-04-07 23:42:43 +00:00
|
|
|
if (seg->backsector->e->XFloor.ffloors.Size() && (seg->backsector->e->XFloor.ffloors[0]->flags&(FF_FIX | FF_SEETHROUGH)) == FF_FIX)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
totalms.Unclock();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-07 23:42:43 +00:00
|
|
|
for (unsigned int i = 0; i < MissingLowerTextures.Size(); i++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
if (MissingLowerTextures[i].sub == sub)
|
|
|
|
{
|
|
|
|
// Use the highest adjoining height to draw a fake floor if necessary
|
2016-04-07 23:42:43 +00:00
|
|
|
if (Backheight > MissingLowerTextures[i].Planez)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-04-07 23:42:43 +00:00
|
|
|
MissingLowerTextures[i].Planez = Backheight;
|
2013-06-23 07:49:34 +00:00
|
|
|
MissingLowerTextures[i].seg = seg;
|
|
|
|
}
|
|
|
|
|
|
|
|
msi.MTI_Index = i;
|
2016-04-07 23:42:43 +00:00
|
|
|
msi.seg = seg;
|
2013-06-23 07:49:34 +00:00
|
|
|
MissingLowerSegs.Push(msi);
|
|
|
|
totalms.Unclock();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-04-07 23:42:43 +00:00
|
|
|
mti.seg = seg;
|
2013-06-23 07:49:34 +00:00
|
|
|
mti.sub = sub;
|
2016-04-07 23:42:43 +00:00
|
|
|
mti.Planez = Backheight;
|
2013-06-23 07:49:34 +00:00
|
|
|
msi.MTI_Index = MissingLowerTextures.Push(mti);
|
2016-04-07 23:42:43 +00:00
|
|
|
msi.seg = seg;
|
2013-06-23 07:49:34 +00:00
|
|
|
MissingLowerSegs.Push(msi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
totalms.Unclock();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2016-04-07 23:42:43 +00:00
|
|
|
bool FDrawInfo::DoOneSectorUpper(subsector_t * subsec, float Planez)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
// Is there a one-sided wall in this sector?
|
|
|
|
// Do this first to avoid unnecessary recursion
|
2017-03-09 19:19:55 +00:00
|
|
|
for (uint32_t i = 0; i < subsec->numlines; i++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
if (subsec->firstline[i].backsector == NULL) return false;
|
|
|
|
if (subsec->firstline[i].PartnerSeg == NULL) return false;
|
|
|
|
}
|
|
|
|
|
2017-03-09 19:19:55 +00:00
|
|
|
for (uint32_t i = 0; i < subsec->numlines; i++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-04-07 23:42:43 +00:00
|
|
|
seg_t * seg = subsec->firstline + i;
|
2013-06-23 07:49:34 +00:00
|
|
|
subsector_t * backsub = seg->PartnerSeg->Subsector;
|
|
|
|
|
|
|
|
// already checked?
|
2016-04-07 23:42:43 +00:00
|
|
|
if (backsub->validcount == validcount) continue;
|
|
|
|
backsub->validcount = validcount;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
if (seg->frontsector != seg->backsector && seg->linedef)
|
|
|
|
{
|
|
|
|
// Note: if this is a real line between sectors
|
|
|
|
// we can be sure that render_sector is the real sector!
|
|
|
|
|
2017-03-12 22:13:07 +00:00
|
|
|
sector_t * sec = gl_FakeFlat(seg->backsector, &fakesec, mDrawer->in_area, true);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
// Don't bother with slopes
|
2016-03-29 11:45:50 +00:00
|
|
|
if (sec->ceilingplane.isSlope()) return false;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
// Is the neighboring ceiling lower than the desired height?
|
2016-04-24 11:35:43 +00:00
|
|
|
if (sec->GetPlaneTexZ(sector_t::ceiling) < Planez)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
// todo: check for missing textures.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is an exact height match which means we don't have to do any further checks for this sector
|
2016-04-24 11:35:43 +00:00
|
|
|
if (sec->GetPlaneTexZ(sector_t::ceiling) == Planez)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
// If there's a texture abort
|
|
|
|
FTexture * tex = TexMan[seg->sidedef->GetTexture(side_t::top)];
|
2018-03-25 18:26:16 +00:00
|
|
|
if (!tex || tex->UseType == ETextureType::Null) continue;
|
2013-06-23 07:49:34 +00:00
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
}
|
2016-04-07 23:42:43 +00:00
|
|
|
if (!DoOneSectorUpper(backsub, Planez)) return false;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
// all checked ok. This subsector is part of the current fake plane
|
|
|
|
|
|
|
|
HandledSubsectors.Push(subsec);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2016-04-07 23:42:43 +00:00
|
|
|
bool FDrawInfo::DoOneSectorLower(subsector_t * subsec, float Planez)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
// Is there a one-sided wall in this subsector?
|
|
|
|
// Do this first to avoid unnecessary recursion
|
2017-03-09 19:19:55 +00:00
|
|
|
for (uint32_t i = 0; i < subsec->numlines; i++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
if (subsec->firstline[i].backsector == NULL) return false;
|
|
|
|
if (subsec->firstline[i].PartnerSeg == NULL) return false;
|
|
|
|
}
|
|
|
|
|
2017-03-09 19:19:55 +00:00
|
|
|
for (uint32_t i = 0; i < subsec->numlines; i++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
seg_t * seg = subsec->firstline + i;
|
|
|
|
subsector_t * backsub = seg->PartnerSeg->Subsector;
|
|
|
|
|
|
|
|
// already checked?
|
2016-04-07 23:42:43 +00:00
|
|
|
if (backsub->validcount == validcount) continue;
|
|
|
|
backsub->validcount = validcount;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
if (seg->frontsector != seg->backsector && seg->linedef)
|
|
|
|
{
|
|
|
|
// Note: if this is a real line between sectors
|
|
|
|
// we can be sure that render_sector is the real sector!
|
|
|
|
|
2017-03-12 22:13:07 +00:00
|
|
|
sector_t * sec = gl_FakeFlat(seg->backsector, &fakesec, mDrawer->in_area, true);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
// Don't bother with slopes
|
2016-03-29 11:45:50 +00:00
|
|
|
if (sec->floorplane.isSlope()) return false;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
// Is the neighboring floor higher than the desired height?
|
2016-04-24 11:35:43 +00:00
|
|
|
if (sec->GetPlaneTexZ(sector_t::floor) > Planez)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
// todo: check for missing textures.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is an exact height match which means we don't have to do any further checks for this sector
|
2016-04-24 11:35:43 +00:00
|
|
|
if (sec->GetPlaneTexZ(sector_t::floor) == Planez)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
// If there's a texture abort
|
|
|
|
FTexture * tex = TexMan[seg->sidedef->GetTexture(side_t::bottom)];
|
2018-03-25 18:26:16 +00:00
|
|
|
if (!tex || tex->UseType == ETextureType::Null) continue;
|
2013-06-23 07:49:34 +00:00
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
}
|
2016-04-07 23:42:43 +00:00
|
|
|
if (!DoOneSectorLower(backsub, Planez)) return false;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
// all checked ok. This sector is part of the current fake plane
|
|
|
|
|
|
|
|
HandledSubsectors.Push(subsec);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2016-04-07 23:42:43 +00:00
|
|
|
bool FDrawInfo::DoFakeBridge(subsector_t * subsec, float Planez)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
// Is there a one-sided wall in this sector?
|
|
|
|
// Do this first to avoid unnecessary recursion
|
2017-03-09 19:19:55 +00:00
|
|
|
for (uint32_t i = 0; i < subsec->numlines; i++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
if (subsec->firstline[i].backsector == NULL) return false;
|
|
|
|
if (subsec->firstline[i].PartnerSeg == NULL) return false;
|
|
|
|
}
|
|
|
|
|
2017-03-09 19:19:55 +00:00
|
|
|
for (uint32_t i = 0; i < subsec->numlines; i++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
seg_t * seg = subsec->firstline + i;
|
|
|
|
subsector_t * backsub = seg->PartnerSeg->Subsector;
|
|
|
|
|
|
|
|
// already checked?
|
2016-04-07 23:42:43 +00:00
|
|
|
if (backsub->validcount == validcount) continue;
|
|
|
|
backsub->validcount = validcount;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
if (seg->frontsector != seg->backsector && seg->linedef)
|
|
|
|
{
|
|
|
|
// Note: if this is a real line between sectors
|
|
|
|
// we can be sure that render_sector is the real sector!
|
|
|
|
|
2017-03-12 22:13:07 +00:00
|
|
|
sector_t * sec = gl_FakeFlat(seg->backsector, &fakesec, mDrawer->in_area, true);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
// Don't bother with slopes
|
2016-03-29 11:45:50 +00:00
|
|
|
if (sec->floorplane.isSlope()) return false;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
// Is the neighboring floor higher than the desired height?
|
2016-04-24 11:35:43 +00:00
|
|
|
if (sec->GetPlaneTexZ(sector_t::floor) < Planez)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
// todo: check for missing textures.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is an exact height match which means we don't have to do any further checks for this sector
|
|
|
|
// No texture checks though!
|
2016-04-24 11:35:43 +00:00
|
|
|
if (sec->GetPlaneTexZ(sector_t::floor) == Planez) continue;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
2016-04-07 23:42:43 +00:00
|
|
|
if (!DoFakeBridge(backsub, Planez)) return false;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
// all checked ok. This sector is part of the current fake plane
|
|
|
|
|
|
|
|
HandledSubsectors.Push(subsec);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2016-04-07 23:42:43 +00:00
|
|
|
bool FDrawInfo::DoFakeCeilingBridge(subsector_t * subsec, float Planez)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
// Is there a one-sided wall in this sector?
|
|
|
|
// Do this first to avoid unnecessary recursion
|
2017-03-09 19:19:55 +00:00
|
|
|
for (uint32_t i = 0; i < subsec->numlines; i++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
if (subsec->firstline[i].backsector == NULL) return false;
|
|
|
|
if (subsec->firstline[i].PartnerSeg == NULL) return false;
|
|
|
|
}
|
|
|
|
|
2017-03-09 19:19:55 +00:00
|
|
|
for (uint32_t i = 0; i < subsec->numlines; i++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
seg_t * seg = subsec->firstline + i;
|
|
|
|
subsector_t * backsub = seg->PartnerSeg->Subsector;
|
|
|
|
|
|
|
|
// already checked?
|
2016-04-07 23:42:43 +00:00
|
|
|
if (backsub->validcount == validcount) continue;
|
|
|
|
backsub->validcount = validcount;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
if (seg->frontsector != seg->backsector && seg->linedef)
|
|
|
|
{
|
|
|
|
// Note: if this is a real line between sectors
|
|
|
|
// we can be sure that render_sector is the real sector!
|
|
|
|
|
2017-03-12 22:13:07 +00:00
|
|
|
sector_t * sec = gl_FakeFlat(seg->backsector, &fakesec, mDrawer->in_area, true);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
// Don't bother with slopes
|
2016-03-29 11:45:50 +00:00
|
|
|
if (sec->ceilingplane.isSlope()) return false;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
// Is the neighboring ceiling higher than the desired height?
|
2016-04-24 11:35:43 +00:00
|
|
|
if (sec->GetPlaneTexZ(sector_t::ceiling) > Planez)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
// todo: check for missing textures.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is an exact height match which means we don't have to do any further checks for this sector
|
|
|
|
// No texture checks though!
|
2016-04-24 11:35:43 +00:00
|
|
|
if (sec->GetPlaneTexZ(sector_t::ceiling) == Planez) continue;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
2016-04-07 23:42:43 +00:00
|
|
|
if (!DoFakeCeilingBridge(backsub, Planez)) return false;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
// all checked ok. This sector is part of the current fake plane
|
|
|
|
|
|
|
|
HandledSubsectors.Push(subsec);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Draws the fake planes
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
void FDrawInfo::HandleMissingTextures()
|
|
|
|
{
|
|
|
|
sector_t fake;
|
|
|
|
totalms.Clock();
|
2016-04-07 23:42:43 +00:00
|
|
|
totalupper = MissingUpperTextures.Size();
|
|
|
|
totallower = MissingLowerTextures.Size();
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2016-04-07 23:42:43 +00:00
|
|
|
for (unsigned int i = 0; i < MissingUpperTextures.Size(); i++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
if (!MissingUpperTextures[i].seg) continue;
|
|
|
|
HandledSubsectors.Clear();
|
|
|
|
validcount++;
|
|
|
|
|
2017-03-11 22:28:07 +00:00
|
|
|
if (MissingUpperTextures[i].Planez > r_viewpoint.Pos.Z)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
// close the hole only if all neighboring sectors are an exact height match
|
|
|
|
// Otherwise just fill in the missing textures.
|
2016-04-07 23:42:43 +00:00
|
|
|
MissingUpperTextures[i].sub->validcount = validcount;
|
|
|
|
if (DoOneSectorUpper(MissingUpperTextures[i].sub, MissingUpperTextures[i].Planez))
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
sector_t * sec = MissingUpperTextures[i].seg->backsector;
|
|
|
|
// The mere fact that this seg has been added to the list means that the back sector
|
|
|
|
// will be rendered so we can safely assume that it is already in the render list
|
|
|
|
|
2016-04-07 23:42:43 +00:00
|
|
|
for (unsigned int j = 0; j < HandledSubsectors.Size(); j++)
|
|
|
|
{
|
2013-06-23 07:49:34 +00:00
|
|
|
gl_subsectorrendernode * node = SSR_List.GetNew();
|
|
|
|
node->sub = HandledSubsectors[j];
|
|
|
|
|
|
|
|
AddOtherCeilingPlane(sec->sectornum, node);
|
|
|
|
}
|
|
|
|
|
2016-04-07 23:42:43 +00:00
|
|
|
if (HandledSubsectors.Size() != 1)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
// mark all subsectors in the missing list that got processed by this
|
2016-04-07 23:42:43 +00:00
|
|
|
for (unsigned int j = 0; j < HandledSubsectors.Size(); j++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-04-07 23:42:43 +00:00
|
|
|
for (unsigned int k = 0; k < MissingUpperTextures.Size(); k++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-04-07 23:42:43 +00:00
|
|
|
if (MissingUpperTextures[k].sub == HandledSubsectors[j])
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-04-07 23:42:43 +00:00
|
|
|
MissingUpperTextures[k].seg = NULL;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-07 23:42:43 +00:00
|
|
|
else MissingUpperTextures[i].seg = NULL;
|
2013-06-23 07:49:34 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!MissingUpperTextures[i].seg->PartnerSeg) continue;
|
|
|
|
subsector_t *backsub = MissingUpperTextures[i].seg->PartnerSeg->Subsector;
|
|
|
|
if (!backsub) continue;
|
|
|
|
validcount++;
|
|
|
|
HandledSubsectors.Clear();
|
|
|
|
|
|
|
|
{
|
|
|
|
// It isn't a hole. Now check whether it might be a fake bridge
|
2017-03-12 22:13:07 +00:00
|
|
|
sector_t * fakesector = gl_FakeFlat(MissingUpperTextures[i].seg->frontsector, &fake, mDrawer->in_area, false);
|
2016-04-24 11:35:43 +00:00
|
|
|
float planez = (float)fakesector->GetPlaneTexZ(sector_t::ceiling);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2016-04-07 23:42:43 +00:00
|
|
|
backsub->validcount = validcount;
|
2013-06-23 07:49:34 +00:00
|
|
|
if (DoFakeCeilingBridge(backsub, planez))
|
|
|
|
{
|
|
|
|
// The mere fact that this seg has been added to the list means that the back sector
|
|
|
|
// will be rendered so we can safely assume that it is already in the render list
|
|
|
|
|
2016-04-07 23:42:43 +00:00
|
|
|
for (unsigned int j = 0; j < HandledSubsectors.Size(); j++)
|
|
|
|
{
|
2013-06-23 07:49:34 +00:00
|
|
|
gl_subsectorrendernode * node = SSR_List.GetNew();
|
|
|
|
node->sub = HandledSubsectors[j];
|
|
|
|
AddOtherCeilingPlane(fakesector->sectornum, node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-07 23:42:43 +00:00
|
|
|
for (unsigned int i = 0; i < MissingLowerTextures.Size(); i++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
if (!MissingLowerTextures[i].seg) continue;
|
|
|
|
HandledSubsectors.Clear();
|
|
|
|
validcount++;
|
|
|
|
|
2017-03-11 22:28:07 +00:00
|
|
|
if (MissingLowerTextures[i].Planez < r_viewpoint.Pos.Z)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
// close the hole only if all neighboring sectors are an exact height match
|
|
|
|
// Otherwise just fill in the missing textures.
|
2016-04-07 23:42:43 +00:00
|
|
|
MissingLowerTextures[i].sub->validcount = validcount;
|
|
|
|
if (DoOneSectorLower(MissingLowerTextures[i].sub, MissingLowerTextures[i].Planez))
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
sector_t * sec = MissingLowerTextures[i].seg->backsector;
|
|
|
|
// The mere fact that this seg has been added to the list means that the back sector
|
|
|
|
// will be rendered so we can safely assume that it is already in the render list
|
|
|
|
|
2016-04-07 23:42:43 +00:00
|
|
|
for (unsigned int j = 0; j < HandledSubsectors.Size(); j++)
|
|
|
|
{
|
2013-06-23 07:49:34 +00:00
|
|
|
gl_subsectorrendernode * node = SSR_List.GetNew();
|
|
|
|
node->sub = HandledSubsectors[j];
|
|
|
|
AddOtherFloorPlane(sec->sectornum, node);
|
|
|
|
}
|
|
|
|
|
2016-04-07 23:42:43 +00:00
|
|
|
if (HandledSubsectors.Size() != 1)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
// mark all subsectors in the missing list that got processed by this
|
2016-04-07 23:42:43 +00:00
|
|
|
for (unsigned int j = 0; j < HandledSubsectors.Size(); j++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-04-07 23:42:43 +00:00
|
|
|
for (unsigned int k = 0; k < MissingLowerTextures.Size(); k++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-04-07 23:42:43 +00:00
|
|
|
if (MissingLowerTextures[k].sub == HandledSubsectors[j])
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-04-07 23:42:43 +00:00
|
|
|
MissingLowerTextures[k].seg = NULL;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-07 23:42:43 +00:00
|
|
|
else MissingLowerTextures[i].seg = NULL;
|
2013-06-23 07:49:34 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!MissingLowerTextures[i].seg->PartnerSeg) continue;
|
|
|
|
subsector_t *backsub = MissingLowerTextures[i].seg->PartnerSeg->Subsector;
|
|
|
|
if (!backsub) continue;
|
|
|
|
validcount++;
|
|
|
|
HandledSubsectors.Clear();
|
|
|
|
|
|
|
|
{
|
|
|
|
// It isn't a hole. Now check whether it might be a fake bridge
|
2017-03-12 22:13:07 +00:00
|
|
|
sector_t * fakesector = gl_FakeFlat(MissingLowerTextures[i].seg->frontsector, &fake, mDrawer->in_area, false);
|
2016-04-24 11:35:43 +00:00
|
|
|
float planez = (float)fakesector->GetPlaneTexZ(sector_t::floor);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2016-04-07 23:42:43 +00:00
|
|
|
backsub->validcount = validcount;
|
2013-06-23 07:49:34 +00:00
|
|
|
if (DoFakeBridge(backsub, planez))
|
|
|
|
{
|
|
|
|
// The mere fact that this seg has been added to the list means that the back sector
|
|
|
|
// will be rendered so we can safely assume that it is already in the render list
|
|
|
|
|
2016-04-07 23:42:43 +00:00
|
|
|
for (unsigned int j = 0; j < HandledSubsectors.Size(); j++)
|
|
|
|
{
|
2013-06-23 07:49:34 +00:00
|
|
|
gl_subsectorrendernode * node = SSR_List.GetNew();
|
|
|
|
node->sub = HandledSubsectors[j];
|
|
|
|
AddOtherFloorPlane(fakesector->sectornum, node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
totalms.Unclock();
|
2016-04-07 23:42:43 +00:00
|
|
|
showtotalms = totalms;
|
2013-06-23 07:49:34 +00:00
|
|
|
totalms.Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void FDrawInfo::DrawUnhandledMissingTextures()
|
|
|
|
{
|
|
|
|
validcount++;
|
2016-04-07 23:42:43 +00:00
|
|
|
for (int i = MissingUpperSegs.Size() - 1; i >= 0; i--)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
int index = MissingUpperSegs[i].MTI_Index;
|
2016-04-07 23:42:43 +00:00
|
|
|
if (index >= 0 && MissingUpperTextures[index].seg == NULL) continue;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
seg_t * seg = MissingUpperSegs[i].seg;
|
|
|
|
|
|
|
|
// already done!
|
2016-04-07 23:42:43 +00:00
|
|
|
if (seg->linedef->validcount == validcount) continue; // already done
|
|
|
|
seg->linedef->validcount = validcount;
|
2017-03-11 22:28:07 +00:00
|
|
|
if (seg->frontsector->GetPlaneTexZ(sector_t::ceiling) < r_viewpoint.Pos.Z) continue; // out of sight
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
// FIXME: The check for degenerate subsectors should be more precise
|
|
|
|
if (seg->PartnerSeg && (seg->PartnerSeg->Subsector->flags & SSECF_DEGENERATE)) continue;
|
|
|
|
if (seg->backsector->transdoor) continue;
|
2016-04-07 23:42:43 +00:00
|
|
|
if (seg->backsector->GetTexture(sector_t::ceiling) == skyflatnum) continue;
|
2016-04-22 07:15:22 +00:00
|
|
|
if (seg->backsector->ValidatePortal(sector_t::ceiling) != NULL) continue;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
if (!glset.notexturefill) FloodUpperGap(seg);
|
|
|
|
}
|
|
|
|
|
|
|
|
validcount++;
|
2016-04-07 23:42:43 +00:00
|
|
|
for (int i = MissingLowerSegs.Size() - 1; i >= 0; i--)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
int index = MissingLowerSegs[i].MTI_Index;
|
2016-04-07 23:42:43 +00:00
|
|
|
if (index >= 0 && MissingLowerTextures[index].seg == NULL) continue;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
seg_t * seg = MissingLowerSegs[i].seg;
|
|
|
|
|
2016-04-07 23:42:43 +00:00
|
|
|
if (seg->linedef->validcount == validcount) continue; // already done
|
|
|
|
seg->linedef->validcount = validcount;
|
2013-06-23 07:49:34 +00:00
|
|
|
if (!(sectorrenderflags[seg->backsector->sectornum] & SSRF_RENDERFLOOR)) continue;
|
2017-03-11 22:28:07 +00:00
|
|
|
if (seg->frontsector->GetPlaneTexZ(sector_t::floor) > r_viewpoint.Pos.Z) continue; // out of sight
|
2013-06-23 07:49:34 +00:00
|
|
|
if (seg->backsector->transdoor) continue;
|
2016-04-07 23:42:43 +00:00
|
|
|
if (seg->backsector->GetTexture(sector_t::floor) == skyflatnum) continue;
|
2016-04-22 07:15:22 +00:00
|
|
|
if (seg->backsector->ValidatePortal(sector_t::floor) != NULL) continue;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
if (!glset.notexturefill) FloodLowerGap(seg);
|
|
|
|
}
|
|
|
|
MissingUpperTextures.Clear();
|
|
|
|
MissingLowerTextures.Clear();
|
|
|
|
MissingUpperSegs.Clear();
|
|
|
|
MissingLowerSegs.Clear();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppendMissingTextureStats(FString &out)
|
|
|
|
{
|
|
|
|
out.AppendFormat("Missing textures: %d upper, %d lower, %.3f ms\n",
|
|
|
|
totalupper, totallower, showtotalms.TimeMS());
|
|
|
|
}
|
|
|
|
|
|
|
|
ADD_STAT(missingtextures)
|
|
|
|
{
|
|
|
|
FString out;
|
|
|
|
AppendMissingTextureStats(out);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Multi-sector deep water hacks
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void FDrawInfo::AddHackedSubsector(subsector_t * sub)
|
|
|
|
{
|
|
|
|
if (!(level.maptype == MAPTYPE_HEXEN))
|
|
|
|
{
|
|
|
|
SubsectorHackInfo sh={sub, 0};
|
|
|
|
SubsectorHacks.Push (sh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Finds a subsector whose plane can be used for rendering
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
bool FDrawInfo::CheckAnchorFloor(subsector_t * sub)
|
|
|
|
{
|
|
|
|
// This subsector has a one sided wall and can be used.
|
|
|
|
if (sub->hacked==3) return true;
|
|
|
|
if (sub->flags & SSECF_DEGENERATE) return false;
|
|
|
|
|
2017-03-09 19:19:55 +00:00
|
|
|
for(uint32_t j=0;j<sub->numlines;j++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
seg_t * seg = sub->firstline + j;
|
|
|
|
if (!seg->PartnerSeg) return true;
|
|
|
|
|
|
|
|
subsector_t * backsub = seg->PartnerSeg->Subsector;
|
|
|
|
|
|
|
|
// Find a linedef with a different visplane on the other side.
|
|
|
|
if (!(backsub->flags & SSECF_DEGENERATE) && seg->linedef &&
|
|
|
|
(sub->render_sector != backsub->render_sector && sub->sector != backsub->sector))
|
|
|
|
{
|
|
|
|
// I'm ignoring slopes, scaling and rotation here. The likelihood of ZDoom maps
|
|
|
|
// using such crap hacks is simply too small
|
2016-04-24 11:35:43 +00:00
|
|
|
if (sub->render_sector->GetTexture(sector_t::floor) == backsub->render_sector->GetTexture(sector_t::floor) &&
|
|
|
|
sub->render_sector->GetPlaneTexZ(sector_t::floor) == backsub->render_sector->GetPlaneTexZ(sector_t::floor) &&
|
2013-06-23 07:49:34 +00:00
|
|
|
sub->render_sector->GetFloorLight() == backsub->render_sector->GetFloorLight())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// This means we found an adjoining subsector that clearly would go into another
|
|
|
|
// visplane. That means that this subsector can be used as an anchor.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Collect connected subsectors that have to be rendered with the same plane
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
static bool inview;
|
|
|
|
static subsector_t * viewsubsector;
|
|
|
|
static TArray<seg_t *> lowersegs;
|
|
|
|
|
|
|
|
bool FDrawInfo::CollectSubsectorsFloor(subsector_t * sub, sector_t * anchor)
|
|
|
|
{
|
|
|
|
|
|
|
|
// mark it checked
|
|
|
|
sub->validcount=validcount;
|
|
|
|
|
|
|
|
|
|
|
|
// We must collect any subsector that either is connected to this one with a miniseg
|
|
|
|
// or has the same visplane.
|
|
|
|
// We must not collect any subsector that has the anchor's visplane!
|
2016-04-02 21:17:16 +00:00
|
|
|
if (!(sub->flags & SSECF_DEGENERATE))
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
// Is not being rendered so don't bother.
|
2017-03-16 23:22:52 +00:00
|
|
|
if (!(ss_renderflags[sub->Index()] & SSRF_PROCESSED)) return true;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
if (sub->render_sector->GetTexture(sector_t::floor) != anchor->GetTexture(sector_t::floor) ||
|
2016-04-24 11:35:43 +00:00
|
|
|
sub->render_sector->GetPlaneTexZ(sector_t::floor) != anchor->GetPlaneTexZ(sector_t::floor) ||
|
2016-04-02 21:17:16 +00:00
|
|
|
sub->render_sector->GetFloorLight() != anchor->GetFloorLight())
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-03-11 22:28:07 +00:00
|
|
|
if (sub == viewsubsector && r_viewpoint.Pos.Z < anchor->GetPlaneTexZ(sector_t::floor)) inview = true;
|
2016-04-02 21:17:16 +00:00
|
|
|
HandledSubsectors.Push(sub);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We can assume that all segs in this subsector are connected to a subsector that has
|
|
|
|
// to be checked as well
|
2017-03-09 19:19:55 +00:00
|
|
|
for(uint32_t j=0;j<sub->numlines;j++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
seg_t * seg = sub->firstline + j;
|
|
|
|
if (seg->PartnerSeg)
|
|
|
|
{
|
|
|
|
subsector_t * backsub = seg->PartnerSeg->Subsector;
|
|
|
|
|
|
|
|
// could be an anchor itself.
|
|
|
|
if (!CheckAnchorFloor (backsub)) // must not be an anchor itself!
|
|
|
|
{
|
|
|
|
if (backsub->validcount!=validcount)
|
|
|
|
{
|
|
|
|
if (!CollectSubsectorsFloor (backsub, anchor)) return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (sub->render_sector == backsub->render_sector)
|
|
|
|
{
|
|
|
|
// Any anchor not within the original anchor's visplane terminates the processing.
|
2016-04-24 11:35:43 +00:00
|
|
|
if (sub->render_sector->GetTexture(sector_t::floor) != anchor->GetTexture(sector_t::floor) ||
|
|
|
|
sub->render_sector->GetPlaneTexZ(sector_t::floor) != anchor->GetPlaneTexZ(sector_t::floor) ||
|
|
|
|
sub->render_sector->GetFloorLight() != anchor->GetFloorLight())
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!seg->linedef || (seg->frontsector==seg->backsector && sub->render_sector!=backsub->render_sector))
|
|
|
|
lowersegs.Push(seg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Finds a subsector whose plane can be used for rendering
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
bool FDrawInfo::CheckAnchorCeiling(subsector_t * sub)
|
|
|
|
{
|
|
|
|
// This subsector has a one sided wall and can be used.
|
|
|
|
if (sub->hacked==3) return true;
|
|
|
|
if (sub->flags & SSECF_DEGENERATE) return false;
|
|
|
|
|
2017-03-09 19:19:55 +00:00
|
|
|
for(uint32_t j=0;j<sub->numlines;j++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
seg_t * seg = sub->firstline + j;
|
|
|
|
if (!seg->PartnerSeg) return true;
|
|
|
|
|
|
|
|
subsector_t * backsub = seg->PartnerSeg->Subsector;
|
|
|
|
|
|
|
|
// Find a linedef with a different visplane on the other side.
|
|
|
|
if (!(backsub->flags & SSECF_DEGENERATE) && seg->linedef &&
|
|
|
|
(sub->render_sector != backsub->render_sector && sub->sector != backsub->sector))
|
|
|
|
{
|
|
|
|
// I'm ignoring slopes, scaling and rotation here. The likelihood of ZDoom maps
|
|
|
|
// using such crap hacks is simply too small
|
2016-04-24 11:35:43 +00:00
|
|
|
if (sub->render_sector->GetTexture(sector_t::ceiling) == backsub->render_sector->GetTexture(sector_t::ceiling) &&
|
|
|
|
sub->render_sector->GetPlaneTexZ(sector_t::ceiling) == backsub->render_sector->GetPlaneTexZ(sector_t::ceiling) &&
|
2013-06-23 07:49:34 +00:00
|
|
|
sub->render_sector->GetCeilingLight() == backsub->render_sector->GetCeilingLight())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// This means we found an adjoining subsector that clearly would go into another
|
|
|
|
// visplane. That means that this subsector can be used as an anchor.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Collect connected subsectors that have to be rendered with the same plane
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
bool FDrawInfo::CollectSubsectorsCeiling(subsector_t * sub, sector_t * anchor)
|
|
|
|
{
|
|
|
|
// mark it checked
|
|
|
|
sub->validcount=validcount;
|
|
|
|
|
|
|
|
|
|
|
|
// We must collect any subsector that either is connected to this one with a miniseg
|
|
|
|
// or has the same visplane.
|
|
|
|
// We must not collect any subsector that has the anchor's visplane!
|
|
|
|
if (!(sub->flags & SSECF_DEGENERATE))
|
|
|
|
{
|
|
|
|
// Is not being rendererd so don't bother.
|
2017-03-16 23:22:52 +00:00
|
|
|
if (!(ss_renderflags[sub->Index()]&SSRF_PROCESSED)) return true;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2016-04-24 11:35:43 +00:00
|
|
|
if (sub->render_sector->GetTexture(sector_t::ceiling) != anchor->GetTexture(sector_t::ceiling) ||
|
|
|
|
sub->render_sector->GetPlaneTexZ(sector_t::ceiling) != anchor->GetPlaneTexZ(sector_t::ceiling) ||
|
|
|
|
sub->render_sector->GetCeilingLight() != anchor->GetCeilingLight())
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-04-24 11:35:43 +00:00
|
|
|
HandledSubsectors.Push(sub);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We can assume that all segs in this subsector are connected to a subsector that has
|
|
|
|
// to be checked as well
|
2017-03-09 19:19:55 +00:00
|
|
|
for(uint32_t j=0;j<sub->numlines;j++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
seg_t * seg = sub->firstline + j;
|
|
|
|
if (seg->PartnerSeg)
|
|
|
|
{
|
|
|
|
subsector_t * backsub = seg->PartnerSeg->Subsector;
|
|
|
|
|
|
|
|
// could be an anchor itself.
|
|
|
|
if (!CheckAnchorCeiling (backsub)) // must not be an anchor itself!
|
|
|
|
{
|
|
|
|
if (backsub->validcount!=validcount)
|
|
|
|
{
|
|
|
|
if (!CollectSubsectorsCeiling (backsub, anchor)) return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (sub->render_sector == backsub->render_sector)
|
|
|
|
{
|
|
|
|
// Any anchor not within the original anchor's visplane terminates the processing.
|
2016-04-24 11:35:43 +00:00
|
|
|
if (sub->render_sector->GetTexture(sector_t::ceiling) != anchor->GetTexture(sector_t::ceiling) ||
|
|
|
|
sub->render_sector->GetPlaneTexZ(sector_t::ceiling) != anchor->GetPlaneTexZ(sector_t::ceiling) ||
|
|
|
|
sub->render_sector->GetCeilingLight() != anchor->GetCeilingLight())
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Process the subsectors that have been marked as hacked
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void FDrawInfo::HandleHackedSubsectors()
|
|
|
|
{
|
|
|
|
lowershcount=uppershcount=0;
|
|
|
|
totalssms.Reset();
|
|
|
|
totalssms.Clock();
|
|
|
|
|
2017-03-11 22:28:07 +00:00
|
|
|
viewsubsector = R_PointInSubsector(r_viewpoint.Pos);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
// Each subsector may only be processed once in this loop!
|
|
|
|
validcount++;
|
|
|
|
for(unsigned int i=0;i<SubsectorHacks.Size();i++)
|
|
|
|
{
|
|
|
|
subsector_t * sub = SubsectorHacks[i].sub;
|
|
|
|
if (sub->validcount!=validcount && CheckAnchorFloor(sub))
|
|
|
|
{
|
|
|
|
// Now collect everything that is connected with this subsector.
|
|
|
|
HandledSubsectors.Clear();
|
|
|
|
inview=false;
|
|
|
|
lowersegs.Clear();
|
|
|
|
if (CollectSubsectorsFloor(sub, sub->render_sector))
|
|
|
|
{
|
|
|
|
for(unsigned int j=0;j<HandledSubsectors.Size();j++)
|
|
|
|
{
|
|
|
|
gl_subsectorrendernode * node = SSR_List.GetNew();
|
|
|
|
|
|
|
|
node->sub = HandledSubsectors[j];
|
|
|
|
AddOtherFloorPlane(sub->render_sector->sectornum, node);
|
|
|
|
}
|
|
|
|
if (inview) for(unsigned int j=0;j<lowersegs.Size();j++)
|
|
|
|
{
|
|
|
|
seg_t * seg=lowersegs[j];
|
2017-03-12 20:57:39 +00:00
|
|
|
GLWall wall(mDrawer);
|
|
|
|
wall.ProcessLowerMiniseg(seg, seg->Subsector->render_sector, seg->PartnerSeg->Subsector->render_sector);
|
|
|
|
rendered_lines++;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
lowershcount+=HandledSubsectors.Size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Each subsector may only be processed once in this loop!
|
|
|
|
validcount++;
|
|
|
|
for(unsigned int i=0;i<SubsectorHacks.Size();i++)
|
|
|
|
{
|
|
|
|
subsector_t * sub = SubsectorHacks[i].sub;
|
|
|
|
if (sub->validcount!=validcount && CheckAnchorCeiling(sub))
|
|
|
|
{
|
|
|
|
// Now collect everything that is connected with this subsector.
|
|
|
|
HandledSubsectors.Clear();
|
|
|
|
if (CollectSubsectorsCeiling(sub, sub->render_sector))
|
|
|
|
{
|
|
|
|
for(unsigned int j=0;j<HandledSubsectors.Size();j++)
|
|
|
|
{
|
|
|
|
gl_subsectorrendernode * node = SSR_List.GetNew();
|
|
|
|
|
|
|
|
node->sub = HandledSubsectors[j];
|
|
|
|
AddOtherCeilingPlane(sub->render_sector->sectornum, node);
|
|
|
|
}
|
|
|
|
uppershcount+=HandledSubsectors.Size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SubsectorHacks.Clear();
|
|
|
|
totalssms.Unclock();
|
|
|
|
}
|
|
|
|
|
|
|
|
ADD_STAT(sectorhacks)
|
|
|
|
{
|
|
|
|
FString out;
|
|
|
|
out.Format("sectorhacks = %.3f ms, %d upper, %d lower\n", totalssms.TimeMS(), uppershcount, lowershcount);
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// This merges visplanes that lie inside a sector stack together
|
|
|
|
// to avoid rendering these unneeded flats
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void FDrawInfo::AddFloorStack(sector_t * sec)
|
|
|
|
{
|
|
|
|
FloorStacks.Push(sec);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FDrawInfo::AddCeilingStack(sector_t * sec)
|
|
|
|
{
|
|
|
|
CeilingStacks.Push(sec);
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void FDrawInfo::CollectSectorStacksCeiling(subsector_t * sub, sector_t * anchor)
|
|
|
|
{
|
|
|
|
// mark it checked
|
|
|
|
sub->validcount=validcount;
|
|
|
|
|
|
|
|
// Has a sector stack or skybox itself!
|
2016-04-20 09:39:41 +00:00
|
|
|
if (sub->render_sector->GetGLPortal(sector_t::ceiling) != nullptr) return;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
// Don't bother processing unrendered subsectors
|
2017-03-16 23:22:52 +00:00
|
|
|
if (sub->numlines>2 && !(ss_renderflags[sub->Index()]&SSRF_PROCESSED)) return;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
// Must be the exact same visplane
|
2017-03-12 22:13:07 +00:00
|
|
|
sector_t * me = gl_FakeFlat(sub->render_sector, &fakesec, mDrawer->in_area, false);
|
2013-06-23 07:49:34 +00:00
|
|
|
if (me->GetTexture(sector_t::ceiling) != anchor->GetTexture(sector_t::ceiling) ||
|
|
|
|
me->ceilingplane != anchor->ceilingplane ||
|
|
|
|
me->GetCeilingLight() != anchor->GetCeilingLight() ||
|
2017-03-15 15:47:42 +00:00
|
|
|
me->Colormap != anchor->Colormap ||
|
|
|
|
me->SpecialColors[sector_t::ceiling] != anchor->SpecialColors[sector_t::ceiling] ||
|
2016-04-23 11:35:51 +00:00
|
|
|
me->planes[sector_t::ceiling].xform != anchor->planes[sector_t::ceiling].xform)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
// different visplane so it can't belong to this stack
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
HandledSubsectors.Push (sub);
|
|
|
|
|
2017-03-09 19:19:55 +00:00
|
|
|
for(uint32_t j=0;j<sub->numlines;j++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
seg_t * seg = sub->firstline + j;
|
|
|
|
if (seg->PartnerSeg)
|
|
|
|
{
|
|
|
|
subsector_t * backsub = seg->PartnerSeg->Subsector;
|
|
|
|
|
|
|
|
if (backsub->validcount!=validcount) CollectSectorStacksCeiling (backsub, anchor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void FDrawInfo::CollectSectorStacksFloor(subsector_t * sub, sector_t * anchor)
|
|
|
|
{
|
|
|
|
// mark it checked
|
|
|
|
sub->validcount=validcount;
|
|
|
|
|
|
|
|
// Has a sector stack or skybox itself!
|
2016-04-20 09:39:41 +00:00
|
|
|
if (sub->render_sector->GetGLPortal(sector_t::floor) != nullptr) return;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
// Don't bother processing unrendered subsectors
|
2017-03-16 23:22:52 +00:00
|
|
|
if (sub->numlines>2 && !(ss_renderflags[sub->Index()]&SSRF_PROCESSED)) return;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
// Must be the exact same visplane
|
2017-03-12 22:13:07 +00:00
|
|
|
sector_t * me = gl_FakeFlat(sub->render_sector, &fakesec, mDrawer->in_area, false);
|
2013-06-23 07:49:34 +00:00
|
|
|
if (me->GetTexture(sector_t::floor) != anchor->GetTexture(sector_t::floor) ||
|
|
|
|
me->floorplane != anchor->floorplane ||
|
|
|
|
me->GetFloorLight() != anchor->GetFloorLight() ||
|
2017-03-15 15:47:42 +00:00
|
|
|
me->Colormap != anchor->Colormap ||
|
|
|
|
me->SpecialColors[sector_t::floor] != anchor->SpecialColors[sector_t::floor] ||
|
2016-04-23 11:35:51 +00:00
|
|
|
me->planes[sector_t::floor].xform != anchor->planes[sector_t::floor].xform)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
// different visplane so it can't belong to this stack
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
HandledSubsectors.Push (sub);
|
|
|
|
|
2017-03-09 19:19:55 +00:00
|
|
|
for(uint32_t j=0;j<sub->numlines;j++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
seg_t * seg = sub->firstline + j;
|
|
|
|
if (seg->PartnerSeg)
|
|
|
|
{
|
|
|
|
subsector_t * backsub = seg->PartnerSeg->Subsector;
|
|
|
|
|
|
|
|
if (backsub->validcount!=validcount) CollectSectorStacksFloor (backsub, anchor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void FDrawInfo::ProcessSectorStacks()
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
sector_t fake;
|
|
|
|
|
|
|
|
validcount++;
|
|
|
|
for (i=0;i<CeilingStacks.Size (); i++)
|
|
|
|
{
|
2017-03-12 22:13:07 +00:00
|
|
|
sector_t *sec = gl_FakeFlat(CeilingStacks[i], &fake, mDrawer->in_area, false);
|
2016-04-20 09:39:41 +00:00
|
|
|
FPortal *portal = sec->GetGLPortal(sector_t::ceiling);
|
2013-06-23 07:49:34 +00:00
|
|
|
if (portal != NULL) for(int k=0;k<sec->subsectorcount;k++)
|
|
|
|
{
|
|
|
|
subsector_t * sub = sec->subsectors[k];
|
2017-03-16 23:22:52 +00:00
|
|
|
if (ss_renderflags[sub->Index()] & SSRF_PROCESSED)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
HandledSubsectors.Clear();
|
2017-03-09 19:19:55 +00:00
|
|
|
for(uint32_t j=0;j<sub->numlines;j++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
seg_t * seg = sub->firstline + j;
|
|
|
|
if (seg->PartnerSeg)
|
|
|
|
{
|
|
|
|
subsector_t * backsub = seg->PartnerSeg->Subsector;
|
|
|
|
|
|
|
|
if (backsub->validcount!=validcount) CollectSectorStacksCeiling (backsub, sec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(unsigned int j=0;j<HandledSubsectors.Size();j++)
|
|
|
|
{
|
|
|
|
subsector_t *sub = HandledSubsectors[j];
|
2017-03-16 23:22:52 +00:00
|
|
|
ss_renderflags[sub->Index()] &= ~SSRF_RENDERCEILING;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
if (sub->portalcoverage[sector_t::ceiling].subsectors == NULL)
|
|
|
|
{
|
2016-04-20 09:39:41 +00:00
|
|
|
gl_BuildPortalCoverage(&sub->portalcoverage[sector_t::ceiling], sub, portal->mDisplacement);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
2016-04-20 09:39:41 +00:00
|
|
|
portal->GetRenderState()->AddSubsector(sub);
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
if (sec->GetAlpha(sector_t::ceiling) != 0 && sec->GetTexture(sector_t::ceiling) != skyflatnum)
|
|
|
|
{
|
|
|
|
gl_subsectorrendernode * node = SSR_List.GetNew();
|
|
|
|
node->sub = sub;
|
|
|
|
AddOtherCeilingPlane(sec->sectornum, node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
validcount++;
|
|
|
|
for (i=0;i<FloorStacks.Size (); i++)
|
|
|
|
{
|
2017-03-12 22:13:07 +00:00
|
|
|
sector_t *sec = gl_FakeFlat(FloorStacks[i], &fake, mDrawer->in_area, false);
|
2016-04-20 09:39:41 +00:00
|
|
|
FPortal *portal = sec->GetGLPortal(sector_t::floor);
|
2013-06-23 07:49:34 +00:00
|
|
|
if (portal != NULL) for(int k=0;k<sec->subsectorcount;k++)
|
|
|
|
{
|
|
|
|
subsector_t * sub = sec->subsectors[k];
|
2017-03-16 23:22:52 +00:00
|
|
|
if (ss_renderflags[sub->Index()] & SSRF_PROCESSED)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
HandledSubsectors.Clear();
|
2017-03-09 19:19:55 +00:00
|
|
|
for(uint32_t j=0;j<sub->numlines;j++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
seg_t * seg = sub->firstline + j;
|
|
|
|
if (seg->PartnerSeg)
|
|
|
|
{
|
|
|
|
subsector_t * backsub = seg->PartnerSeg->Subsector;
|
|
|
|
|
|
|
|
if (backsub->validcount!=validcount) CollectSectorStacksFloor (backsub, sec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(unsigned int j=0;j<HandledSubsectors.Size();j++)
|
|
|
|
{
|
|
|
|
subsector_t *sub = HandledSubsectors[j];
|
2017-03-16 23:22:52 +00:00
|
|
|
ss_renderflags[sub->Index()] &= ~SSRF_RENDERFLOOR;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
if (sub->portalcoverage[sector_t::floor].subsectors == NULL)
|
|
|
|
{
|
2016-04-20 09:39:41 +00:00
|
|
|
gl_BuildPortalCoverage(&sub->portalcoverage[sector_t::floor], sub, portal->mDisplacement);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
2016-04-20 09:39:41 +00:00
|
|
|
GLSectorStackPortal *glportal = portal->GetRenderState();
|
2013-06-23 07:49:34 +00:00
|
|
|
glportal->AddSubsector(sub);
|
|
|
|
|
|
|
|
if (sec->GetAlpha(sector_t::floor) != 0 && sec->GetTexture(sector_t::floor) != skyflatnum)
|
|
|
|
{
|
|
|
|
gl_subsectorrendernode * node = SSR_List.GetNew();
|
|
|
|
node->sub = sub;
|
|
|
|
AddOtherFloorPlane(sec->sectornum, node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FloorStacks.Clear();
|
|
|
|
CeilingStacks.Clear();
|
|
|
|
}
|
|
|
|
|