Permalink
Browse files

- added Level parameter to R/P_PointInSector(Sub)Sector.

  • Loading branch information...
coelckers committed Jan 9, 2019
1 parent a28d5dd commit 2aa9c065ac28955646937c41f592e3d3bdcd091f
@@ -2591,7 +2591,7 @@ void AM_drawWalls (bool allmap)
if (line.sidedef[0]->Flags & WALLF_POLYOBJ)
{
// For polyobjects we must test the surrounding sector to get the proper group.
pg = P_PointInSector(line.v1->fX() + line.Delta().X / 2, line.v1->fY() + line.Delta().Y / 2)->PortalGroup;
pg = P_PointInSector(line.GetLevel(), line.v1->fX() + line.Delta().X / 2, line.v1->fY() + line.Delta().Y / 2)->PortalGroup;
}
else
{
@@ -866,7 +866,7 @@ void FParser::SF_Spawn(void)
// [Graf Zahl] added option of spawning with a relative z coordinate
if(t_argc > 5)
{
if (intvalue(t_argv[5])) pos.Z += P_PointInSector(pos)->floorplane.ZatPoint(pos);
if (intvalue(t_argv[5])) pos.Z += P_PointInSector(Level, pos)->floorplane.ZatPoint(pos);
}
}
else
@@ -2928,7 +2928,7 @@ void FParser::SF_SpawnExplosion()
if(t_argc > 3)
pos.Z = floatvalue(t_argv[3]);
else
pos.Z = P_PointInSector(pos)->floorplane.ZatPoint(pos);
pos.Z = P_PointInSector(Level, pos)->floorplane.ZatPoint(pos);

spawn = Spawn (Level, pclass, pos, ALLOW_REPLACE);
t_return.type = svt_int;
@@ -1315,7 +1315,7 @@ void G_PlayerReborn (int player)
// because something is occupying it
//

