- moved more varialbles into FLevelLocals.

This commit is contained in:
Christoph Oelckers 2017-03-17 12:49:43 +01:00
parent ea1d6634f7
commit f864a09faa
11 changed files with 59 additions and 82 deletions

View File

@ -435,12 +435,6 @@ struct FPlayerStart
type(pnum) type(pnum)
{ } { }
}; };
// Player spawn spots for deathmatch.
extern TArray<FPlayerStart> deathmatchstarts;
// Player spawn spots.
extern FPlayerStart playerstarts[MAXPLAYERS];
extern TArray<FPlayerStart> AllPlayerStarts;
#endif // __DOOMDATA__ #endif // __DOOMDATA__

View File

@ -172,7 +172,7 @@ void FMapInfoParser::ParseDoomEdNums()
defined[ednum] = true; defined[ednum] = true;
if (sc.String[0] == '$') 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.classname = NAME_None;
editem.special = sc.MustMatchString(SpecialMapthingNames) + 1; // todo: assign proper constants editem.special = sc.MustMatchString(SpecialMapthingNames) + 1; // todo: assign proper constants
} }

View File

@ -1546,12 +1546,12 @@ static FPlayerStart *SelectFarthestDeathmatchSpot (size_t selections)
for (i = 0; i < selections; i++) for (i = 0; i < selections; i++)
{ {
double distance = PlayersRangeFromSpot (&deathmatchstarts[i]); double distance = PlayersRangeFromSpot (&level.deathmatchstarts[i]);
if (distance > bestdistance) if (distance > bestdistance)
{ {
bestdistance = distance; 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++) for (j = 0; j < 20; j++)
{ {
i = pr_dmspawn() % selections; 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 // [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) DEFINE_ACTION_FUNCTION(DObject, G_PickDeathmatchStart)
{ {
PARAM_PROLOGUE; PARAM_PROLOGUE;
unsigned int selections = deathmatchstarts.Size(); unsigned int selections = level.deathmatchstarts.Size();
DVector3 pos; DVector3 pos;
int angle; int angle;
if (selections == 0) if (selections == 0)
@ -1590,8 +1590,8 @@ DEFINE_ACTION_FUNCTION(DObject, G_PickDeathmatchStart)
else else
{ {
unsigned int i = pr_dmspawn() % selections; unsigned int i = pr_dmspawn() % selections;
angle = deathmatchstarts[i].angle; angle = level.deathmatchstarts[i].angle;
pos = deathmatchstarts[i].pos; pos = level.deathmatchstarts[i].pos;
} }
if (numret > 1) if (numret > 1)
@ -1611,7 +1611,7 @@ void G_DeathMatchSpawnPlayer (int playernum)
unsigned int selections; unsigned int selections;
FPlayerStart *spot; FPlayerStart *spot;
selections = deathmatchstarts.Size (); selections = level.deathmatchstarts.Size ();
// [RH] We can get by with just 1 deathmatch start // [RH] We can get by with just 1 deathmatch start
if (selections < 1) if (selections < 1)
I_Error ("No deathmatch starts"); I_Error ("No deathmatch starts");
@ -1635,10 +1635,10 @@ void G_DeathMatchSpawnPlayer (int playernum)
spot = SelectRandomDeathmatchSpot(playernum, selections); spot = SelectRandomDeathmatchSpot(playernum, selections);
if (spot == NULL) if (spot == NULL)
{ // We have a player 1 start, right? { // We have a player 1 start, right?
spot = &playerstarts[0]; spot = &level.playerstarts[0];
if (spot->type == 0) if (spot->type == 0)
{ // Fine, whatever. { // 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) 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; return NULL;
} }
if ((level.flags2 & LEVEL2_RANDOMPLAYERSTARTS) || (flags & PPS_FORCERANDOM) || if ((level.flags2 & LEVEL2_RANDOMPLAYERSTARTS) || (flags & PPS_FORCERANDOM) ||
playerstarts[playernum].type == 0) level.playerstarts[playernum].type == 0)
{ {
if (!(flags & PPS_NOBLOCKINGCHECK)) if (!(flags & PPS_NOBLOCKINGCHECK))
{ {
@ -1667,11 +1667,11 @@ FPlayerStart *G_PickPlayerStart(int playernum, int flags)
unsigned int i; unsigned int i;
// Find all unblocked player starts. // 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) 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. // 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) DEFINE_ACTION_FUNCTION(DObject, G_PickPlayerStart)
@ -1782,10 +1782,10 @@ void G_DoReborn (int playernum, bool freshbot)
} }
if (!(level.flags2 & LEVEL2_RANDOMPLAYERSTARTS) && if (!(level.flags2 & LEVEL2_RANDOMPLAYERSTARTS) &&
playerstarts[playernum].type != 0 && level.playerstarts[playernum].type != 0 &&
G_CheckSpot (playernum, &playerstarts[playernum])) 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); if (mo != NULL) P_PlayerStartStomp(mo, true);
} }
else else

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include "doomdata.h"
#include "g_level.h" #include "g_level.h"
#include "r_defs.h" #include "r_defs.h"
#include "portal.h" #include "portal.h"
@ -31,6 +32,7 @@ struct FLevelLocals
TArray<vertex_t> vertexes; TArray<vertex_t> vertexes;
TArray<sector_t> sectors; TArray<sector_t> sectors;
TArray<line_t*> linebuffer; // contains the line lists for the sectors.
TArray<line_t> lines; TArray<line_t> lines;
TArray<side_t> sides; TArray<side_t> sides;
TArray<seg_t> segs; TArray<seg_t> segs;
@ -39,6 +41,7 @@ struct FLevelLocals
TArray<subsector_t> gamesubsectors; TArray<subsector_t> gamesubsectors;
TArray<node_t> gamenodes; TArray<node_t> gamenodes;
node_t *headgamenode; node_t *headgamenode;
TArray<uint8_t> rejectmatrix;
TArray<FSectorPortal> sectorPortals; TArray<FSectorPortal> sectorPortals;
TArray<zone_t> Zones; TArray<zone_t> Zones;
@ -49,6 +52,11 @@ struct FLevelLocals
TArray<line_t> loadlines; TArray<line_t> loadlines;
TArray<side_t> loadsides; TArray<side_t> loadsides;
// Maintain single and multi player starting spots.
TArray<FPlayerStart> deathmatchstarts;
FPlayerStart playerstarts[MAXPLAYERS];
TArray<FPlayerStart> AllPlayerStarts;
uint32_t flags; uint32_t flags;
uint32_t flags2; uint32_t flags2;

View File

@ -362,7 +362,7 @@ void P_RunEffects ()
{ {
// Only run the effect if the actor is potentially visible // Only run the effect if the actor is potentially visible
int rnum = pnum + actor->Sector->Index(); 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); P_RunEffect (actor, actor->effects);
} }
} }

View File

@ -404,13 +404,6 @@ double P_GetFriction(const AActor *mo, double *frictionfactor);
// [RH] // [RH]
const secplane_t * P_CheckSlopeWalk(AActor *actor, DVector2 &move); const secplane_t * P_CheckSlopeWalk(AActor *actor, DVector2 &move);
//
// P_SETUP
//
extern uint8_t* rejectmatrix; // for fast sight rejection
// //
// P_INTER // P_INTER
// //

View File

@ -5690,7 +5690,7 @@ AActor *P_SpawnMapThing (FMapThing *mthing, int position)
{ {
// count deathmatch start positions // count deathmatch start positions
FPlayerStart start(mthing, 0); FPlayerStart start(mthing, 0);
deathmatchstarts.Push(start); level.deathmatchstarts.Push(start);
return NULL; return NULL;
} }
@ -5793,10 +5793,10 @@ AActor *P_SpawnMapThing (FMapThing *mthing, int position)
// save spots for respawning in network games // save spots for respawning in network games
FPlayerStart start(mthing, pnum+1); FPlayerStart start(mthing, pnum+1);
playerstarts[pnum] = start; level.playerstarts[pnum] = start;
if (level.flags2 & LEVEL2_RANDOMPLAYERSTARTS) if (level.flags2 & LEVEL2_RANDOMPLAYERSTARTS)
{ // When using random player starts, all starts count { // When using random player starts, all starts count
AllPlayerStarts.Push(start); level.AllPlayerStarts.Push(start);
} }
else else
{ // When not using random player starts, later single player { // 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 // ones are for voodoo dolls and not likely to be ideal for
// spawning regular players. // spawning regular players.
unsigned i; 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; break;
} }
} }
if (i == AllPlayerStarts.Size()) if (i == level.AllPlayerStarts.Size())
{ {
AllPlayerStarts.Push(start); level.AllPlayerStarts.Push(start);
} }
} }
if (!deathmatch && !(level.flags2 & LEVEL2_RANDOMPLAYERSTARTS)) if (!deathmatch && !(level.flags2 & LEVEL2_RANDOMPLAYERSTARTS))

