- moved slope creation code to MapLoader.

This commit is contained in:
Christoph Oelckers 2018-11-08 23:36:42 +01:00
parent 4a7c4c89e5
commit bbad004e25
5 changed files with 111 additions and 60 deletions

View file

@ -971,7 +971,6 @@ set (PCH_SOURCES
p_sectors.cpp
p_setup.cpp
p_sight.cpp
p_slopes.cpp
p_spec.cpp
p_states.cpp
p_switch.cpp
@ -1078,6 +1077,7 @@ set (PCH_SOURCES
maploader/maploader_glnodes.cpp
maploader/maploader_bsp.cpp
maploader/maploader_blockmap.cpp
maploader/maploader_slopes.cpp
menu/joystickmenu.cpp
menu/loadsavemenu.cpp
menu/menu.cpp

View file

@ -69,6 +69,8 @@ public:
FTagManager *tagManager = nullptr;
int sidecount = 0;
subsector_t *PointInSubsector(double x, double y);
// maploader_bsp.cpp
int CheckForMissingSegs();
bool CheckForGLNodes();
@ -112,6 +114,17 @@ public:
bool VerifyBlockMap(int count);
void LoadBlockMap(MapData * map);
void SlopeLineToPoint (int lineid, const DVector3 &pos, bool slopeCeil);
void CopyPlane (int tag, sector_t *dest, bool copyCeil);
void CopyPlane (int tag, const DVector2 &pos, bool copyCeil);
void SetSlope (secplane_t *plane, bool setCeil, int xyangi, int zangi, const DVector3 &pos);
void VavoomSlope(sector_t * sec, int id, const DVector3 &pos, int which);
void SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt, const int *oldvertextable);
void SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt, const int *oldvertextable);
void AlignPlane(sector_t *sec, line_t *line, int which);
void SetSlopes ();
void CopySlopes();
public:
template<class T>MapLoader(T &store, FTagManager *tm)

View file

