- 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)
{ }
};
// Player spawn spots for deathmatch.
extern TArray<FPlayerStart> deathmatchstarts;
// Player spawn spots.
extern FPlayerStart playerstarts[MAXPLAYERS];
extern TArray<FPlayerStart> AllPlayerStarts;
#endif // __DOOMDATA__

View file

@ -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
}

View file

@ -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

View file

@ -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<vertex_t> vertexes;
TArray<sector_t> sectors;
TArray<line_t*> linebuffer; // contains the line lists for the sectors.
TArray<line_t> lines;
TArray<side_t> sides;
TArray<seg_t> segs;
@ -39,6 +41,7 @@ struct FLevelLocals
TArray<subsector_t> gamesubsectors;
TArray<node_t> gamenodes;
node_t *headgamenode;
TArray<uint8_t> rejectmatrix;
TArray<FSectorPortal> sectorPortals;
TArray<zone_t> Zones;
@ -49,6 +52,11 @@ struct FLevelLocals
TArray<line_t> loadlines;
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 flags2;

View file

@ -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);
}
}

View file

@ -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
//

View file

@ -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))

View file

@ -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);
}
}
}

View file

@ -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<FPlayerStart> deathmatchstarts (16);
FPlayerStart playerstarts[MAXPLAYERS];
TArray<FPlayerStart> 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.

View file

@ -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

View file

@ -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)