View File

@ -903,7 +903,7 @@ static void SpawnExtraPlayers()
if (playeringame[i] && players[i].mo == NULL) if (playeringame[i] && players[i].mo == NULL)
{ {
players[i].playerstate = PST_ENTER; 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);
} }
} }
} }

View File

@ -163,15 +163,9 @@ FBlockNode** blocklinks; // for thing chains
// Without special effect, this could be // Without special effect, this could be
// used as a PVS lookup as well. // used as a PVS lookup as well.
// //
uint8_t* rejectmatrix;
bool ForceNodeBuild; bool ForceNodeBuild;
// Maintain single and multi player starting spots.
TArray<FPlayerStart> deathmatchstarts (16);
FPlayerStart playerstarts[MAXPLAYERS];
TArray<FPlayerStart> AllPlayerStarts;
static void P_AllocateSideDefs (MapData *map, int count); static void P_AllocateSideDefs (MapData *map, int count);
//=========================================================================== //===========================================================================
@ -3035,9 +3029,7 @@ void P_LoadBlockMap (MapData * map)
// P_GroupLines // P_GroupLines
// Builds sector line lists and subsector sector numbers. // Builds sector line lists and subsector sector numbers.
// Finds block bounding boxes for sectors. // Finds block bounding boxes for sectors.
// [RH] Handles extra lights
// //
line_t** linebuffer;
static void P_GroupLines (bool buildmap) static void P_GroupLines (bool buildmap)
{ {
@ -3104,8 +3096,8 @@ static void P_GroupLines (bool buildmap)
// build line tables for each sector // build line tables for each sector
times[3].Clock(); times[3].Clock();
linebuffer = new line_t *[total]; level.linebuffer.Alloc(total);
line_t **lineb_p = linebuffer; line_t **lineb_p = &level.linebuffer[0];
auto numsectors = level.sectors.Size(); auto numsectors = level.sectors.Size();
linesDoneInEachSector = new unsigned int[numsectors]; linesDoneInEachSector = new unsigned int[numsectors];
memset (linesDoneInEachSector, 0, sizeof(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, Printf ("REJECT is %d byte%s too small.\n", neededsize - rejectsize,
neededsize-rejectsize==1?"":"s"); neededsize-rejectsize==1?"":"s");
} }
rejectmatrix = NULL; level.rejectmatrix.Reset();
} }
else else
{ {
// Check if the reject has some actual content. If not, free it. // Check if the reject has some actual content. If not, free it.
rejectsize = MIN (rejectsize, neededsize); rejectsize = MIN (rejectsize, neededsize);
rejectmatrix = new uint8_t[rejectsize]; level.rejectmatrix.Alloc(rejectsize);
map->Seek(ML_REJECT); map->Seek(ML_REJECT);
map->file->Read (rejectmatrix, rejectsize); map->file->Read (&level.rejectmatrix[0], rejectsize);
int qwords = rejectsize / 8; int qwords = rejectsize / 8;
int i; int i;
if (qwords > 0) if (qwords > 0)
{ {
const uint64_t *qreject = (const uint64_t *)rejectmatrix; const uint64_t *qreject = (const uint64_t *)&level.rejectmatrix[0];
i = 0; i = 0;
do do
@ -3249,13 +3241,12 @@ void P_LoadReject (MapData * map, bool junk)
qwords *= 8; qwords *= 8;
for (i = 0; i < rejectsize; ++i) for (i = 0; i < rejectsize; ++i)
{ {
if (rejectmatrix[qwords + i] != 0) if (level.rejectmatrix[qwords + i] != 0)
return; return;
} }
// Reject has no data, so pretend it isn't there. // Reject has no data, so pretend it isn't there.
delete[] rejectmatrix; level.rejectmatrix.Reset();
rejectmatrix = NULL;
} }
} }
@ -3439,6 +3430,8 @@ void P_FreeLevelData ()
level.gamenodes.Reset(); level.gamenodes.Reset();
level.subsectors.Clear(); level.subsectors.Clear();
level.gamesubsectors.Reset(); level.gamesubsectors.Reset();
level.rejectmatrix.Clear();
level.Zones.Clear();
if (blockmaplump != NULL) if (blockmaplump != NULL)
{ {
@ -3465,23 +3458,17 @@ void P_FreeLevelData ()
delete[] PolyBlockMap; delete[] PolyBlockMap;
PolyBlockMap = NULL; PolyBlockMap = NULL;
} }
if (rejectmatrix != NULL)
{
delete[] rejectmatrix;
rejectmatrix = NULL;
}
if (linebuffer != NULL)
{
delete[] linebuffer;
linebuffer = NULL;
}
if (polyobjs != NULL) if (polyobjs != NULL)
{ {
delete[] polyobjs; delete[] polyobjs;
polyobjs = NULL; polyobjs = NULL;
} }
po_NumPolyobjs = 0; po_NumPolyobjs = 0;
level.Zones.Clear();
level.deathmatchstarts.Clear();
level.AllPlayerStarts.Clear();
memset(level.playerstarts, 0, sizeof(level.playerstarts));
P_FreeStrifeConversations (); P_FreeStrifeConversations ();
level.Scrolls.Clear(); level.Scrolls.Clear();
P_ClearUDMFKeys(); P_ClearUDMFKeys();
@ -3924,10 +3911,6 @@ void P_SetupLevel (const char *lumpname, int position)
for (i = 0; i < BODYQUESIZE; i++) for (i = 0; i < BODYQUESIZE; i++)
bodyque[i] = NULL; bodyque[i] = NULL;
deathmatchstarts.Clear();
AllPlayerStarts.Clear();
memset(playerstarts, 0, sizeof(playerstarts));
if (!buildmap) if (!buildmap)
{ {
// [RH] Spawn slope creating things first. // [RH] Spawn slope creating things first.

View File

@ -847,8 +847,8 @@ bool P_CheckSight (AActor *t1, AActor *t2, int flags)
// //
// check for trivial rejection // check for trivial rejection
// //
if (rejectmatrix != NULL && if (level.rejectmatrix.Size() > 0 &&
(rejectmatrix[pnum>>3] & (1 << (pnum & 7)))) (level.rejectmatrix[pnum>>3] & (1 << (pnum & 7))))
{ {
sightcounts[0]++; sightcounts[0]++;
res = false; // can't possibly be connected res = false; // can't possibly be connected

View File

@ -1098,10 +1098,9 @@ void P_CreateLinkedPortals()
} }
// reject would just get in the way when checking sight through portals. // reject would just get in the way when checking sight through portals.
if (Displacements.size > 1 && rejectmatrix != nullptr) if (Displacements.size > 1)
{ {
delete[] rejectmatrix; level.rejectmatrix.Reset();
rejectmatrix = nullptr;
} }
// finally we must flag all planes which are obstructed by the sector's own ceiling or floor. // finally we must flag all planes which are obstructed by the sector's own ceiling or floor.
for (auto &sec : level.sectors) for (auto &sec : level.sectors)