2016-09-14 18:01:13 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Copyright(C) 2005-2016 Christoph Oelckers
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with this program. If not, see http://www.gnu.org/licenses/
|
|
|
|
//
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
//
|
2013-06-23 07:49:34 +00:00
|
|
|
/*
|
|
|
|
** gl_setup.cpp
|
|
|
|
** Initializes the data structures required by the GL renderer to handle
|
|
|
|
** a level
|
|
|
|
**
|
2016-09-14 18:01:13 +00:00
|
|
|
**/
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
#include "gl/system/gl_system.h"
|
|
|
|
#include "doomtype.h"
|
|
|
|
#include "colormatcher.h"
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "p_local.h"
|
2016-02-16 21:01:04 +00:00
|
|
|
#include "p_spec.h"
|
2013-06-23 07:49:34 +00:00
|
|
|
#include "p_lnspec.h"
|
|
|
|
#include "c_dispatch.h"
|
|
|
|
#include "r_sky.h"
|
|
|
|
#include "sc_man.h"
|
|
|
|
#include "w_wad.h"
|
|
|
|
#include "gi.h"
|
|
|
|
#include "p_setup.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/data/gl_vertexbuffer.h"
|
|
|
|
#include "gl/dynlights/gl_dynlight.h"
|
|
|
|
#include "gl/dynlights/gl_glow.h"
|
|
|
|
#include "gl/utility/gl_clock.h"
|
|
|
|
#include "gl/gl_functions.h"
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2016-07-27 14:27:40 +00:00
|
|
|
static TArray<subsector_t *> MapSectionCollector;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
static void DoSetMapSection(subsector_t *sub, int num)
|
|
|
|
{
|
2016-07-27 14:27:40 +00:00
|
|
|
MapSectionCollector.Resize(1);
|
|
|
|
MapSectionCollector[0] = sub;
|
2013-06-23 07:49:34 +00:00
|
|
|
sub->mapsection = num;
|
2016-07-27 14:27:40 +00:00
|
|
|
for (unsigned a = 0; a < MapSectionCollector.Size(); a++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-07-27 14:27:40 +00:00
|
|
|
sub = MapSectionCollector[a];
|
2017-03-09 19:19:55 +00:00
|
|
|
for (uint32_t i = 0; i < sub->numlines; i++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-07-27 14:27:40 +00:00
|
|
|
seg_t * seg = sub->firstline + i;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2016-07-27 14:27:40 +00:00
|
|
|
if (seg->PartnerSeg)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-07-27 14:27:40 +00:00
|
|
|
subsector_t * sub2 = seg->PartnerSeg->Subsector;
|
|
|
|
|
|
|
|
if (sub2->mapsection != num)
|
|
|
|
{
|
|
|
|
assert(sub2->mapsection == 0);
|
|
|
|
sub2->mapsection = num;
|
|
|
|
MapSectionCollector.Push(sub2);
|
|
|
|
}
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-27 14:27:40 +00:00
|
|
|
MapSectionCollector.Clear();
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Merge sections. This is needed in case the map contains errors
|
|
|
|
// like overlapping lines resulting in abnormal subsectors.
|
|
|
|
//
|
|
|
|
// This function ensures that any vertex position can only be in one section.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
struct cvertex_t
|
|
|
|
{
|
2016-04-08 10:38:09 +00:00
|
|
|
double X, Y;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2016-04-08 10:38:09 +00:00
|
|
|
operator int() const { return xs_FloorToInt(X) + 65536 * xs_FloorToInt(Y); }
|
|
|
|
bool operator!= (const cvertex_t &other) const { return fabs(X - other.X) >= EQUAL_EPSILON || fabs(Y - other.Y) >= EQUAL_EPSILON; }
|
|
|
|
cvertex_t& operator =(const vertex_t *v) { X = v->fX(); Y = v->fY(); return *this; }
|
2013-06-23 07:49:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef TMap<cvertex_t, int> FSectionVertexMap;
|
|
|
|
|
|
|
|
static int MergeMapSections(int num)
|
|
|
|
{
|
|
|
|
FSectionVertexMap vmap;
|
|
|
|
FSectionVertexMap::Pair *pair;
|
|
|
|
TArray<int> sectmap;
|
|
|
|
TArray<bool> sectvalid;
|
|
|
|
sectmap.Resize(num);
|
|
|
|
sectvalid.Resize(num);
|
2017-03-16 20:33:13 +00:00
|
|
|
for (int i = 0; i < num; i++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
sectmap[i] = -1;
|
|
|
|
sectvalid[i] = true;
|
|
|
|
}
|
|
|
|
int mergecount = 1;
|
|
|
|
|
|
|
|
|
|
|
|
cvertex_t vt;
|
|
|
|
|
|
|
|
// first step: Set mapsection for all vertex positions.
|
2017-03-16 20:33:13 +00:00
|
|
|
for (auto &seg : level.segs)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-03-16 20:33:13 +00:00
|
|
|
int section = seg.Subsector->mapsection;
|
|
|
|
for (int j = 0; j < 2; j++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-03-16 20:33:13 +00:00
|
|
|
vt = j == 0 ? seg.v1 : seg.v2;
|
2013-06-23 07:49:34 +00:00
|
|
|
vmap[vt] = section;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// second step: Check if any seg references more than one mapsection, either by subsector or by vertex
|
2017-03-16 20:33:13 +00:00
|
|
|
for (auto &seg : level.segs)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-03-16 20:33:13 +00:00
|
|
|
int section = seg.Subsector->mapsection;
|
|
|
|
for (int j = 0; j < 2; j++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-03-16 20:33:13 +00:00
|
|
|
vt = j == 0 ? seg.v1 : seg.v2;
|
2013-06-23 07:49:34 +00:00
|
|
|
int vsection = vmap[vt];
|
|
|
|
|
|
|
|
if (vsection != section)
|
|
|
|
{
|
|
|
|
// These 2 sections should be merged
|
2017-03-16 23:22:52 +00:00
|
|
|
for (auto &sub : level.subsectors)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-03-16 23:22:52 +00:00
|
|
|
if (sub.mapsection == vsection) sub.mapsection = section;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
FSectionVertexMap::Iterator it(vmap);
|
|
|
|
while (it.NextPair(pair))
|
|
|
|
{
|
|
|
|
if (pair->Value == vsection) pair->Value = section;
|
|
|
|
}
|
2017-03-16 20:33:13 +00:00
|
|
|
sectvalid[vsection - 1] = false;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-16 20:33:13 +00:00
|
|
|
for (int i = 0; i < num; i++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
if (sectvalid[i]) sectmap[i] = mergecount++;
|
|
|
|
}
|
2017-03-16 23:22:52 +00:00
|
|
|
for (auto &sub : level.subsectors)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-03-16 23:22:52 +00:00
|
|
|
sub.mapsection = sectmap[sub.mapsection - 1];
|
|
|
|
assert(sub.mapsection != -1);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
2017-03-16 20:33:13 +00:00
|
|
|
return mergecount - 1;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
static void SetMapSections()
|
|
|
|
{
|
|
|
|
bool set;
|
|
|
|
int num = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
set = false;
|
2017-03-16 23:22:52 +00:00
|
|
|
for (auto &sub : level.subsectors)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-03-16 23:22:52 +00:00
|
|
|
if (sub.mapsection == 0)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
num++;
|
2017-03-16 23:22:52 +00:00
|
|
|
DoSetMapSection(&sub, num);
|
2013-06-23 07:49:34 +00:00
|
|
|
set = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (set);
|
|
|
|
num = MergeMapSections(num);
|
|
|
|
currentmapsection.Resize(1 + num/8);
|
|
|
|
#ifdef DEBUG
|
|
|
|
Printf("%d map sections found\n", num);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// prepare subsectors for GL rendering
|
|
|
|
// - analyze rendering hacks using open sectors
|
|
|
|
// - assign a render sector (for self referencing sectors)
|
|
|
|
// - calculate a bounding box
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
static void SpreadHackedFlag(subsector_t * sub)
|
|
|
|
{
|
|
|
|
// The subsector pointer hasn't been set yet!
|
2017-03-09 19:19:55 +00:00
|
|
|
for(uint32_t i=0;i<sub->numlines;i++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
seg_t * seg = sub->firstline + i;
|
|
|
|
|
|
|
|
if (seg->PartnerSeg)
|
|
|
|
{
|
|
|
|
subsector_t * sub2 = seg->PartnerSeg->Subsector;
|
|
|
|
|
|
|
|
if (!(sub2->hacked&1) && sub2->render_sector == sub->render_sector)
|
|
|
|
{
|
|
|
|
sub2->hacked|=1;
|
2014-08-31 21:01:53 +00:00
|
|
|
sub->hacked &= ~4;
|
2013-06-23 07:49:34 +00:00
|
|
|
SpreadHackedFlag (sub2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
static void PrepareSectorData()
|
|
|
|
{
|
|
|
|
TArray<subsector_t *> undetermined;
|
|
|
|
|
|
|
|
// now group the subsectors by sector
|
2017-03-16 23:22:52 +00:00
|
|
|
subsector_t ** subsectorbuffer = new subsector_t * [level.subsectors.Size()];
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2017-03-16 23:22:52 +00:00
|
|
|
for (auto &sub : level.subsectors)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-03-16 23:22:52 +00:00
|
|
|
sub.render_sector->subsectorcount++;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
2017-01-07 18:32:24 +00:00
|
|
|
for (auto &sec : level.sectors)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-01-07 18:32:24 +00:00
|
|
|
sec.subsectors = subsectorbuffer;
|
|
|
|
subsectorbuffer += sec.subsectorcount;
|
|
|
|
sec.subsectorcount = 0;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
2017-03-16 23:22:52 +00:00
|
|
|
for (auto &sub : level.subsectors)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-03-16 23:22:52 +00:00
|
|
|
sub.render_sector->subsectors[sub.render_sector->subsectorcount++] = ⊂
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// marks all malformed subsectors so rendering tricks using them can be handled more easily
|
2017-03-16 23:22:52 +00:00
|
|
|
for (auto &sub : level.subsectors)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-03-16 23:22:52 +00:00
|
|
|
if (sub.sector == sub.render_sector)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-03-16 23:22:52 +00:00
|
|
|
seg_t * seg = sub.firstline;
|
|
|
|
for(uint32_t j=0;j<sub.numlines;j++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-03-16 23:22:52 +00:00
|
|
|
if (!(sub.hacked&1) && seg[j].linedef==0 &&
|
2013-06-23 07:49:34 +00:00
|
|
|
seg[j].PartnerSeg!=NULL &&
|
2017-03-16 23:22:52 +00:00
|
|
|
sub.render_sector != seg[j].PartnerSeg->Subsector->render_sector)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-08-28 08:11:09 +00:00
|
|
|
DPrintf(DMSG_NOTIFY, "Found hack: (%f,%f) (%f,%f)\n", seg[j].v1->fX(), seg[j].v1->fY(), seg[j].v2->fX(), seg[j].v2->fY());
|
2017-03-16 23:22:52 +00:00
|
|
|
sub.hacked|=5;
|
|
|
|
SpreadHackedFlag(&sub);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
2017-03-16 23:22:52 +00:00
|
|
|
if (seg[j].PartnerSeg==NULL) sub.hacked|=2; // used for quick termination checks
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SetMapSections();
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Some processing for transparent door hacks using a floor raised by 1 map unit
|
|
|
|
// - This will be used to lower the floor of such sectors by one map unit
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
static void PrepareTransparentDoors(sector_t * sector)
|
|
|
|
{
|
|
|
|
bool solidwall=false;
|
2017-01-05 13:45:15 +00:00
|
|
|
unsigned int notextures=0;
|
|
|
|
unsigned int nobtextures=0;
|
|
|
|
unsigned int selfref=0;
|
2013-06-23 07:49:34 +00:00
|
|
|
sector_t * nextsec=NULL;
|
|
|
|
|
|
|
|
P_Recalculate3DFloors(sector);
|
|
|
|
if (sector->subsectorcount==0) return;
|
|
|
|
|
|
|
|
sector->transdoorheight=sector->GetPlaneTexZ(sector_t::floor);
|
2016-03-29 11:45:50 +00:00
|
|
|
sector->transdoor= !(sector->e->XFloor.ffloors.Size() || sector->heightsec || sector->floorplane.isSlope());
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
if (sector->transdoor)
|
|
|
|
{
|
2017-01-02 20:40:52 +00:00
|
|
|
for (auto ln : sector->Lines)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-01-02 20:40:52 +00:00
|
|
|
if (ln->frontsector == ln->backsector)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
selfref++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-01-02 20:40:52 +00:00
|
|
|
sector_t * sec=getNextSector(ln, sector);
|
2013-06-23 07:49:34 +00:00
|
|
|
if (sec==NULL)
|
|
|
|
{
|
|
|
|
solidwall=true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nextsec=sec;
|
|
|
|
|
2017-01-02 20:40:52 +00:00
|
|
|
int side = ln->sidedef[0]->sector == sec;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2016-06-29 10:19:00 +00:00
|
|
|
if (sector->GetPlaneTexZ(sector_t::floor)!=sec->GetPlaneTexZ(sector_t::floor)+1. || sec->floorplane.isSlope())
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
sector->transdoor=false;
|
|
|
|
return;
|
|
|
|
}
|
2017-01-02 20:40:52 +00:00
|
|
|
if (!ln->sidedef[1-side]->GetTexture(side_t::top).isValid()) notextures++;
|
|
|
|
if (!ln->sidedef[1-side]->GetTexture(side_t::bottom).isValid()) nobtextures++;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sector->GetTexture(sector_t::ceiling)==skyflatnum)
|
|
|
|
{
|
|
|
|
sector->transdoor=false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-02 20:40:52 +00:00
|
|
|
if (selfref+nobtextures!=sector->Lines.Size())
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
sector->transdoor=false;
|
|
|
|
}
|
|
|
|
|
2017-01-02 20:40:52 +00:00
|
|
|
if (selfref+notextures!=sector->Lines.Size())
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
// This is a crude attempt to fix an incorrect transparent door effect I found in some
|
|
|
|
// WolfenDoom maps but considering the amount of code required to handle it I left it in.
|
|
|
|
// Do this only if the sector only contains one-sided walls or ones with no lower texture.
|
|
|
|
if (solidwall)
|
|
|
|
{
|
2017-01-02 20:40:52 +00:00
|
|
|
if (solidwall+nobtextures+selfref==sector->Lines.Size() && nextsec)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
sector->heightsec=nextsec;
|
|
|
|
sector->heightsec->MoreFlags=0;
|
|
|
|
}
|
|
|
|
sector->transdoor=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
static void AddToVertex(const sector_t * sec, TArray<int> & list)
|
|
|
|
{
|
2017-01-07 19:02:25 +00:00
|
|
|
int secno = sec->Index();
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
for(unsigned i=0;i<list.Size();i++)
|
|
|
|
{
|
|
|
|
if (list[i]==secno) return;
|
|
|
|
}
|
|
|
|
list.Push(secno);
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Attach sectors to vertices - used to generate vertex height lists
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
static void InitVertexData()
|
|
|
|
{
|
2017-01-14 11:35:23 +00:00
|
|
|
auto vt_sectorlists = new TArray<int>[level.vertexes.Size()];
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2017-01-08 13:39:16 +00:00
|
|
|
for(auto &line : level.lines)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-01-14 11:35:23 +00:00
|
|
|
for(int j = 0; j < 2; ++j)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-01-08 13:39:16 +00:00
|
|
|
vertex_t * v = j==0? line.v1 : line.v2;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2017-01-14 11:35:23 +00:00
|
|
|
for(int k = 0; k < 2; ++k)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-01-08 13:39:16 +00:00
|
|
|
sector_t * sec = k==0? line.frontsector : line.backsector;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
if (sec)
|
|
|
|
{
|
|
|
|
extsector_t::xfloor &x = sec->e->XFloor;
|
|
|
|
|
2017-01-08 23:46:16 +00:00
|
|
|
AddToVertex(sec, vt_sectorlists[v->Index()]);
|
|
|
|
if (sec->heightsec) AddToVertex(sec->heightsec, vt_sectorlists[v->Index()]);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-14 11:35:23 +00:00
|
|
|
for(unsigned i = 0; i < level.vertexes.Size(); ++i)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2018-01-21 15:17:49 +00:00
|
|
|
auto &vert = level.vertexes[i];
|
2013-06-23 07:49:34 +00:00
|
|
|
int cnt = vt_sectorlists[i].Size();
|
|
|
|
|
2017-01-08 23:46:16 +00:00
|
|
|
vert.dirty = true;
|
|
|
|
vert.numheights=0;
|
2013-06-23 07:49:34 +00:00
|
|
|
if (cnt>1)
|
|
|
|
{
|
2017-01-08 23:46:16 +00:00
|
|
|
vert.numsectors= cnt;
|
|
|
|
vert.sectors=new sector_t*[cnt];
|
|
|
|
vert.heightlist = new float[cnt*2];
|
2013-06-23 07:49:34 +00:00
|
|
|
for(int j=0;j<cnt;j++)
|
|
|
|
{
|
2017-01-08 23:46:16 +00:00
|
|
|
vert.sectors[j] = &level.sectors[vt_sectorlists[i][j]];
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-01-08 23:46:16 +00:00
|
|
|
vert.numsectors=0;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
delete [] vt_sectorlists;
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
2016-04-03 09:40:14 +00:00
|
|
|
static void GetSideVertices(int sdnum, DVector2 *v1, DVector2 *v2)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-01-08 17:45:30 +00:00
|
|
|
line_t *ln = level.sides[sdnum].linedef;
|
|
|
|
if (ln->sidedef[0] == &level.sides[sdnum])
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2016-04-03 09:40:14 +00:00
|
|
|
*v1 = ln->v1->fPos();
|
|
|
|
*v2 = ln->v2->fPos();
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-03 09:40:14 +00:00
|
|
|
*v2 = ln->v1->fPos();
|
|
|
|
*v1 = ln->v2->fPos();
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-11 08:55:09 +00:00
|
|
|
static int segcmp(const void *a, const void *b)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
seg_t *A = *(seg_t**)a;
|
|
|
|
seg_t *B = *(seg_t**)b;
|
|
|
|
return xs_RoundToInt(FRACUNIT*(A->sidefrac - B->sidefrac));
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Group segs to sidedefs
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
static void PrepareSegs()
|
|
|
|
{
|
2017-01-08 17:45:30 +00:00
|
|
|
auto numsides = level.sides.Size();
|
2013-06-23 07:49:34 +00:00
|
|
|
int *segcount = new int[numsides];
|
|
|
|
int realsegs = 0;
|
|
|
|
|
|
|
|
// count the segs
|
|
|
|
memset(segcount, 0, numsides * sizeof(int));
|
|
|
|
|
2017-03-16 20:33:13 +00:00
|
|
|
for(auto &seg : level.segs)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-03-16 20:33:13 +00:00
|
|
|
if (seg.sidedef == NULL) continue; // miniseg
|
|
|
|
int sidenum = seg.sidedef->Index();
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
realsegs++;
|
|
|
|
segcount[sidenum]++;
|
2017-03-16 20:33:13 +00:00
|
|
|
DVector2 sidestart, sideend, segend = seg.v2->fPos();
|
2013-06-23 07:49:34 +00:00
|
|
|
GetSideVertices(sidenum, &sidestart, &sideend);
|
|
|
|
|
|
|
|
sideend -=sidestart;
|
|
|
|
segend -= sidestart;
|
|
|
|
|
2017-03-16 20:33:13 +00:00
|
|
|
seg.sidefrac = float(segend.Length() / sideend.Length());
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// allocate memory
|
2017-01-08 17:45:30 +00:00
|
|
|
level.sides[0].segs = new seg_t*[realsegs];
|
|
|
|
level.sides[0].numsegs = 0;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
2017-01-14 11:35:23 +00:00
|
|
|
for(unsigned i = 1; i < numsides; i++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-01-08 17:45:30 +00:00
|
|
|
level.sides[i].segs = level.sides[i-1].segs + segcount[i-1];
|
|
|
|
level.sides[i].numsegs = 0;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
delete [] segcount;
|
|
|
|
|
|
|
|
// assign the segs
|
2017-03-16 20:33:13 +00:00
|
|
|
for (auto &seg : level.segs)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-03-16 20:33:13 +00:00
|
|
|
if (seg.sidedef != NULL) seg.sidedef->segs[seg.sidedef->numsegs++] = &seg;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// sort the segs
|
2017-01-14 11:35:23 +00:00
|
|
|
for(unsigned i = 0; i < numsides; i++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-01-08 17:45:30 +00:00
|
|
|
if (level.sides[i].numsegs > 1) qsort(level.sides[i].segs, level.sides[i].numsegs, sizeof(seg_t*), segcmp);
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Initialize the level data for the GL renderer
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void gl_PreprocessLevel()
|
|
|
|
{
|
|
|
|
PrepareSegs();
|
|
|
|
PrepareSectorData();
|
|
|
|
InitVertexData();
|
2017-01-08 23:46:16 +00:00
|
|
|
int *checkmap = new int[level.vertexes.Size()];
|
|
|
|
memset(checkmap, -1, sizeof(int)*level.vertexes.Size());
|
2017-01-07 18:32:24 +00:00
|
|
|
for(auto &sec : level.sectors)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-01-07 18:32:24 +00:00
|
|
|
int i = sec.sectornum;
|
|
|
|
PrepareTransparentDoors(&sec);
|
2014-07-27 15:57:53 +00:00
|
|
|
|
|
|
|
// This ignores vertices only used for seg splitting because those aren't needed here
|
2017-01-07 18:32:24 +00:00
|
|
|
for(auto l : sec.Lines)
|
2014-07-27 15:57:53 +00:00
|
|
|
{
|
|
|
|
if (l->sidedef[0]->Flags & WALLF_POLYOBJ) continue; // don't bother with polyobjects
|
|
|
|
|
2017-01-08 23:46:16 +00:00
|
|
|
int vtnum1 = l->v1->Index();
|
|
|
|
int vtnum2 = l->v2->Index();
|
2014-07-27 15:57:53 +00:00
|
|
|
|
2014-07-28 20:23:17 +00:00
|
|
|
if (checkmap[vtnum1] < i)
|
2014-07-27 15:57:53 +00:00
|
|
|
{
|
2014-07-28 20:23:17 +00:00
|
|
|
checkmap[vtnum1] = i;
|
2017-01-08 23:46:16 +00:00
|
|
|
sec.e->vertices.Push(&level.vertexes[vtnum1]);
|
|
|
|
level.vertexes[vtnum1].dirty = true;
|
2014-07-27 15:57:53 +00:00
|
|
|
}
|
|
|
|
|
2014-07-28 20:23:17 +00:00
|
|
|
if (checkmap[vtnum2] < i)
|
2014-07-27 15:57:53 +00:00
|
|
|
{
|
2014-07-28 20:23:17 +00:00
|
|
|
checkmap[vtnum2] = i;
|
2017-01-08 23:46:16 +00:00
|
|
|
sec.e->vertices.Push(&level.vertexes[vtnum2]);
|
|
|
|
level.vertexes[vtnum2].dirty = true;
|
2014-07-27 15:57:53 +00:00
|
|
|
}
|
|
|
|
}
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
2014-07-27 15:57:53 +00:00
|
|
|
delete[] checkmap;
|
2013-06-23 07:49:34 +00:00
|
|
|
|
|
|
|
gl_InitPortals();
|
|
|
|
|
|
|
|
if (GLRenderer != NULL)
|
|
|
|
{
|
|
|
|
GLRenderer->SetupLevel();
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
gl_CreateSections();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// Cleans up all the GL data for the last level
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
void gl_CleanLevelData()
|
|
|
|
{
|
|
|
|
// Dynamic lights must be destroyed before the sector information here is deleted.
|
|
|
|
TThinkerIterator<ADynamicLight> it(STAT_DLIGHT);
|
|
|
|
AActor * mo=it.Next();
|
|
|
|
while (mo)
|
|
|
|
{
|
|
|
|
AActor * next = it.Next();
|
|
|
|
mo->Destroy();
|
|
|
|
mo=next;
|
|
|
|
}
|
|
|
|
|
2017-01-08 17:45:30 +00:00
|
|
|
if (level.sides.Size() > 0 && level.sides[0].segs)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-01-08 17:45:30 +00:00
|
|
|
delete [] level.sides[0].segs;
|
|
|
|
level.sides[0].segs = NULL;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
2017-01-07 18:32:24 +00:00
|
|
|
if (level.sectors.Size() > 0 && level.sectors[0].subsectors)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-01-07 18:32:24 +00:00
|
|
|
delete [] level.sectors[0].subsectors;
|
|
|
|
level.sectors[0].subsectors = nullptr;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
2017-03-16 23:22:52 +00:00
|
|
|
for (auto &sub : level.subsectors)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
|
|
|
for(int j=0;j<2;j++)
|
|
|
|
{
|
2017-03-16 23:22:52 +00:00
|
|
|
if (sub.portalcoverage[j].subsectors != NULL)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-03-16 23:22:52 +00:00
|
|
|
delete [] sub.portalcoverage[j].subsectors;
|
|
|
|
sub.portalcoverage[j].subsectors = NULL;
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-16 17:51:54 +00:00
|
|
|
for(unsigned i=0;i<glSectorPortals.Size(); i++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-03-16 17:51:54 +00:00
|
|
|
delete glSectorPortals[i];
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
2017-03-16 17:51:54 +00:00
|
|
|
glSectorPortals.Clear();
|
2013-06-23 07:49:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
CCMD(listmapsections)
|
|
|
|
{
|
2017-03-16 23:22:52 +00:00
|
|
|
for (int i = 0; i < 100; i++)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-03-16 23:22:52 +00:00
|
|
|
for (auto &sub : level.subsectors)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-03-16 23:22:52 +00:00
|
|
|
if (sub.mapsection == i)
|
2013-06-23 07:49:34 +00:00
|
|
|
{
|
2017-03-16 23:22:52 +00:00
|
|
|
Printf("Mapsection %d, sector %d, line %d\n", i, sub.render_sector->Index(), sub.firstline->linedef->Index());
|
2013-06-23 07:49:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-08-28 06:33:11 +00:00
|
|
|
}
|