- made polyobject init code part of MapLoader.

This commit is contained in:
Christoph Oelckers 2018-12-28 14:48:10 +01:00
parent 326e4d8559
commit 9de2f5c1e7
3 changed files with 44 additions and 50 deletions

View file

@ -84,10 +84,14 @@ class MapLoader
int sidecount = 0; int sidecount = 0;
TArray<int> linemap; TArray<int> linemap;
// Extradata loader
TMap<int, EDLinedef> EDLines; TMap<int, EDLinedef> EDLines;
TMap<int, EDSector> EDSectors; TMap<int, EDSector> EDSectors;
TMap<int, EDMapthing> EDThings; TMap<int, EDMapthing> EDThings;
// Polyobject init
TArray<int32_t> KnownPolySides;
void SlopeLineToPoint(int lineid, const DVector3 &pos, bool slopeCeil); void SlopeLineToPoint(int lineid, const DVector3 &pos, bool slopeCeil);
void CopyPlane(int tag, sector_t *dest, bool copyCeil); void CopyPlane(int tag, sector_t *dest, bool copyCeil);
void CopyPlane(int tag, const DVector2 &pos, bool copyCeil); void CopyPlane(int tag, const DVector2 &pos, bool copyCeil);
@ -101,6 +105,12 @@ class MapLoader
void ProcessEDLinedef(line_t *line, int recordnum); void ProcessEDLinedef(line_t *line, int recordnum);
void ProcessEDSector(sector_t *sec, int recordnum); void ProcessEDSector(sector_t *sec, int recordnum);
void InitSideLists();
void IterFindPolySides(FPolyObj *po, side_t *side);
void SpawnPolyobj(int index, int tag, int type);
void TranslateToStartSpot(int tag, const DVector2 &origin);
void InitPolyBlockMap(void);
int checkGLVertex(int num); int checkGLVertex(int num);
int checkGLVertex3(int num); int checkGLVertex3(int num);
int CheckForMissingSegs(); int CheckForMissingSegs();

View file

@ -77,18 +77,23 @@ struct FBlockmap
void Clear() void Clear()
{ {
if (blockmaplump != NULL) if (blockmaplump != nullptr)
{ {
delete[] blockmaplump; delete[] blockmaplump;
blockmaplump = NULL; blockmaplump = nullptr;
} }
if (blocklinks != NULL) if (blocklinks != nullptr)
{ {
delete[] blocklinks; delete[] blocklinks;
blocklinks = NULL; blocklinks = nullptr;
} }
} }
~FBlockmap()
{
Clear();
}
}; };
#endif #endif

View file

