mirror of
https://github.com/ZDoom/Raze.git
synced 2025-06-04 19:20:43 +00:00
After this any old mesh has become invalid and needs to be rebuilt.
- use only one Section type.
This commit is contained in:
parent
8e01d559e8
commit
37e49ed775
8 changed files with 48 additions and 51 deletions
|
@ -46,6 +46,7 @@
|
||||||
#include "nodebuilder/nodebuild.h"
|
#include "nodebuilder/nodebuild.h"
|
||||||
|
|
||||||
|
|
||||||
|
FMemArena tempsectionArena(102400);
|
||||||
TArray<SectionLine> sectionLines;
|
TArray<SectionLine> sectionLines;
|
||||||
TArray<Section> Sections;
|
TArray<Section> Sections;
|
||||||
TArray<TArray<int>> sectionspersector; // reverse map, mainly for the automap
|
TArray<TArray<int>> sectionspersector; // reverse map, mainly for the automap
|
||||||
|
@ -59,13 +60,15 @@ TArray<int> splits;
|
||||||
void hw_BuildSections()
|
void hw_BuildSections()
|
||||||
{
|
{
|
||||||
Sections.Resize(numsectors);
|
Sections.Resize(numsectors);
|
||||||
|
memset(Sections.Data(), 0, numsectors * sizeof(Section));
|
||||||
sectionspersector.Resize(numsectors);
|
sectionspersector.Resize(numsectors);
|
||||||
sectionLines.Resize(numwalls * 5 / 4); // cannot reallocate, unfortunately.
|
sectionLines.Resize(numwalls * 5 / 4); // cannot reallocate, unfortunately.
|
||||||
numsectionlines = numwalls;
|
numsectionlines = numwalls;
|
||||||
for (int i = 0; i < numsectors; i++)
|
for (int i = 0; i < numsectors; i++)
|
||||||
{
|
{
|
||||||
Sections[i].sector = i;
|
Sections[i].sector = i;
|
||||||
Sections[i].lines.Resize(sector[i].wallnum);
|
auto lines = (int*)tempsectionArena.Alloc(sector[i].wallnum * sizeof(int));
|
||||||
|
Sections[i].lines.Set(lines, sector[i].wallnum);
|
||||||
for (int j = 0; j < sector[i].wallnum; j++) Sections[i].lines[j] = sector[i].wallptr + j;
|
for (int j = 0; j < sector[i].wallnum; j++) Sections[i].lines[j] = sector[i].wallptr + j;
|
||||||
sectionspersector[i].Resize(1);
|
sectionspersector[i].Resize(1);
|
||||||
sectionspersector[i][0] = i;
|
sectionspersector[i][0] = i;
|
||||||
|
|
|
@ -2,6 +2,14 @@
|
||||||
|
|
||||||
#include "build.h"
|
#include "build.h"
|
||||||
|
|
||||||
|
enum ESEctionFlag
|
||||||
|
{
|
||||||
|
Unclosed = 1, // at least one unclosed loop
|
||||||
|
Dumped = 2, // builder was unable to properly construct, so content may not be usable for triangulator.
|
||||||
|
BadWinding = 4,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
struct SectionLine
|
struct SectionLine
|
||||||
{
|
{
|
||||||
int section;
|
int section;
|
||||||
|
@ -25,11 +33,21 @@ inline SectionLine* SectionLine::partnerLine() const
|
||||||
return partner == -1 ? nullptr : §ionLines[partner];
|
return partner == -1 ? nullptr : §ionLines[partner];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Section2Loop
|
||||||
|
{
|
||||||
|
TArrayView<int> walls;
|
||||||
|
};
|
||||||
|
|
||||||
struct Section
|
struct Section
|
||||||
{
|
{
|
||||||
|
uint8_t flags;
|
||||||
|
uint8_t dirty;
|
||||||
|
uint8_t geomflags;
|
||||||
|
unsigned index;
|
||||||
int sector;
|
int sector;
|
||||||
// this is the whole point of sections - instead of just having a start index and count, we have an explicit list of lines that's a lot easier to change when needed.
|
// this uses a memory arena for storage, so use TArrayView instead of TArray
|
||||||
TArray<int> lines;
|
TArrayView<int> lines;
|
||||||
|
TArrayView<Section2Loop> loops;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern TArray<Section> Sections;
|
extern TArray<Section> Sections;
|
||||||
|
|
|
@ -43,12 +43,13 @@
|
||||||
#include "memarena.h"
|
#include "memarena.h"
|
||||||
#include "c_cvars.h"
|
#include "c_cvars.h"
|
||||||
|
|
||||||
|
FMemArena sectionArena(102400);
|
||||||
|
|
||||||
CVAR(Bool, hw_sectiondebug, false, 0)
|
CVAR(Bool, hw_sectiondebug, false, 0)
|
||||||
TMap<int, bool> bugged;
|
TMap<int, bool> bugged;
|
||||||
|
|
||||||
static FMemArena sectionArena(102400);
|
TArray<Section*> sections2;
|
||||||
TArray<Section2*> sections2;
|
TArrayView<TArrayView<Section*>> sections2PerSector;
|
||||||
TArrayView<TArrayView<Section2*>> sections2PerSector;
|
|
||||||
|
|
||||||
struct loopcollect
|
struct loopcollect
|
||||||
{
|
{
|
||||||
|
@ -548,9 +549,9 @@ static void ConstructSections(TArray<sectionbuildsector>& builders)
|
||||||
auto& builder = builders[i];
|
auto& builder = builders[i];
|
||||||
count += builder.sections.Size();
|
count += builder.sections.Size();
|
||||||
|
|
||||||
size = sizeof(Section2*) * builder.sections.Size();
|
size = sizeof(Section*) * builder.sections.Size();
|
||||||
data = sectionArena.Calloc(size);
|
data = sectionArena.Calloc(size);
|
||||||
sections2PerSector[i].Set(static_cast<Section2** >(data), builder.sections.Size()); // although this may need reallocation, it is too small to warrant single allocations for each sector.
|
sections2PerSector[i].Set(static_cast<Section** >(data), builder.sections.Size()); // although this may need reallocation, it is too small to warrant single allocations for each sector.
|
||||||
}
|
}
|
||||||
sections2.Resize(count); // this we cannot put into the arena because its size may change.
|
sections2.Resize(count); // this we cannot put into the arena because its size may change.
|
||||||
memset(sections2.Data(), 0, count * sizeof(*sections2.Data()));
|
memset(sections2.Data(), 0, count * sizeof(*sections2.Data()));
|
||||||
|
@ -563,7 +564,7 @@ static void ConstructSections(TArray<sectionbuildsector>& builders)
|
||||||
auto& builder = builders[i];
|
auto& builder = builders[i];
|
||||||
for (unsigned j = 0; j < builder.sections.Size(); j++)
|
for (unsigned j = 0; j < builder.sections.Size(); j++)
|
||||||
{
|
{
|
||||||
auto section = (Section2*)sectionArena.Calloc(sizeof(Section2));
|
auto section = (Section*)sectionArena.Calloc(sizeof(Section));
|
||||||
auto& srcsect = builder.sections[j];
|
auto& srcsect = builder.sections[j];
|
||||||
sections2[cursection] = section;
|
sections2[cursection] = section;
|
||||||
sections2PerSector[i][j] = section;
|
sections2PerSector[i][j] = section;
|
||||||
|
@ -661,7 +662,7 @@ void hw_CreateSections2()
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
Outline BuildOutline(Section2* section)
|
Outline BuildOutline(Section* section)
|
||||||
{
|
{
|
||||||
Outline output(section->loops.Size(), true);
|
Outline output(section->loops.Size(), true);
|
||||||
for (unsigned i = 0; i < section->loops.Size(); i++)
|
for (unsigned i = 0; i < section->loops.Size(); i++)
|
||||||
|
|
|
@ -1,35 +1,10 @@
|
||||||
#include "hw_sections.h"
|
#include "hw_sections.h"
|
||||||
struct Section2;
|
|
||||||
|
|
||||||
enum ESEctionFlag
|
extern TArray<Section*> sections2;
|
||||||
{
|
extern TArrayView<TArrayView<Section*>> sections2PerSector;
|
||||||
Unclosed = 1, // at least one unclosed loop
|
|
||||||
Dumped = 2, // builder was unable to properly construct, so content may not be usable for triangulator.
|
|
||||||
BadWinding = 4,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Section2Loop
|
|
||||||
{
|
|
||||||
TArrayView<int> walls;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Section2
|
|
||||||
{
|
|
||||||
uint8_t flags;
|
|
||||||
uint8_t dirty;
|
|
||||||
uint8_t geomflags;
|
|
||||||
unsigned index;
|
|
||||||
int sector;
|
|
||||||
// this uses a memory arena for storage, so use TArrayView instead of TArray
|
|
||||||
TArrayView<int> lines;
|
|
||||||
TArrayView<Section2Loop> loops;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern TArray<Section2*> sections2;
|
|
||||||
extern TArrayView<TArrayView<Section2*>> sections2PerSector;
|
|
||||||
|
|
||||||
void hw_CreateSections2();
|
void hw_CreateSections2();
|
||||||
using Outline = TArray<TArray<vec2_t>>;
|
using Outline = TArray<TArray<vec2_t>>;
|
||||||
using Point = std::pair<float, float>;
|
using Point = std::pair<float, float>;
|
||||||
using FOutline = std::vector<std::vector<Point>> ; // Data type was chosen so it can be passed directly into Earcut.
|
using FOutline = std::vector<std::vector<Point>> ; // Data type was chosen so it can be passed directly into Earcut.
|
||||||
Outline BuildOutline(Section2* section);
|
Outline BuildOutline(Section* section);
|
||||||
|
|
|
@ -31,7 +31,7 @@ class VSMatrix;
|
||||||
struct FSpriteModelFrame;
|
struct FSpriteModelFrame;
|
||||||
class FRenderState;
|
class FRenderState;
|
||||||
struct voxmodel_t;
|
struct voxmodel_t;
|
||||||
struct Section2;
|
struct Section;
|
||||||
|
|
||||||
struct HWSectorPlane
|
struct HWSectorPlane
|
||||||
{
|
{
|
||||||
|
@ -254,7 +254,7 @@ class HWFlat
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int oldsection;
|
int oldsection;
|
||||||
Section2* section;
|
Section* section;
|
||||||
sectortype * sec;
|
sectortype * sec;
|
||||||
tspritetype* Sprite; // for flat sprites.
|
tspritetype* Sprite; // for flat sprites.
|
||||||
FGameTexture *texture;
|
FGameTexture *texture;
|
||||||
|
@ -281,7 +281,7 @@ public:
|
||||||
//void SetupLights(HWDrawInfo *di, FLightNode *head, FDynLightData &lightdata, int portalgroup);
|
//void SetupLights(HWDrawInfo *di, FLightNode *head, FDynLightData &lightdata, int portalgroup);
|
||||||
|
|
||||||
void PutFlat(HWDrawInfo* di, int whichplane);
|
void PutFlat(HWDrawInfo* di, int whichplane);
|
||||||
void ProcessSector(HWDrawInfo *di, sectortype * frontsector, Section2* sectionp, int sectionnum, int which = 7 /*SSRF_RENDERALL*/); // cannot use constant due to circular dependencies.
|
void ProcessSector(HWDrawInfo *di, sectortype * frontsector, Section* sectionp, int sectionnum, int which = 7 /*SSRF_RENDERALL*/); // cannot use constant due to circular dependencies.
|
||||||
void ProcessFlatSprite(HWDrawInfo* di, tspritetype* sprite, sectortype* sector);
|
void ProcessFlatSprite(HWDrawInfo* di, tspritetype* sprite, sectortype* sector);
|
||||||
|
|
||||||
void DrawSubsectors(HWDrawInfo *di, FRenderState &state);
|
void DrawSubsectors(HWDrawInfo *di, FRenderState &state);
|
||||||
|
|
|
@ -261,7 +261,7 @@ void HWFlat::PutFlat(HWDrawInfo *di, int whichplane)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
void HWFlat::ProcessSector(HWDrawInfo *di, sectortype * frontsector, Section2* sectionp, int section_, int which)
|
void HWFlat::ProcessSector(HWDrawInfo *di, sectortype * frontsector, Section* sectionp, int section_, int which)
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
if (sectnum(sec) == gl_breaksec)
|
if (sectnum(sec) == gl_breaksec)
|
||||||
|
|
|
@ -424,7 +424,7 @@ ETriangulateResult TriangulateOutlineNodeBuild(const FOutline& polygon, int coun
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
bool SectionGeometry::ValidateSection(Section2* section, int plane)
|
bool SectionGeometry::ValidateSection(Section* section, int plane)
|
||||||
{
|
{
|
||||||
auto sec = §or[section->sector];
|
auto sec = §or[section->sector];
|
||||||
auto& sdata = data[section->index];
|
auto& sdata = data[section->index];
|
||||||
|
@ -469,7 +469,7 @@ bool SectionGeometry::ValidateSection(Section2* section, int plane)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
bool SectionGeometry::CreateMesh(Section2* section)
|
bool SectionGeometry::CreateMesh(Section* section)
|
||||||
{
|
{
|
||||||
auto outline = BuildOutline(section);
|
auto outline = BuildOutline(section);
|
||||||
FOutline foutline;
|
FOutline foutline;
|
||||||
|
@ -508,7 +508,7 @@ bool SectionGeometry::CreateMesh(Section2* section)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
void SectionGeometry::CreatePlaneMesh(Section2* section, int plane, const FVector2& offset)
|
void SectionGeometry::CreatePlaneMesh(Section* section, int plane, const FVector2& offset)
|
||||||
{
|
{
|
||||||
auto sectorp = §or[section->sector];
|
auto sectorp = §or[section->sector];
|
||||||
// calculate the rest.
|
// calculate the rest.
|
||||||
|
@ -559,7 +559,7 @@ void SectionGeometry::MarkDirty(sectortype* sector)
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
SectionGeometryPlane* SectionGeometry::get(Section2* section, int plane, const FVector2& offset, TArray<int>** pIndices)
|
SectionGeometryPlane* SectionGeometry::get(Section* section, int plane, const FVector2& offset, TArray<int>** pIndices)
|
||||||
{
|
{
|
||||||
if (!section || section->index >= data.Size()) return nullptr;
|
if (!section || section->index >= data.Size()) return nullptr;
|
||||||
auto sectp = §or[section->sector];
|
auto sectp = §or[section->sector];
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include "vectors.h"
|
#include "vectors.h"
|
||||||
#include "build.h"
|
#include "build.h"
|
||||||
|
|
||||||
struct Section2;
|
struct Section;
|
||||||
|
|
||||||
struct SectorGeometryPlane
|
struct SectorGeometryPlane
|
||||||
{
|
{
|
||||||
|
@ -73,14 +73,14 @@ class SectionGeometry
|
||||||
{
|
{
|
||||||
TArray<SectionGeometryData> data;
|
TArray<SectionGeometryData> data;
|
||||||
|
|
||||||
bool ValidateSection(Section2* section, int plane);
|
bool ValidateSection(Section* section, int plane);
|
||||||
void MarkDirty(sectortype* sector);
|
void MarkDirty(sectortype* sector);
|
||||||
bool CreateMesh(Section2* section);
|
bool CreateMesh(Section* section);
|
||||||
void CreatePlaneMesh(Section2* section, int plane, const FVector2& offset);
|
void CreatePlaneMesh(Section* section, int plane, const FVector2& offset);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SectionGeometryPlane* get(Section2* section, int plane, const FVector2& offset, TArray<int>** pIndices);
|
SectionGeometryPlane* get(Section* section, int plane, const FVector2& offset, TArray<int>** pIndices);
|
||||||
|
|
||||||
void SetSize(unsigned sectcount)
|
void SetSize(unsigned sectcount)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue