2013-06-23 07:49:34 +00:00
|
|
|
/*
|
|
|
|
** gl_missingtexture.cpp
|
|
|
|
** Handles missing upper and lower textures and self referencing sector hacks
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 2000-2005 Christoph Oelckers
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
** 4. When not used as part of GZDoom or a GZDoom derivative, this code will be
|
|
|
|
** covered by the terms of the GNU Lesser General Public License as published
|
|
|
|
** by the Free Software Foundation; either version 2.1 of the License, or (at
|
|
|
|
** your option) any later version.
|
|
|
|
** 5. Full disclosure of the entire project's source code, except for third
|
|
|
|
** party libraries is mandatory. (NOTE: This clause is non-negotiable!)
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "a_sharedglobal.h"
|
|
|
|
#include "r_utility.h"
|
|
|
|
#include "r_defs.h"
|
|
|
|
#include "r_sky.h"
|
|
|
|
#include "g_level.h"
|
|
|
|
|
|
|
|
|
|
|
|
#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"
|
|
|
|
#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
|
2016-04-07 23:42:43 +00:00
|
|
|
for (DWORD 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;
|
|
|
|
}
|
|
|
|
|
2016-04-07 23:42:43 +00:00
|
|
|
for (DWORD 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!
|
|
|
|
|
|
|
|
sector_t * sec = gl_FakeFlat(seg->backsector, &fakesec, true);
|
|
|
|
|
|
|
|
// 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-07 23:42:43 +00:00
|
|
|
if (sec->GetPlaneTexZF(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-07 23:42:43 +00:00
|
|
|
if (sec->GetPlaneTexZF(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)];
|
2016-04-07 23:42:43 +00:00
|
|
|
if (!tex || tex->UseType == FTexture::TEX_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
|
2016-04-07 23:42:43 +00:00
|
|
|
for (DWORD 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;
|
|
|
|
}
|
|
|
|
|
2016-04-07 23:42:43 +00:00
|
|
|
for (DWORD 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!
|
|
|
|
|
|
|
|
sector_t * sec = gl_FakeFlat(seg->backsector, &fakesec, true);
|
|
|
|
|
|
|
|
// 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-07 23:42:43 +00:00
|
|
|
if (sec->GetPlaneTexZF(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-07 23:42:43 +00:00
|
|
|
if (sec->GetPlaneTexZF(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)];
|
2016-04-07 23:42:43 +00:00
|
|
|
if (!tex || tex->UseType == FTexture::TEX_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
|
2016-04-07 23:42:43 +00:00
|
|
|
for (DWORD 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;
|
|
|
|
}
|
|
|
|
|
2016-04-07 23:42:43 +00:00
|
|
|
for (DWORD 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!
|
|
|
|
|
|
|
|
sector_t * sec = gl_FakeFlat(seg->backsector, &fakesec, true);
|
|
|
|
|
|
|
|
// 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-07 23:42:43 +00:00
|
|
|
if (sec->GetPlaneTexZF(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-07 23:42:43 +00:00
|
|
|
if (sec->GetPlaneTexZF(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
|
2016-04-07 23:42:43 +00:00
|
|
|
for (DWORD 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;
|
|
|
|
}
|
|
|
|
|
2016-04-07 23:42:43 +00:00
|
|
|
for (DWORD 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!
|
|
|
|
|
|
|
|
sector_t * sec = gl_FakeFlat(seg->backsector, &fakesec, true);
|
|
|
|
|
|
|
|
// 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-07 23:42:43 +00:00
|
|
|
if (sec->GetPlaneTexZF(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-07 23:42:43 +00:00
|
|
|
if (sec->GetPlaneTexZF(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++;
|
|
|
|
|
2016-04-07 23:42:43 +00:00
|
|
|
if (MissingUpperTextures[i].Planez > ViewPos.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
|
|
|
|
sector_t * fakesector = gl_FakeFlat(MissingUpperTextures[i].seg->frontsector, &fake, false);
|
2016-04-07 23:42:43 +00:00
|
|
|
float planez = (float)fakesector->GetPlaneTexZF(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++;
|
|
|
|
|
2016-04-07 23:42:43 +00:00
|
|
|
if (MissingLowerTextures[i].Planez < ViewPos.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
|
|
|
|
sector_t * fakesector = gl_FakeFlat(MissingLowerTextures[i].seg->frontsector, &fake, false);
|
2016-04-07 23:42:43 +00:00
|
|
|
float planez = (float)fakesector->GetPlaneTexZF(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;
|
2016-04-02 21:17:16 +00:00
|
|
|
if (seg->frontsector->GetPlaneTexZF(sector_t::ceiling) < ViewPos.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;
|
2013-06-23 07:49:34 +00:00
|
|
|
if (seg->backsector->portals[sector_t::ceiling] != NULL) continue;
|
|
|
|
|
|
|
|
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;
|
2016-04-02 21:17:16 +00:00
|
|
|
if (seg->frontsector->GetPlaneTexZF(sector_t::floor) > ViewPos.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;
|
2013-06-23 07:49:34 +00:00
|
|
|
if (seg->backsector->portals[sector_t::floor] != NULL) continue;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
for(DWORD j=0;j<sub->numlines;j++)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
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) &&
|
|
|
|
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.
|
2016-04-02 21:17:16 +00:00
|
|
|
if (!(ss_renderflags[DWORD(sub - subsectors)] & 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-02 21:17:16 +00:00
|
|
|
sub->render_sector->GetPlaneTexZF(sector_t::floor) != anchor->GetPlaneTexZF(sector_t::floor) ||
|
|
|
|
sub->render_sector->GetFloorLight() != anchor->GetFloorLight())
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-04-02 21:17:16 +00:00
|
|
|
if (sub == viewsubsector && ViewPos.Z < anchor->GetPlaneTexZF(sector_t::floor)) inview = true;
|
|
|
|
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
|
|
|
|
for(DWORD j=0;j<sub->numlines;j++)
|
|
|
|
{
|
|
|
|
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.
|
|
|
|
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())
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
for(DWORD j=0;j<sub->numlines;j++)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
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) &&
|
|
|
|
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.
|
|
|
|
if (!(ss_renderflags[DWORD(sub-subsectors)]&SSRF_PROCESSED)) return true;
|
|
|
|
|
|
|
|
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())
|
|
|
|
{
|
|
|
|
HandledSubsectors.Push (sub);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We can assume that all segs in this subsector are connected to a subsector that has
|
|
|
|
// to be checked as well
|
|
|
|
for(DWORD j=0;j<sub->numlines;j++)
|
|
|
|
{
|
|
|
|
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.
|
|
|
|
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())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Process the subsectors that have been marked as hacked
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void FDrawInfo::HandleHackedSubsectors()
|
|
|
|
{
|
|
|
|
lowershcount=uppershcount=0;
|
|
|
|
totalssms.Reset();
|
|
|
|
totalssms.Clock();
|
|
|
|
|
2016-04-02 21:17:16 +00:00
|
|
|
viewsubsector = R_PointInSubsector(ViewPos);
|
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];
|
|
|
|
GLRenderer->ProcessLowerMiniseg (seg, seg->Subsector->render_sector, seg->PartnerSeg->Subsector->render_sector);
|
|
|
|
}
|
|
|
|
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
|
|
|
|
if (sub->numlines>2 && !(ss_renderflags[DWORD(sub-subsectors)]&SSRF_PROCESSED)) return;
|
|
|
|
|
|
|
|
// Must be the exact same visplane
|
2015-05-29 10:03:50 +00:00
|
|
|
sector_t * me = gl_FakeFlat(sub->render_sector, &fakesec, 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() ||
|
|
|
|
me->ColorMap != anchor->ColorMap ||
|
|
|
|
me->GetXOffset(sector_t::ceiling) != anchor->GetXOffset(sector_t::ceiling) ||
|
|
|
|
me->GetYOffset(sector_t::ceiling) != anchor->GetYOffset(sector_t::ceiling) ||
|
|
|
|
me->GetXScale(sector_t::ceiling) != anchor->GetXScale(sector_t::ceiling) ||
|
|
|
|
me->GetYScale(sector_t::ceiling) != anchor->GetYScale(sector_t::ceiling) ||
|
|
|
|
me->GetAngle(sector_t::ceiling) != anchor->GetAngle(sector_t::ceiling))
|
|
|
|
{
|
|
|
|
// different visplane so it can't belong to this stack
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
HandledSubsectors.Push (sub);
|
|
|
|
|
|
|
|
for(DWORD j=0;j<sub->numlines;j++)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
if (sub->numlines>2 && !(ss_renderflags[DWORD(sub-subsectors)]&SSRF_PROCESSED)) return;
|
|
|
|
|
|
|
|
// Must be the exact same visplane
|
2015-05-29 10:03:50 +00:00
|
|
|
sector_t * me = gl_FakeFlat(sub->render_sector, &fakesec, 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() ||
|
|
|
|
me->ColorMap != anchor->ColorMap ||
|
|
|
|
me->GetXOffset(sector_t::floor) != anchor->GetXOffset(sector_t::floor) ||
|
|
|
|
me->GetYOffset(sector_t::floor) != anchor->GetYOffset(sector_t::floor) ||
|
|
|
|
me->GetXScale(sector_t::floor) != anchor->GetXScale(sector_t::floor) ||
|
|
|
|
me->GetYScale(sector_t::floor) != anchor->GetYScale(sector_t::floor) ||
|
|
|
|
me->GetAngle(sector_t::floor) != anchor->GetAngle(sector_t::floor))
|
|
|
|
{
|
|
|
|
// different visplane so it can't belong to this stack
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
HandledSubsectors.Push (sub);
|
|
|
|
|
|
|
|
for(DWORD j=0;j<sub->numlines;j++)
|
|
|
|
{
|
|
|
|
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++)
|
|
|
|
{
|
|
|
|
sector_t *sec = gl_FakeFlat(CeilingStacks[i], &fake, 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];
|
|
|
|
if (ss_renderflags[sub-subsectors] & SSRF_PROCESSED)
|
|
|
|
{
|
|
|
|
HandledSubsectors.Clear();
|
|
|
|
for(DWORD j=0;j<sub->numlines;j++)
|
|
|
|
{
|
|
|
|
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];
|
|
|
|
ss_renderflags[DWORD(sub-subsectors)] &= ~SSRF_RENDERCEILING;
|
|
|
|
|
|
|
|
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++)
|
|
|
|
{
|
|
|
|
sector_t *sec = gl_FakeFlat(FloorStacks[i], &fake, 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];
|
|
|
|
if (ss_renderflags[sub-subsectors] & SSRF_PROCESSED)
|
|
|
|
{
|
|
|
|
HandledSubsectors.Clear();
|
|
|
|
for(DWORD j=0;j<sub->numlines;j++)
|
|
|
|
{
|
|
|
|
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];
|
|
|
|
ss_renderflags[DWORD(sub-subsectors)] &= ~SSRF_RENDERFLOOR;
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|