From f864a09faa9cb208824299ebc4152a70f15e7baa Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 17 Mar 2017 12:49:43 +0100 Subject: [PATCH] - moved more varialbles into FLevelLocals. --- src/doomdata.h | 6 ------ src/g_doomedmap.cpp | 2 +- src/g_game.cpp | 42 ++++++++++++++++++++-------------------- src/g_levellocals.h | 8 ++++++++ src/p_effect.cpp | 2 +- src/p_local.h | 7 ------- src/p_mobj.cpp | 16 +++++++-------- src/p_saveg.cpp | 2 +- src/p_setup.cpp | 47 +++++++++++++++------------------------------ src/p_sight.cpp | 4 ++-- src/portal.cpp | 5 ++--- 11 files changed, 59 insertions(+), 82 deletions(-) diff --git a/src/doomdata.h b/src/doomdata.h index 0ce01bf6a4..2bcd271bdc 100644 --- a/src/doomdata.h +++ b/src/doomdata.h @@ -435,12 +435,6 @@ struct FPlayerStart type(pnum) { } }; -// Player spawn spots for deathmatch. -extern TArray deathmatchstarts; - -// Player spawn spots. -extern FPlayerStart playerstarts[MAXPLAYERS]; -extern TArray AllPlayerStarts; #endif // __DOOMDATA__ diff --git a/src/g_doomedmap.cpp b/src/g_doomedmap.cpp index 6d7ba6796f..2f3409ef2c 100644 --- a/src/g_doomedmap.cpp +++ b/src/g_doomedmap.cpp @@ -172,7 +172,7 @@ void FMapInfoParser::ParseDoomEdNums() defined[ednum] = true; if (sc.String[0] == '$') { - // todo: add special stuff like playerstarts and sound sequence overrides here, too. + // add special stuff like playerstarts and sound sequence overrides here, too. editem.classname = NAME_None; editem.special = sc.MustMatchString(SpecialMapthingNames) + 1; // todo: assign proper constants } diff --git a/src/g_game.cpp b/src/g_game.cpp index 06fd1db95f..92ccc65556 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -1546,12 +1546,12 @@ static FPlayerStart *SelectFarthestDeathmatchSpot (size_t selections) for (i = 0; i < selections; i++) { - double distance = PlayersRangeFromSpot (&deathmatchstarts[i]); + double distance = PlayersRangeFromSpot (&level.deathmatchstarts[i]); if (distance > bestdistance) { bestdistance = distance; - bestspot = &deathmatchstarts[i]; + bestspot = &level.deathmatchstarts[i]; } } @@ -1566,20 +1566,20 @@ static FPlayerStart *SelectRandomDeathmatchSpot (int playernum, unsigned int sel for (j = 0; j < 20; j++) { i = pr_dmspawn() % selections; - if (G_CheckSpot (playernum, &deathmatchstarts[i]) ) + if (G_CheckSpot (playernum, &level.deathmatchstarts[i]) ) { - return &deathmatchstarts[i]; + return &level.deathmatchstarts[i]; } } // [RH] return a spot anyway, since we allow telefragging when a player spawns - return &deathmatchstarts[i]; + return &level.deathmatchstarts[i]; } DEFINE_ACTION_FUNCTION(DObject, G_PickDeathmatchStart) { PARAM_PROLOGUE; - unsigned int selections = deathmatchstarts.Size(); + unsigned int selections = level.deathmatchstarts.Size(); DVector3 pos; int angle; if (selections == 0) @@ -1590,8 +1590,8 @@ DEFINE_ACTION_FUNCTION(DObject, G_PickDeathmatchStart) else { unsigned int i = pr_dmspawn() % selections; - angle = deathmatchstarts[i].angle; - pos = deathmatchstarts[i].pos; + angle = level.deathmatchstarts[i].angle; + pos = level.deathmatchstarts[i].pos; } if (numret > 1) @@ -1611,7 +1611,7 @@ void G_DeathMatchSpawnPlayer (int playernum) unsigned int selections; FPlayerStart *spot; - selections = deathmatchstarts.Size (); + selections = level.deathmatchstarts.Size (); // [RH] We can get by with just 1 deathmatch start if (selections < 1) I_Error ("No deathmatch starts"); @@ -1635,10 +1635,10 @@ void G_DeathMatchSpawnPlayer (int playernum) spot = SelectRandomDeathmatchSpot(playernum, selections); if (spot == NULL) { // We have a player 1 start, right? - spot = &playerstarts[0]; + spot = &level.playerstarts[0]; if (spot->type == 0) { // Fine, whatever. - spot = &deathmatchstarts[0]; + spot = &level.deathmatchstarts[0]; } } } @@ -1653,13 +1653,13 @@ void G_DeathMatchSpawnPlayer (int playernum) // FPlayerStart *G_PickPlayerStart(int playernum, int flags) { - if (AllPlayerStarts.Size() == 0) // No starts to pick + if (level.AllPlayerStarts.Size() == 0) // No starts to pick { return NULL; } if ((level.flags2 & LEVEL2_RANDOMPLAYERSTARTS) || (flags & PPS_FORCERANDOM) || - playerstarts[playernum].type == 0) + level.playerstarts[playernum].type == 0) { if (!(flags & PPS_NOBLOCKINGCHECK)) { @@ -1667,11 +1667,11 @@ FPlayerStart *G_PickPlayerStart(int playernum, int flags) unsigned int i; // Find all unblocked player starts. - for (i = 0; i < AllPlayerStarts.Size(); ++i) + for (i = 0; i < level.AllPlayerStarts.Size(); ++i) { - if (G_CheckSpot(playernum, &AllPlayerStarts[i])) + if (G_CheckSpot(playernum, &level.AllPlayerStarts[i])) { - good_starts.Push(&AllPlayerStarts[i]); + good_starts.Push(&level.AllPlayerStarts[i]); } } if (good_starts.Size() > 0) @@ -1680,9 +1680,9 @@ FPlayerStart *G_PickPlayerStart(int playernum, int flags) } } // Pick a spot at random, whether it's open or not. - return &AllPlayerStarts[pr_pspawn(AllPlayerStarts.Size())]; + return &level.AllPlayerStarts[pr_pspawn(level.AllPlayerStarts.Size())]; } - return &playerstarts[playernum]; + return &level.playerstarts[playernum]; } DEFINE_ACTION_FUNCTION(DObject, G_PickPlayerStart) @@ -1782,10 +1782,10 @@ void G_DoReborn (int playernum, bool freshbot) } if (!(level.flags2 & LEVEL2_RANDOMPLAYERSTARTS) && - playerstarts[playernum].type != 0 && - G_CheckSpot (playernum, &playerstarts[playernum])) + level.playerstarts[playernum].type != 0 && + G_CheckSpot (playernum, &level.playerstarts[playernum])) { - AActor *mo = P_SpawnPlayer(&playerstarts[playernum], playernum); + AActor *mo = P_SpawnPlayer(&level.playerstarts[playernum], playernum); if (mo != NULL) P_PlayerStartStomp(mo, true); } else diff --git a/src/g_levellocals.h b/src/g_levellocals.h index 433d8a3a4e..2deb98f94e 100644 --- a/src/g_levellocals.h +++ b/src/g_levellocals.h @@ -1,5 +1,6 @@ #pragma once +#include "doomdata.h" #include "g_level.h" #include "r_defs.h" #include "portal.h" @@ -31,6 +32,7 @@ struct FLevelLocals TArray vertexes; TArray sectors; + TArray linebuffer; // contains the line lists for the sectors. TArray lines; TArray sides; TArray segs; @@ -39,6 +41,7 @@ struct FLevelLocals TArray gamesubsectors; TArray gamenodes; node_t *headgamenode; + TArray rejectmatrix; TArray sectorPortals; TArray Zones; @@ -49,6 +52,11 @@ struct FLevelLocals TArray loadlines; TArray loadsides; + // Maintain single and multi player starting spots. + TArray deathmatchstarts; + FPlayerStart playerstarts[MAXPLAYERS]; + TArray AllPlayerStarts; + uint32_t flags; uint32_t flags2; diff --git a/src/p_effect.cpp b/src/p_effect.cpp index ba1b4552f8..95e215f555 100644 --- a/src/p_effect.cpp +++ b/src/p_effect.cpp @@ -362,7 +362,7 @@ void P_RunEffects () { // Only run the effect if the actor is potentially visible int rnum = pnum + actor->Sector->Index(); - if (rejectmatrix == NULL || !(rejectmatrix[rnum>>3] & (1 << (rnum & 7)))) + if (level.rejectmatrix.Size() > 0 || !(level.rejectmatrix[rnum>>3] & (1 << (rnum & 7)))) P_RunEffect (actor, actor->effects); } } diff --git a/src/p_local.h b/src/p_local.h index 098c9c4ff3..eb921ae96d 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -404,13 +404,6 @@ double P_GetFriction(const AActor *mo, double *frictionfactor); // [RH] const secplane_t * P_CheckSlopeWalk(AActor *actor, DVector2 &move); -// -// P_SETUP -// -extern uint8_t* rejectmatrix; // for fast sight rejection - - - // // P_INTER // diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index f45a2fc864..a95e1a4336 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -5690,7 +5690,7 @@ AActor *P_SpawnMapThing (FMapThing *mthing, int position) { // count deathmatch start positions FPlayerStart start(mthing, 0); - deathmatchstarts.Push(start); + level.deathmatchstarts.Push(start); return NULL; } @@ -5793,10 +5793,10 @@ AActor *P_SpawnMapThing (FMapThing *mthing, int position) // save spots for respawning in network games FPlayerStart start(mthing, pnum+1); - playerstarts[pnum] = start; + level.playerstarts[pnum] = start; if (level.flags2 & LEVEL2_RANDOMPLAYERSTARTS) { // When using random player starts, all starts count - AllPlayerStarts.Push(start); + level.AllPlayerStarts.Push(start); } else { // When not using random player starts, later single player @@ -5804,17 +5804,17 @@ AActor *P_SpawnMapThing (FMapThing *mthing, int position) // ones are for voodoo dolls and not likely to be ideal for // spawning regular players. unsigned i; - for (i = 0; i < AllPlayerStarts.Size(); ++i) + for (i = 0; i < level.AllPlayerStarts.Size(); ++i) { - if (AllPlayerStarts[i].type == pnum+1) + if (level.AllPlayerStarts[i].type == pnum+1) { - AllPlayerStarts[i] = start; + level.AllPlayerStarts[i] = start; break; } } - if (i == AllPlayerStarts.Size()) + if (i == level.AllPlayerStarts.Size()) { - AllPlayerStarts.Push(start); + level.AllPlayerStarts.Push(start); } } if (!deathmatch && !(level.flags2 & LEVEL2_RANDOMPLAYERSTARTS)) diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index 72d87855ac..523f004b25 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -903,7 +903,7 @@ static void SpawnExtraPlayers() if (playeringame[i] && players[i].mo == NULL) { players[i].playerstate = PST_ENTER; - P_SpawnPlayer(&playerstarts[i], i, (level.flags2 & LEVEL2_PRERAISEWEAPON) ? SPF_WEAPONFULLYUP : 0); + P_SpawnPlayer(&level.playerstarts[i], i, (level.flags2 & LEVEL2_PRERAISEWEAPON) ? SPF_WEAPONFULLYUP : 0); } } } diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 5c395e34b9..e334a272be 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -163,15 +163,9 @@ FBlockNode** blocklinks; // for thing chains // Without special effect, this could be // used as a PVS lookup as well. // -uint8_t* rejectmatrix; bool ForceNodeBuild; -// Maintain single and multi player starting spots. -TArray deathmatchstarts (16); -FPlayerStart playerstarts[MAXPLAYERS]; -TArray AllPlayerStarts; - static void P_AllocateSideDefs (MapData *map, int count); //=========================================================================== @@ -3035,9 +3029,7 @@ void P_LoadBlockMap (MapData * map) // P_GroupLines // Builds sector line lists and subsector sector numbers. // Finds block bounding boxes for sectors. -// [RH] Handles extra lights // -line_t** linebuffer; static void P_GroupLines (bool buildmap) { @@ -3104,8 +3096,8 @@ static void P_GroupLines (bool buildmap) // build line tables for each sector times[3].Clock(); - linebuffer = new line_t *[total]; - line_t **lineb_p = linebuffer; + level.linebuffer.Alloc(total); + line_t **lineb_p = &level.linebuffer[0]; auto numsectors = level.sectors.Size(); linesDoneInEachSector = new unsigned int[numsectors]; memset (linesDoneInEachSector, 0, sizeof(int)*numsectors); @@ -3220,23 +3212,23 @@ void P_LoadReject (MapData * map, bool junk) Printf ("REJECT is %d byte%s too small.\n", neededsize - rejectsize, neededsize-rejectsize==1?"":"s"); } - rejectmatrix = NULL; + level.rejectmatrix.Reset(); } else { // Check if the reject has some actual content. If not, free it. rejectsize = MIN (rejectsize, neededsize); - rejectmatrix = new uint8_t[rejectsize]; + level.rejectmatrix.Alloc(rejectsize); map->Seek(ML_REJECT); - map->file->Read (rejectmatrix, rejectsize); + map->file->Read (&level.rejectmatrix[0], rejectsize); int qwords = rejectsize / 8; int i; if (qwords > 0) { - const uint64_t *qreject = (const uint64_t *)rejectmatrix; + const uint64_t *qreject = (const uint64_t *)&level.rejectmatrix[0]; i = 0; do @@ -3249,13 +3241,12 @@ void P_LoadReject (MapData * map, bool junk) qwords *= 8; for (i = 0; i < rejectsize; ++i) { - if (rejectmatrix[qwords + i] != 0) + if (level.rejectmatrix[qwords + i] != 0) return; } // Reject has no data, so pretend it isn't there. - delete[] rejectmatrix; - rejectmatrix = NULL; + level.rejectmatrix.Reset(); } } @@ -3439,6 +3430,8 @@ void P_FreeLevelData () level.gamenodes.Reset(); level.subsectors.Clear(); level.gamesubsectors.Reset(); + level.rejectmatrix.Clear(); + level.Zones.Clear(); if (blockmaplump != NULL) { @@ -3465,23 +3458,17 @@ void P_FreeLevelData () delete[] PolyBlockMap; PolyBlockMap = NULL; } - if (rejectmatrix != NULL) - { - delete[] rejectmatrix; - rejectmatrix = NULL; - } - if (linebuffer != NULL) - { - delete[] linebuffer; - linebuffer = NULL; - } if (polyobjs != NULL) { delete[] polyobjs; polyobjs = NULL; } po_NumPolyobjs = 0; - level.Zones.Clear(); + + level.deathmatchstarts.Clear(); + level.AllPlayerStarts.Clear(); + memset(level.playerstarts, 0, sizeof(level.playerstarts)); + P_FreeStrifeConversations (); level.Scrolls.Clear(); P_ClearUDMFKeys(); @@ -3924,10 +3911,6 @@ void P_SetupLevel (const char *lumpname, int position) for (i = 0; i < BODYQUESIZE; i++) bodyque[i] = NULL; - deathmatchstarts.Clear(); - AllPlayerStarts.Clear(); - memset(playerstarts, 0, sizeof(playerstarts)); - if (!buildmap) { // [RH] Spawn slope creating things first. diff --git a/src/p_sight.cpp b/src/p_sight.cpp index d468d52a91..238a73ef25 100644 --- a/src/p_sight.cpp +++ b/src/p_sight.cpp @@ -847,8 +847,8 @@ bool P_CheckSight (AActor *t1, AActor *t2, int flags) // // check for trivial rejection // - if (rejectmatrix != NULL && - (rejectmatrix[pnum>>3] & (1 << (pnum & 7)))) + if (level.rejectmatrix.Size() > 0 && + (level.rejectmatrix[pnum>>3] & (1 << (pnum & 7)))) { sightcounts[0]++; res = false; // can't possibly be connected diff --git a/src/portal.cpp b/src/portal.cpp index 8880387357..15d012416c 100644 --- a/src/portal.cpp +++ b/src/portal.cpp @@ -1098,10 +1098,9 @@ void P_CreateLinkedPortals() } // reject would just get in the way when checking sight through portals. - if (Displacements.size > 1 && rejectmatrix != nullptr) + if (Displacements.size > 1) { - delete[] rejectmatrix; - rejectmatrix = nullptr; + level.rejectmatrix.Reset(); } // finally we must flag all planes which are obstructed by the sector's own ceiling or floor. for (auto &sec : level.sectors)