@ -40,6 +40,34 @@
#include "p_spec.h"
#include "g_levellocals.h"
#include "actor.h"
#include "r_utility.h"
#include "r_defs.h"
#include "maploader.h"
//==========================================================================
//
// P_PointInSubsector
// Variant that uses the nodes in the map loader not the global ones-
//
//==========================================================================
subsector_t *MapLoader::PointInSubsector(double x, double y)
{
int side;
auto node = gamenodes.Size() > 0 ? &gamenodes.Last() : nodes.Size() ? &nodes.Last() : nullptr;
if (node == nullptr) return &subsectors[0];
fixed_t xx = FLOAT2FIXED(x);
fixed_t yy = FLOAT2FIXED(y);
do
{
side = R_PointOnSide(xx, yy, node);
node = (node_t *)node->children[side];
} while (!((size_t)node & 1));
return (subsector_t *)((uint8_t *)node - 1);
}
//===========================================================================
//
@ -47,14 +75,14 @@
//
//===========================================================================
static void P_SlopeLineToPoint (int lineid, const DVector3 &pos, bool slopeCeil)
void MapLoader::SlopeLineToPoint (int lineid, const DVector3 &pos, bool slopeCeil)
{
int linenum;
FLineIdIterator itr(lineid);
FLineIdIterator itr(*tagManager, lineid);
while ((linenum = itr.Next()) >= 0)
{
const line_t *line = &level.lines[linenum];
const line_t *line = &lines[linenum];
sector_t *sec;
secplane_t *plane;
@ -66,7 +94,7 @@ static void P_SlopeLineToPoint (int lineid, const DVector3 &pos, bool slopeCeil)
{
sec = line->backsector;
}
if (sec == NULL)
if (sec == nullptr)
{
continue;
}
@ -116,18 +144,19 @@ static void P_SlopeLineToPoint (int lineid, const DVector3 &pos, bool slopeCeil)
//
//===========================================================================
static void P_CopyPlane (int tag, sector_t *dest, bool copyCeil)
void MapLoader::CopyPlane (int tag, sector_t *dest, bool copyCeil)
{
sector_t *source;
int secnum;
secnum = P_FindFirstSectorFromTag (tag);
FSectorTagIterator it(*tagManager, tag);
secnum = it.Next();
if (secnum == -1)
{
return;
}
source = &level.sectors[secnum];
source = &sectors[secnum];
if (copyCeil)
{
@ -139,10 +168,10 @@ static void P_CopyPlane (int tag, sector_t *dest, bool copyCeil)
}
}
static void P_CopyPlane (int tag, const DVector2 &pos, bool copyCeil)
void MapLoader::CopyPlane (int tag, const DVector2 &pos, bool copyCeil)
{
sector_t *dest = P_PointInSector (pos);
P_CopyPlane(tag, dest, copyCeil);
sector_t *dest = PointInSubsector (pos.X, pos.Y)->sector;
CopyPlane(tag, dest, copyCeil);
}
//===========================================================================
@ -151,7 +180,7 @@ static void P_CopyPlane (int tag, const DVector2 &pos, bool copyCeil)
//
//===========================================================================
void P_SetSlope (secplane_t *plane, bool setCeil, int xyangi, int zangi, const DVector3 &pos)
void MapLoader::SetSlope (secplane_t *plane, bool setCeil, int xyangi, int zangi, const DVector3 &pos)
{
DAngle xyang;
DAngle zang;
@ -201,7 +230,7 @@ void P_SetSlope (secplane_t *plane, bool setCeil, int xyangi, int zangi, const D
//
//===========================================================================
void P_VavoomSlope(sector_t * sec, int id, const DVector3 &pos, int which)
void MapLoader::VavoomSlope(sector_t * sec, int id, const DVector3 &pos, int which)
{
for(auto l : sec->Lines)
{
@ -247,7 +276,7 @@ void P_VavoomSlope(sector_t * sec, int id, const DVector3 &pos, int which)
//
//==========================================================================
static void P_SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt, const int *oldvertextable)
void MapLoader::SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt, const int *oldvertextable)
{
TMap<int, double> vt_heights[2];
FMapThing *mt;
@ -255,13 +284,13 @@ static void P_SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt,
for (mt = firstmt; mt < lastmt; ++mt)
{
if (mt->info != NULL && mt->info->Type == NULL)
if (mt->info != nullptr && mt->info->Type == nullptr)
{
if (mt->info->Special == SMT_VertexFloorZ || mt->info->Special == SMT_VertexCeilingZ)
{
for (unsigned i = 0; i < level.vertexes.Size(); i++)
for (unsigned i = 0; i < vertexes.Size(); i++)
{
if (level.vertexes[i].fX() == mt->pos.X && level.vertexes[i].fY() == mt->pos.Y)
if (vertexes[i].fX() == mt->pos.X && vertexes[i].fY() == mt->pos.Y)
{
if (mt->info->Special == SMT_VertexFloorZ)
{
@ -281,7 +310,7 @@ static void P_SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt,
for(unsigned i = 0; i < vertexdatas.Size(); i++)
{
int ii = oldvertextable == NULL ? i : oldvertextable[i];
int ii = oldvertextable == nullptr ? i : oldvertextable[i];
if (vertexdatas[i].flags & VERTEXFLAG_ZCeilingEnabled)
{
@ -297,12 +326,11 @@ static void P_SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt,
}
// If vertexdata_t is ever extended for non-slope usage, this will obviously have to be deferred or removed.
vertexdatas.Clear();
vertexdatas.ShrinkToFit();
vertexdatas.Reset();
if (vt_found)
{
for (auto &sec : level.sectors)
for (auto &sec : sectors)
{
if (sec.Lines.Size() != 3) continue; // only works with triangular sectors
@ -315,22 +343,22 @@ static void P_SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt,
vi3 = (sec.Lines[1]->v1 == sec.Lines[0]->v1 || sec.Lines[1]->v1 == sec.Lines[0]->v2)?
sec.Lines[1]->v2->Index() : sec.Lines[1]->v1->Index();
vt1 = DVector3(level.vertexes[vi1].fPos(), 0);
vt2 = DVector3(level.vertexes[vi2].fPos(), 0);
vt3 = DVector3(level.vertexes[vi3].fPos(), 0);
vt1 = DVector3(vertexes[vi1].fPos(), 0);
vt2 = DVector3(vertexes[vi2].fPos(), 0);
vt3 = DVector3(vertexes[vi3].fPos(), 0);
for(int j=0; j<2; j++)
{
double *h1 = vt_heights[j].CheckKey(vi1);
double *h2 = vt_heights[j].CheckKey(vi2);
double *h3 = vt_heights[j].CheckKey(vi3);
if (h1 == NULL && h2 == NULL && h3 == NULL) continue;
if (h1 == nullptr && h2 == nullptr && h3 == nullptr) continue;
vt1.Z = h1? *h1 : j==0? sec.GetPlaneTexZ(sector_t::floor) : sec.GetPlaneTexZ(sector_t::ceiling);
vt2.Z = h2? *h2 : j==0? sec.GetPlaneTexZ(sector_t::floor) : sec.GetPlaneTexZ(sector_t::ceiling);
vt3.Z = h3? *h3 : j==0? sec.GetPlaneTexZ(sector_t::floor) : sec.GetPlaneTexZ(sector_t::ceiling);
if (P_PointOnLineSidePrecise(level.vertexes[vi3].fX(), level.vertexes[vi3].fY(), sec.Lines[0]) == 0)
if (P_PointOnLineSidePrecise(vertexes[vi3].fX(), vertexes[vi3].fY(), sec.Lines[0]) == 0)
{
vec1 = vt2 - vt3;
vec2 = vt1 - vt3;
@ -360,7 +388,7 @@ static void P_SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt,
secplane_t *plane = j==0? &sec.floorplane : &sec.ceilingplane;
double dist = -cross[0] * level.vertexes[vi3].fX() - cross[1] * level.vertexes[vi3].fY() - cross[2] * vt3.Z;
double dist = -cross[0] * vertexes[vi3].fX() - cross[1] * vertexes[vi3].fY() - cross[2] * vt3.Z;
plane->set(cross[0], cross[1], cross[2], dist);
}
}
@ -373,13 +401,13 @@ static void P_SetSlopesFromVertexHeights(FMapThing *firstmt, FMapThing *lastmt,
//
//===========================================================================
void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt, const int *oldvertextable)
void MapLoader::SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt, const int *oldvertextable)
{
FMapThing *mt;
for (mt = firstmt; mt < lastmt; ++mt)
{
if (mt->info != NULL && mt->info->Type == NULL &&
if (mt->info != nullptr && mt->info->Type == nullptr &&
(mt->info->Special >= SMT_SlopeFloorPointLine && mt->info->Special <= SMT_VavoomCeiling))
{
DVector3 pos = mt->pos;
@ -387,7 +415,7 @@ void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt, const int *oldve
sector_t *sec;
bool ceiling;
sec = P_PointInSector (mt->pos);
sec = PointInSubsector (mt->pos.X, mt->pos.Y)->sector;
if (mt->info->Special == SMT_SlopeCeilingPointLine || mt->info->Special == SMT_VavoomCeiling || mt->info->Special == SMT_SetCeilingSlope)
{
refplane = &sec->ceilingplane;
@ -402,15 +430,15 @@ void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt, const int *oldve
if (mt->info->Special <= SMT_SlopeCeilingPointLine)
{ // SlopeFloorPointLine and SlopCeilingPointLine
P_SlopeLineToPoint (mt->args[0], pos, ceiling);
SlopeLineToPoint (mt->args[0], pos, ceiling);
}
else if (mt->info->Special <= SMT_SetCeilingSlope)
{ // SetFloorSlope and SetCeilingSlope
P_SetSlope (refplane, ceiling, mt->angle, mt->args[0], pos);
SetSlope (refplane, ceiling, mt->angle, mt->args[0], pos);
}
else
{ // VavoomFloor and VavoomCeiling (these do not perform any sector height adjustment - z is absolute)
P_VavoomSlope(sec, mt->thingid, mt->pos, ceiling);
VavoomSlope(sec, mt->thingid, mt->pos, ceiling);
}
mt->EdNum = 0;
}
@ -418,15 +446,15 @@ void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt, const int *oldve
for (mt = firstmt; mt < lastmt; ++mt)
{
if (mt->info != NULL && mt->info->Type == NULL &&
if (mt->info != nullptr && mt->info->Type == nullptr &&
(mt->info->Special == SMT_CopyFloorPlane || mt->info->Special == SMT_CopyCeilingPlane))
{
P_CopyPlane (mt->args[0], mt->pos, mt->info->Special == SMT_CopyCeilingPlane);
CopyPlane (mt->args[0], mt->pos, mt->info->Special == SMT_CopyCeilingPlane);
mt->EdNum = 0;
}
}
P_SetSlopesFromVertexHeights(firstmt, lastmt, oldvertextable);
SetSlopesFromVertexHeights(firstmt, lastmt, oldvertextable);
}
@ -445,13 +473,13 @@ void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt, const int *oldve
//
//===========================================================================
static void P_AlignPlane(sector_t *sec, line_t *line, int which)
void MapLoader::AlignPlane(sector_t *sec, line_t *line, int which)
{
sector_t *refsec;
double bestdist;
vertex_t *refvert = sec->Lines[0]->v1; // Shut up, GCC
if (line->backsector == NULL)
if (line->backsector == nullptr)
return;
// Find furthest vertex from the reference line. It, along with the two ends
@ -515,11 +543,11 @@ static void P_AlignPlane(sector_t *sec, line_t *line, int which)
//
//===========================================================================
void P_SetSlopes ()
void MapLoader::SetSlopes ()
{
int s;
for (auto &line : level.lines)
for (auto &line : lines)
{
if (line.special == Plane_Align)
{
@ -538,9 +566,9 @@ void P_SetSlopes ()
bits = (line.args[0] >> 2) & 3;
if (bits == 1) // align front side to back
P_AlignPlane (line.frontsector, &line, s);
AlignPlane (line.frontsector, &line, s);
else if (bits == 2) // align back side to front
P_AlignPlane (line.backsector, &line, s);
AlignPlane (line.backsector, &line, s);
}
}
}
@ -553,9 +581,9 @@ void P_SetSlopes ()
//
//===========================================================================
void P_CopySlopes()
void MapLoader::CopySlopes()
{
for (auto &line : level.lines)
for (auto &line : lines)
{
if (line.special == Plane_Copy)
{
@ -569,11 +597,10 @@ void P_CopySlopes()
for (int s = 0; s < (line.backsector ? 4 : 2); s++)
{
if (line.args[s])
P_CopyPlane(line.args[s],
(s & 2 ? line.backsector : line.frontsector), s & 1);
CopyPlane(line.args[s], (s & 2 ? line.backsector : line.frontsector), s & 1);
}
if (line.backsector != NULL)
if (line.backsector != nullptr)
{
if ((line.args[4] & 3) == 1)
{

View file

@ -112,9 +112,6 @@
#define MISSING_TEXTURE_WARN_LIMIT 20
void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt, const int *oldvertextable);
void P_SetSlopes ();
void P_CopySlopes();
void BloodCrypt (void *data, int key, int len);
void P_ClearUDMFKeys();
void InitRenderInfo();
@ -988,6 +985,7 @@ void P_SetupLevel (const char *lumpname, int position, bool newGame)
FMissingTextureTracker missingtex;
times[0].Clock();
if (!map->isText)
{
maploader.LoadVertexes (map);
@ -998,13 +996,8 @@ void P_SetupLevel (const char *lumpname, int position, bool newGame)
else
maploader.LoadLineDefs2 (map); // [RH] Load Hexen-style linedefs
times[4].Clock();
maploader.LoadSideDefs2 (map, missingtex);
times[4].Unclock();
times[5].Clock();
maploader.FinishLoadingLineDefs ();
times[5].Unclock();
if (!map->HasBehavior)
P_LoadThings (map);
@ -1013,10 +1006,9 @@ void P_SetupLevel (const char *lumpname, int position, bool newGame)
}
else
{
times[0].Clock();
maploader.ParseTextMap(map, missingtex);
times[0].Unclock();
}
times[0].Unclock();
SetCompatibilityParams(checksum);
@ -1046,7 +1038,7 @@ void P_SetupLevel (const char *lumpname, int position, bool newGame)
times[12].Clock();
maploader.GroupLines (buildmap);
P_SetSlopes();
maploader.SetSlopes();
times[12].Unclock();
times[13].Clock();
@ -1069,8 +1061,8 @@ void P_SetupLevel (const char *lumpname, int position, bool newGame)
if (!buildmap)
{
// [RH] Spawn slope creating things first.
P_SpawnSlopeMakers (&MapThingsConverted[0], &MapThingsConverted[MapThingsConverted.Size()], maploader.oldvertextable);
P_CopySlopes();
maploader.SpawnSlopeMakers (&MapThingsConverted[0], &MapThingsConverted[MapThingsConverted.Size()], maploader.oldvertextable);
maploader.CopySlopes();
// Spawn 3d floors - must be done before spawning things so it can't be done in P_SpawnSpecials
P_Spawn3DFloors();

View file

@ -76,8 +76,10 @@ class FSectorTagIterator
protected:
int searchtag;
int start;
FTagManager &tagManager;
FSectorTagIterator()
: tagManager(::tagManager)
{
// For DSectorTagIterator
}
@ -104,12 +106,20 @@ protected:
public:
FSectorTagIterator(int tag)
:tagManager(::tagManager)
{
Init(tag);
}
FSectorTagIterator(FTagManager &tm, int tag)
:tagManager(tm)
{
Init(tag);
}
// Special constructor for actions that treat tag 0 as 'back of activation line'
FSectorTagIterator(int tag, line_t *line)
:tagManager(::tagManager)
{
Init(tag, line);
}
@ -123,9 +133,18 @@ class FLineIdIterator
protected:
int searchtag;
int start;
FTagManager &tagManager;
public:
FLineIdIterator(int id)
: tagManager(::tagManager)
{
searchtag = id;
start = tagManager.IDHashFirst[((unsigned int)id) % FTagManager::TAG_HASH_SIZE];
}
FLineIdIterator(FTagManager &tm, int id)
: tagManager(tm)
{
searchtag = id;
start = tagManager.IDHashFirst[((unsigned int)id) % FTagManager::TAG_HASH_SIZE];