@ -123,22 +123,13 @@ public:
FPolyObj *NextMirror(); FPolyObj *NextMirror();
}; };
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
void PO_Init (void);
// PRIVATE FUNCTION PROTOTYPES --------------------------------------------- // PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
static void UnLinkPolyobj (FPolyObj *po); static void UnLinkPolyobj (FPolyObj *po);
static void LinkPolyobj (FPolyObj *po); static void LinkPolyobj (FPolyObj *po);
static bool CheckMobjBlocking (side_t *seg, FPolyObj *po); static bool CheckMobjBlocking (side_t *seg, FPolyObj *po);
static void InitBlockMap (void);
static void IterFindPolySides (FPolyObj *po, side_t *side);
static void SpawnPolyobj (int index, int tag, int type); static void SpawnPolyobj (int index, int tag, int type);
static void TranslateToStartSpot (int tag, const DVector2 &origin);
static void DoMovePolyobj (FPolyObj *po, const DVector2 & move); static void DoMovePolyobj (FPolyObj *po, const DVector2 & move);
static void InitSegLists ();
static void KillSegLists ();
static FPolyNode *NewPolyNode(); static FPolyNode *NewPolyNode();
static void FreePolyNode(); static void FreePolyNode();
static void ReleaseAllPolyNodes(); static void ReleaseAllPolyNodes();
@ -151,7 +142,6 @@ polyblock_t **PolyBlockMap;
// PRIVATE DATA DEFINITIONS ------------------------------------------------ // PRIVATE DATA DEFINITIONS ------------------------------------------------
static TArray<int32_t> KnownPolySides;
static FPolyNode *FreePolyNodes; static FPolyNode *FreePolyNodes;
// CODE -------------------------------------------------------------------- // CODE --------------------------------------------------------------------
@ -1400,15 +1390,15 @@ void FPolyObj::ClosestPoint(const DVector2 &fpos, DVector2 &out, side_t **side)
// //
//========================================================================== //==========================================================================
static void InitBlockMap (void) void MapLoader::InitPolyBlockMap ()
{ {
int bmapwidth = level.blockmap.bmapwidth; int bmapwidth = Level->blockmap.bmapwidth;
int bmapheight = level.blockmap.bmapheight; int bmapheight = Level->blockmap.bmapheight;
PolyBlockMap = new polyblock_t *[bmapwidth*bmapheight]; PolyBlockMap = new polyblock_t *[bmapwidth*bmapheight];
memset (PolyBlockMap, 0, bmapwidth*bmapheight*sizeof(polyblock_t *)); memset (PolyBlockMap, 0, bmapwidth*bmapheight*sizeof(polyblock_t *));
for(auto &poly : level.Polyobjects) for(auto &poly : Level->Polyobjects)
{ {
poly.LinkPolyobj(); poly.LinkPolyobj();
} }
@ -1422,31 +1412,20 @@ static void InitBlockMap (void)
// polyobject so that they can be initialized fast. // polyobject so that they can be initialized fast.
//========================================================================== //==========================================================================
static void InitSideLists () void MapLoader::InitSideLists ()
{ {
for (unsigned i = 0; i < level.sides.Size(); ++i) auto &sides = Level->sides;
for (unsigned i = 0; i < sides.Size(); ++i)
{ {
if (level.sides[i].linedef != NULL && if (sides[i].linedef != NULL &&
(level.sides[i].linedef->special == Polyobj_StartLine || (sides[i].linedef->special == Polyobj_StartLine ||
level.sides[i].linedef->special == Polyobj_ExplicitLine)) sides[i].linedef->special == Polyobj_ExplicitLine))
{ {
KnownPolySides.Push (i); KnownPolySides.Push (i);
} }
} }
} }
//==========================================================================
//
// KillSideLists [RH]
//
//==========================================================================
static void KillSideLists ()
{
KnownPolySides.Clear ();
KnownPolySides.ShrinkToFit ();
}
//========================================================================== //==========================================================================
// //
// AddPolyVert // AddPolyVert
@ -1478,7 +1457,7 @@ static void AddPolyVert(TArray<uint32_t> &vnum, uint32_t vert)
// //
//========================================================================== //==========================================================================
static void IterFindPolySides (FPolyObj *po, side_t *side) void MapLoader::IterFindPolySides (FPolyObj *po, side_t *side)
{ {
static TArray<uint32_t> vnum; static TArray<uint32_t> vnum;
unsigned int vnumat; unsigned int vnumat;
@ -1494,8 +1473,8 @@ static void IterFindPolySides (FPolyObj *po, side_t *side)
uint32_t sidenum = sidetemp[vnum[vnumat++]].b.first; uint32_t sidenum = sidetemp[vnum[vnumat++]].b.first;
while (sidenum != NO_SIDE) while (sidenum != NO_SIDE)
{ {
po->Sidedefs.Push(&level.sides[sidenum]); po->Sidedefs.Push(&Level->sides[sidenum]);
AddPolyVert(vnum, uint32_t(level.sides[sidenum].V2()->Index())); AddPolyVert(vnum, uint32_t(Level->sides[sidenum].V2()->Index()));
sidenum = sidetemp[sidenum].b.next; sidenum = sidetemp[sidenum].b.next;
} }
} }
@ -1513,11 +1492,11 @@ static int posicmp(const void *a, const void *b)
return (*(const side_t **)a)->linedef->args[1] - (*(const side_t **)b)->linedef->args[1]; return (*(const side_t **)a)->linedef->args[1] - (*(const side_t **)b)->linedef->args[1];
} }
static void SpawnPolyobj (int index, int tag, int type) void MapLoader::SpawnPolyobj (int index, int tag, int type)
{ {
unsigned int ii; unsigned int ii;
int i; int i;
FPolyObj *po = &level.Polyobjects[index]; FPolyObj *po = &Level->Polyobjects[index];
for (ii = 0; ii < KnownPolySides.Size(); ++ii) for (ii = 0; ii < KnownPolySides.Size(); ++ii)
{ {
@ -1529,7 +1508,7 @@ static void SpawnPolyobj (int index, int tag, int type)
po->bBlocked = false; po->bBlocked = false;
po->bHasPortals = 0; po->bHasPortals = 0;
side_t *sd = &level.sides[i]; side_t *sd = &Level->sides[i];
if (sd->linedef->special == Polyobj_StartLine && if (sd->linedef->special == Polyobj_StartLine &&
sd->linedef->args[0] == tag) sd->linedef->args[0] == tag)
@ -1543,7 +1522,7 @@ static void SpawnPolyobj (int index, int tag, int type)
{ {
sd->linedef->special = 0; sd->linedef->special = 0;
sd->linedef->args[0] = 0; sd->linedef->args[0] = 0;
IterFindPolySides(&level.Polyobjects[index], sd); IterFindPolySides(&Level->Polyobjects[index], sd);
po->MirrorNum = sd->linedef->args[1]; po->MirrorNum = sd->linedef->args[1];
po->crush = (type != SMT_PolySpawn) ? 3 : 0; po->crush = (type != SMT_PolySpawn) ? 3 : 0;
po->bHurtOnTouch = (type == SMT_PolySpawnHurt); po->bHurtOnTouch = (type == SMT_PolySpawnHurt);
@ -1569,17 +1548,17 @@ static void SpawnPolyobj (int index, int tag, int type)
i = KnownPolySides[ii]; i = KnownPolySides[ii];
if (i >= 0 && if (i >= 0 &&
level.sides[i].linedef->special == Polyobj_ExplicitLine && Level->sides[i].linedef->special == Polyobj_ExplicitLine &&
level.sides[i].linedef->args[0] == tag) Level->sides[i].linedef->args[0] == tag)
{ {
if (!level.sides[i].linedef->args[1]) if (!Level->sides[i].linedef->args[1])
{ {
Printf(TEXTCOLOR_RED "SpawnPolyobj: Explicit line missing order number in poly %d, linedef %d.\n", tag, level.sides[i].linedef->Index()); Printf(TEXTCOLOR_RED "SpawnPolyobj: Explicit line missing order number in poly %d, linedef %d.\n", tag, Level->sides[i].linedef->Index());
return; return;
} }
else else
{ {
po->Sidedefs.Push(&level.sides[i]); po->Sidedefs.Push(&Level->sides[i]);
} }
} }
} }
@ -1643,7 +1622,7 @@ static void SpawnPolyobj (int index, int tag, int type)
// //
//========================================================================== //==========================================================================
static void TranslateToStartSpot (int tag, const DVector2 &origin) void MapLoader::TranslateToStartSpot (int tag, const DVector2 &origin)
{ {
FPolyObj *po; FPolyObj *po;
DVector2 delta; DVector2 delta;
@ -1750,10 +1729,10 @@ void MapLoader::PO_Init (void)
Printf (TEXTCOLOR_RED "PO_Init: StartSpot located without an Anchor point: %d\n", poly.tag); Printf (TEXTCOLOR_RED "PO_Init: StartSpot located without an Anchor point: %d\n", poly.tag);
} }
} }
InitBlockMap(); InitPolyBlockMap();
// [RH] Don't need the side lists anymore // [RH] Don't need the side lists anymore
KillSideLists (); KnownPolySides.Reset();
// mark all subsectors which have a seg belonging to a polyobj // mark all subsectors which have a seg belonging to a polyobj
// These ones should not be rendered on the textured automap. // These ones should not be rendered on the textured automap.