bool G_CheckSpot (int playernum, FPlayerStart *mthing)
bool G_CheckSpot (FLevelLocals *Level, int playernum, FPlayerStart *mthing)
{
DVector3 spot;
double oldz;
@@ -1329,7 +1329,7 @@ bool G_CheckSpot (int playernum, FPlayerStart *mthing)
{
spot.Z = 0;
}
spot.Z += P_PointInSector (spot)->floorplane.ZatPoint (spot);
spot.Z += P_PointInSector (Level, spot)->floorplane.ZatPoint (spot);

if (!players[playernum].mo)
{ // first spawn of level, before corpses
@@ -1409,27 +1409,28 @@ static FPlayerStart *SelectFarthestDeathmatchSpot (size_t selections)
}

// [RH] Select a deathmatch spawn spot at random (original mechanism)
static FPlayerStart *SelectRandomDeathmatchSpot (int playernum, unsigned int selections)
static FPlayerStart *SelectRandomDeathmatchSpot (FLevelLocals *Level, int playernum, unsigned int selections)
{
unsigned int i, j;

for (j = 0; j < 20; j++)
{
i = pr_dmspawn() % selections;
if (G_CheckSpot (playernum, &level.deathmatchstarts[i]) )
if (G_CheckSpot (Level, playernum, &level.deathmatchstarts[i]) )
{
return &level.deathmatchstarts[i];
return &Level->deathmatchstarts[i];
}
}

// [RH] return a spot anyway, since we allow telefragging when a player spawns
return &level.deathmatchstarts[i];
return &Level->deathmatchstarts[i];
}

DEFINE_ACTION_FUNCTION(DObject, G_PickDeathmatchStart)
{
PARAM_PROLOGUE;
unsigned int selections = level.deathmatchstarts.Size();
auto Level = &level;
unsigned int selections = Level->deathmatchstarts.Size();
DVector3 pos;
int angle;
if (selections == 0)
@@ -1440,8 +1441,8 @@ DEFINE_ACTION_FUNCTION(DObject, G_PickDeathmatchStart)
else
{
unsigned int i = pr_dmspawn() % selections;
angle = level.deathmatchstarts[i].angle;
pos = level.deathmatchstarts[i].pos;
angle = Level->deathmatchstarts[i].angle;
pos = Level->deathmatchstarts[i].pos;
}

if (numret > 1)
@@ -1456,12 +1457,12 @@ DEFINE_ACTION_FUNCTION(DObject, G_PickDeathmatchStart)
return numret;
}

void G_DeathMatchSpawnPlayer (int playernum)
void G_DeathMatchSpawnPlayer (FLevelLocals *Level, int playernum)
{
unsigned int selections;
FPlayerStart *spot;

selections = level.deathmatchstarts.Size ();
selections = Level->deathmatchstarts.Size ();
// [RH] We can get by with just 1 deathmatch start
if (selections < 1)
I_Error ("No deathmatch starts");
@@ -1472,28 +1473,28 @@ void G_DeathMatchSpawnPlayer (int playernum)
if ((dmflags & DF_SPAWN_FARTHEST) && players[playernum].mo)
spot = SelectFarthestDeathmatchSpot (selections);
else
spot = SelectRandomDeathmatchSpot (playernum, selections);
spot = SelectRandomDeathmatchSpot (Level, playernum, selections);

if (spot == NULL)
{ // No good spot, so the player will probably get stuck.
// We were probably using select farthest above, and all
// the spots were taken.
spot = G_PickPlayerStart(playernum, PPS_FORCERANDOM);
if (!G_CheckSpot(playernum, spot))
if (!G_CheckSpot(&level, playernum, spot))
{ // This map doesn't have enough coop spots for this player
// to use one.
spot = SelectRandomDeathmatchSpot(playernum, selections);
spot = SelectRandomDeathmatchSpot(Level, playernum, selections);
if (spot == NULL)
{ // We have a player 1 start, right?
spot = &level.playerstarts[0];
if (spot->type == 0)
{ // Fine, whatever.
spot = &level.deathmatchstarts[0];
spot = &Level->deathmatchstarts[0];
}
}
}
}
AActor *mo = P_SpawnPlayer(&level, spot, playernum);
AActor *mo = P_SpawnPlayer(Level, spot, playernum);
if (mo != NULL) P_PlayerStartStomp(mo);
}

@@ -1519,7 +1520,7 @@ FPlayerStart *G_PickPlayerStart(int playernum, int flags)
// Find all unblocked player starts.
for (i = 0; i < level.AllPlayerStarts.Size(); ++i)
{
if (G_CheckSpot(playernum, &level.AllPlayerStarts[i]))
if (G_CheckSpot(&level, playernum, &level.AllPlayerStarts[i]))
{
good_starts.Push(&level.AllPlayerStarts[i]);
}
@@ -1630,13 +1631,13 @@ void G_DoReborn (int playernum, bool freshbot)
// spawn at random spot if in deathmatch
if ((deathmatch || isUnfriendly) && (level.deathmatchstarts.Size () > 0))
{
G_DeathMatchSpawnPlayer (playernum);
G_DeathMatchSpawnPlayer (&level, playernum);
return;
}

if (!(level.flags2 & LEVEL2_RANDOMPLAYERSTARTS) &&
level.playerstarts[playernum].type != 0 &&
G_CheckSpot (playernum, &level.playerstarts[playernum]))
G_CheckSpot (&level, playernum, &level.playerstarts[playernum]))
{
AActor *mo = P_SpawnPlayer(&level, &level.playerstarts[playernum], playernum);
if (mo != NULL) P_PlayerStartStomp(mo, true);
@@ -34,11 +34,12 @@ struct event_t;


class AActor;
struct FLevelLocals;

//
// GAME
//
void G_DeathMatchSpawnPlayer (int playernum);
void G_DeathMatchSpawnPlayer (FLevelLocals *Level, int playernum);

struct FPlayerStart *G_PickPlayerStart (int playernum, int flags = 0);
enum
@@ -2062,7 +2062,7 @@ void FLevelLocals::SetMusicVolume(float f)

int IsPointInMap(FLevelLocals *Level, double x, double y, double z)
{
subsector_t *subsector = R_PointInSubsector(FLOAT2FIXED(x), FLOAT2FIXED(y));
subsector_t *subsector = R_PointInSubsector(Level, FLOAT2FIXED(x), FLOAT2FIXED(y));
if (!subsector) return false;

for (uint32_t i = 0; i < subsector->numlines; i++)
@@ -2102,8 +2102,8 @@ inline T VecDiff(FLevelLocals *Level, const T& v1, const T& v2)

if (level.subsectors.Size() > 0)
{
const sector_t *const sec1 = P_PointInSector(v1);
const sector_t *const sec2 = P_PointInSector(v2);
const sector_t *const sec1 = P_PointInSector(Level, v1);
const sector_t *const sec2 = P_PointInSector(Level, v2);

if (nullptr != sec1 && nullptr != sec2)
{
@@ -591,7 +591,7 @@ void FDynamicLight::CollectWithinRadius(const DVector3 &opos, FSection *section,
line_t *other = port->mDestination;
if (other->validcount != ::validcount)
{
subsector_t *othersub = R_PointInSubsector(other->v1->fPos() + other->Delta() / 2);
subsector_t *othersub = R_PointInSubsector(Level, other->v1->fPos() + other->Delta() / 2);
FSection *othersect = othersub->section;
if (othersect->validcount != ::validcount)
{
@@ -642,7 +642,7 @@ void FDynamicLight::CollectWithinRadius(const DVector3 &opos, FSection *section,
if (sec->GetPortalPlaneZ(sector_t::ceiling) < Z() + radius)
{
DVector2 refpos = other->v1->fPos() + other->Delta() / 2 + sec->GetPortalDisplacement(sector_t::ceiling);
subsector_t *othersub = R_PointInSubsector(refpos);
subsector_t *othersub = R_PointInSubsector(Level, refpos);
FSection *othersect = othersub->section;
if (othersect->validcount != dl_validcount)
{
@@ -657,7 +657,7 @@ void FDynamicLight::CollectWithinRadius(const DVector3 &opos, FSection *section,
if (sec->GetPortalPlaneZ(sector_t::floor) > Z() - radius)
{
DVector2 refpos = other->v1->fPos() + other->Delta() / 2 + sec->GetPortalDisplacement(sector_t::floor);
subsector_t *othersub = R_PointInSubsector(refpos);
subsector_t *othersub = R_PointInSubsector(Level, refpos);
FSection *othersect = othersub->section;
if (othersect->validcount != dl_validcount)
{
@@ -697,7 +697,7 @@ void FDynamicLight::LinkLight()
if (radius>0)
{
// passing in radius*radius allows us to do a distance check without any calls to sqrt
FSection *sect = R_PointInSubsector(Pos)->section;
FSection *sect = R_PointInSubsector(Level, Pos)->section;

dl_validcount++;
::validcount++;
@@ -219,7 +219,7 @@ void HWDrawInfo::ClearBuffers()

void HWDrawInfo::UpdateCurrentMapSection()
{
const int mapsection = R_PointInSubsector(Viewpoint.Pos)->mapsection;
const int mapsection = R_PointInSubsector(Level, Viewpoint.Pos)->mapsection;
CurrentMapSections.Set(mapsection);
}

@@ -234,7 +234,7 @@ void HWDrawInfo::SetViewArea()
{
auto &vp = Viewpoint;
// The render_sector is better suited to represent the current position in GL
vp.sector = R_PointInSubsector(vp.Pos)->render_sector;
vp.sector = R_PointInSubsector(Level, vp.Pos)->render_sector;

// Get the heightsec state from the render sector, not the current one!
if (vp.sector->GetHeightSec())
@@ -648,7 +648,7 @@ void HWDrawInfo::ProcessScene(bool toscreen, const std::function<void(HWDrawInfo
{
screen->mPortalState->BeginScene();

int mapsection = R_PointInSubsector(Viewpoint.Pos)->mapsection;
int mapsection = R_PointInSubsector(Level, Viewpoint.Pos)->mapsection;
CurrentMapSections.Set(mapsection);
DrawScene = drawScene;
DrawScene(this, toscreen ? DM_MAINVIEW : DM_OFFSCREEN);
@@ -625,7 +625,7 @@ bool HWLineToLinePortal::Setup(HWDrawInfo *di, FRenderState &rstate, Clipper *cl
line_t *line = lines[i].seg->linedef->getPortalDestination();
subsector_t *sub;
if (line->sidedef[0]->Flags & WALLF_POLYOBJ)
sub = R_PointInSubsector(line->v1->fixX(), line->v1->fixY());
sub = R_PointInSubsector(di->Level, line->v1->fixX(), line->v1->fixY());
else sub = line->frontsector->subsectors[0];
di->CurrentMapSections.Set(sub->mapsection);
}
@@ -791,7 +791,7 @@ bool HWSectorStackPortal::Setup(HWDrawInfo *di, FRenderState &rstate, Clipper *c

// If the viewpoint is not within the portal, we need to invalidate the entire clip area.
// The portal will re-validate the necessary parts when its subsectors get traversed.
subsector_t *sub = R_PointInSubsector(vp.Pos);
subsector_t *sub = R_PointInSubsector(di->Level, vp.Pos);
if (!(di->ss_renderflags[sub->Index()] & SSRF_SEEN))
{
clipper->SafeAddClipRange(0, ANGLE_MAX);
@@ -1123,7 +1123,7 @@ void HWDrawInfo::ProcessLowerMinisegs(TArray<seg_t *> &lowersegs)

void HWDrawInfo::HandleHackedSubsectors()
{
viewsubsector = R_PointInSubsector(Viewpoint.Pos);
viewsubsector = R_PointInSubsector(Level, Viewpoint.Pos);

// Each subsector may only be processed once in this loop!
validcount++;
@@ -315,7 +315,7 @@ void MapLoader::TranslateToStartSpot (int tag, const DVector2 &origin)
}
po->CalcCenter();
// For compatibility purposes
po->CenterSubsector = R_PointInSubsector(po->CenterSpot.pos);
po->CenterSubsector = R_PointInSubsector(po->GetLevel(), po->CenterSpot.pos);
}

//==========================================================================
@@ -143,7 +143,7 @@ void MapLoader::CopyPlane (int tag, sector_t *dest, bool copyCeil)

void MapLoader::CopyPlane (int tag, const DVector2 &pos, bool copyCeil)
{
sector_t *dest = P_PointInSector (pos);
sector_t *dest = P_PointInSector (Level, pos);
CopyPlane(tag, dest, copyCeil);
}

@@ -389,7 +389,7 @@ void MapLoader::SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt, const i
sector_t *sec;
bool ceiling;

sec = P_PointInSector (mt->pos);
sec = P_PointInSector (Level, mt->pos);
if (mt->info->Special == SMT_SlopeCeilingPointLine || mt->info->Special == SMT_VavoomCeiling || mt->info->Special == SMT_SetCeilingSlope)
{
refplane = &sec->ceilingplane;
@@ -965,10 +965,6 @@ secplane_t P_FindFloorPlane(sector_t * sector, const DVector3 &pos)

int P_Find3DFloor(sector_t * sec, const DVector3 &pos, bool above, bool floor, double &cmpz)
{
// If no sector given, find the one appropriate
if (sec == NULL)
sec = P_PointInSector(pos);

// Above normal ceiling
cmpz = sec->ceilingplane.ZatPoint(pos);
if (pos.Z >= cmpz)
@@ -9470,7 +9470,7 @@ int DLevelScript::RunScript ()
if (tag != 0)
secnum = Level->tagManager.FindFirstSectorFromTag (tag);
else
secnum = P_PointInSector (x, y)->sectornum;
secnum = P_PointInSector (Level, x, y)->sectornum;

if (secnum >= 0)
{
@@ -295,7 +295,7 @@ DEFINE_ACTION_FUNCTION(AActor, GetZAt)
double c = angle.Cos();
pos = mobj->Vec2Offset(pos.X * c + pos.Y * s, pos.X * s - pos.Y * c);
}
sector_t *sec = P_PointInSector(pos);
sector_t *sec = P_PointInSector(mobj->Level, pos);

if (sec)
{
@@ -2290,7 +2290,7 @@ DEFINE_ACTION_FUNCTION(AActor, CheckLOF)
range
*/

sector_t *sec = P_PointInSector(pos);
sector_t *sec = P_PointInSector(self->Level, pos);

if (range == 0)
{
@@ -187,7 +187,7 @@ void P_FindParticleSubsectors ()
for (uint16_t i = ActiveParticles; i != NO_PARTICLE; i = Particles[i].tnext)
{
// Try to reuse the subsector from the last portal check, if still valid.
if (Particles[i].subsector == NULL) Particles[i].subsector = R_PointInSubsector(Particles[i].Pos);
if (Particles[i].subsector == NULL) Particles[i].subsector = R_PointInSubsector(&level, Particles[i].Pos);
int ssnum = Particles[i].subsector->Index();
Particles[i].snext = ParticlesInSubsec[ssnum];
ParticlesInSubsec[ssnum] = i;
@@ -270,8 +270,8 @@ void P_ThinkParticles ()
particle->Pos.Y = newxy.Y;
particle->Pos.Z += particle->Vel.Z;
particle->Vel += particle->Acc;
particle->subsector = R_PointInSubsector(particle->Pos);
sector_t *s = particle->subsector->sector;
particle->subsector = R_PointInSubsector(s->Level, particle->Pos);
// Handle crossing a sector portal.
if (!s->PortalBlocksMovement(sector_t::ceiling))
{
@@ -161,12 +161,12 @@ static void P_RecursiveSound(sector_t *sec, AActor *soundtarget, bool splash, AA
// I wish there was a better method to do this than randomly looking through the portal at a few places...
if (checkabove)
{
sector_t *upper = P_PointInSector(check->v1->fPos() + check->Delta() / 2 + sec->GetPortalDisplacement(sector_t::ceiling));
sector_t *upper = P_PointInSector(sec->Level, check->v1->fPos() + check->Delta() / 2 + sec->GetPortalDisplacement(sector_t::ceiling));
NoiseMarkSector(upper, soundtarget, splash, emitter, soundblocks, maxdist);
}
if (checkbelow)
{
sector_t *lower = P_PointInSector(check->v1->fPos() + check->Delta() / 2 + sec->GetPortalDisplacement(sector_t::floor));
sector_t *lower = P_PointInSector(sec->Level, check->v1->fPos() + check->Delta() / 2 + sec->GetPortalDisplacement(sector_t::floor));
NoiseMarkSector(lower, soundtarget, splash, emitter, soundblocks, maxdist);
}

Oops, something went wrong.

0 comments on commit 2aa9c06

Please sign in to comment.