mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-15 00:41:55 +00:00
- new section WIP.
This commit is contained in:
parent
1bf654036a
commit
a733de618f
6 changed files with 131 additions and 0 deletions
|
@ -1066,6 +1066,7 @@ set (PCH_SOURCES
|
|||
core/rendering/hw_voxels.cpp
|
||||
core/rendering/hw_palmanager.cpp
|
||||
core/rendering/hw_sections.cpp
|
||||
core/rendering/hw_sections2.cpp
|
||||
core/rendering/scene/hw_clipper.cpp
|
||||
core/rendering/scene/hw_walls.cpp
|
||||
core/rendering/scene/hw_flats.cpp
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#include "render.h"
|
||||
#include "hw_sections.h"
|
||||
#include "interpolate.h"
|
||||
#include "hw_sections2.h"
|
||||
#include "games/blood/src/mapstructs.h"
|
||||
|
||||
extern BitArray clipsectormap;
|
||||
|
@ -489,6 +490,7 @@ void engineLoadBoard(const char* filename, int flags, vec3_t* pos, int16_t* ang,
|
|||
G_LoadMapHack(filename, md4, sprites);
|
||||
setWallSectors();
|
||||
hw_BuildSections();
|
||||
hw_CreateSections2();
|
||||
sectorGeometry.SetSize(Sections.Size());
|
||||
|
||||
|
||||
|
|
93
source/core/rendering/hw_sections2.cpp
Normal file
93
source/core/rendering/hw_sections2.cpp
Normal file
|
@ -0,0 +1,93 @@
|
|||
#include "build.h"
|
||||
#include "hw_sections2.h"
|
||||
|
||||
int GetWindingOrder(TArray<int>& walls)
|
||||
{
|
||||
int check = -1;
|
||||
int minY = INT_MAX;
|
||||
int minXAtMinY = INT_MAX;
|
||||
for (unsigned i = 0; i < walls.Size(); i++)
|
||||
{
|
||||
auto wal = &wall[walls[i]];
|
||||
int y = wal->y;
|
||||
|
||||
if (y < minY)
|
||||
{
|
||||
minY = y;
|
||||
minXAtMinY = INT_MAX, // must reset this if a new y is picked.
|
||||
check = i;
|
||||
}
|
||||
else if (y == minY && wal->x < minXAtMinY)
|
||||
{
|
||||
minXAtMinY = wal->x;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned prev = check == 0? walls.Size() - 1 : check - 1;
|
||||
unsigned next = check == walls.Size()? 0 : check + 1;
|
||||
|
||||
DVector2 a = { (double)wall[walls[prev]].x, (double)wall[walls[prev]].y };
|
||||
DVector2 b = { (double)wall[walls[check]].x, (double)wall[walls[check]].y };
|
||||
DVector2 c = { (double)wall[walls[next]].x, (double)wall[walls[next]].y };
|
||||
|
||||
return (b.X * c.Y + a.X * b.Y + a.Y * c.X) - (a.Y * b.X + b.Y * c.X + a.X * c.Y) > 0;
|
||||
}
|
||||
|
||||
struct loopcollect
|
||||
{
|
||||
TArray<TArray<int>> loops;
|
||||
bool bugged;
|
||||
};
|
||||
|
||||
void CollectLoops(TArray<loopcollect>& sectors)
|
||||
{
|
||||
BitArray visited;
|
||||
visited.Resize(numwalls);
|
||||
visited.Zero();
|
||||
|
||||
TArray<int> thisloop;
|
||||
|
||||
int count = 0;
|
||||
for (int i = 0; i < numsectors; i++)
|
||||
{
|
||||
int first = sector[i].wallptr;
|
||||
int last = first + sector[i].wallnum;
|
||||
sectors.Reserve(1);
|
||||
sectors.Last().bugged = false;
|
||||
|
||||
for (int w = first; w < last; w++)
|
||||
{
|
||||
if (visited[w]) continue;
|
||||
thisloop.Clear();
|
||||
thisloop.Push(w);
|
||||
|
||||
for (int ww = wall[w].point2; ww != w; ww = wall[ww].point2)
|
||||
{
|
||||
if (ww < first || ww >= last)
|
||||
{
|
||||
Printf("Found wall %d outside sector %d in a loop\n", ww, i);
|
||||
sectors.Last().bugged = true;
|
||||
break;
|
||||
}
|
||||
if (visited[ww])
|
||||
{
|
||||
Printf("Wall %d's point2 links to already visited wall %d\n", w, ww);
|
||||
sectors.Last().bugged = true;
|
||||
break;
|
||||
}
|
||||
thisloop.Push(ww);
|
||||
visited.Set(ww);
|
||||
}
|
||||
count ++;
|
||||
sectors.Last().loops.Push(std::move(thisloop));
|
||||
}
|
||||
}
|
||||
Printf("Created %d loops from %d sectors, %d walls\n", count, numsectors, numwalls);
|
||||
}
|
||||
|
||||
|
||||
void hw_CreateSections2()
|
||||
{
|
||||
TArray<loopcollect> sectors;
|
||||
CollectLoops(sectors);
|
||||
}
|
31
source/core/rendering/hw_sections2.h
Normal file
31
source/core/rendering/hw_sections2.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
|
||||
struct Section2;
|
||||
|
||||
struct Section2Wall
|
||||
{
|
||||
// references to game data
|
||||
vec3_t* v1; // points to start vertex in wall[]
|
||||
vec3_t* v2; // points to end vertex in wall[]
|
||||
walltype* wall; // points to the actual wall this belongs to - this is NOT necessarily the same as v1 and can be null.
|
||||
|
||||
// references to section data
|
||||
Section2Wall* backside; // points to this wall's back side
|
||||
Section2* frontsection;
|
||||
Section2* backsection; // if this is null the wall is one-sided
|
||||
};
|
||||
|
||||
struct Loop
|
||||
{
|
||||
TArrayView<Section2Wall*> walls;
|
||||
bool unclosed;
|
||||
};
|
||||
|
||||
struct Section2
|
||||
{
|
||||
sectortype* sector;
|
||||
// this uses a memory arena for storage, so use TArrayView instead of TArray
|
||||
TArrayView<Section2Wall*> walls;
|
||||
TArrayView<Loop*> loops;
|
||||
};
|
||||
|
||||
void hw_CreateSections2();
|
|
@ -63,6 +63,7 @@
|
|||
#include "ns.h"
|
||||
#include "serialize_obj.h"
|
||||
#include "games/blood/src/mapstructs.h"
|
||||
#include "hw_sections2.h"
|
||||
#include <zlib.h>
|
||||
|
||||
|
||||
|
@ -725,6 +726,7 @@ void SerializeMap(FSerializer& arc)
|
|||
{
|
||||
setWallSectors();
|
||||
hw_BuildSections();
|
||||
hw_CreateSections2();
|
||||
sectorGeometry.SetSize(Sections.Size());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#include "gamefuncs.h"
|
||||
#include "hw_sections.h"
|
||||
#include "sectorgeometry.h"
|
||||
#include "hw_sections2.h"
|
||||
|
||||
#include "blood.h"
|
||||
|
||||
|
@ -728,6 +729,7 @@ void dbLoadMap(const char* pPath, int* pX, int* pY, int* pZ, short* pAngle, sect
|
|||
|
||||
setWallSectors();
|
||||
hw_BuildSections();
|
||||
hw_CreateSections2();
|
||||
sectorGeometry.SetSize(Sections.Size());
|
||||
wallbackup = wall;
|
||||
sectorbackup = sector;
|
||||
|
|
Loading…
Reference in a new issue