diff --git a/src/fragglescript/t_func.cpp b/src/fragglescript/t_func.cpp index 8ab237e8b5..d654c5f3f3 100644 --- a/src/fragglescript/t_func.cpp +++ b/src/fragglescript/t_func.cpp @@ -1067,7 +1067,7 @@ void FParser::SF_Teleport(void) } if(mo) - EV_Teleport(0, tag, NULL, 0, mo, TELF_DESTFOG | TELF_SOURCEFOG); + EV_Teleport(Level, 0, tag, NULL, 0, mo, TELF_DESTFOG | TELF_SOURCEFOG); } } @@ -1096,7 +1096,7 @@ void FParser::SF_SilentTeleport(void) } if(mo) - EV_Teleport(0, tag, NULL, 0, mo, TELF_KEEPORIENTATION); + EV_Teleport(Level, 0, tag, NULL, 0, mo, TELF_KEEPORIENTATION); } } diff --git a/src/g_level.cpp b/src/g_level.cpp index 9539dddb66..486e242ea0 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -1947,20 +1947,6 @@ void P_ReadACSDefereds (FSerializer &arc) } -//========================================================================== -// -// -//========================================================================== - -void FLevelLocals::Tick () -{ - // Reset carry sectors - if (Scrolls.Size() > 0) - { - memset (&Scrolls[0], 0, sizeof(Scrolls[0])*Scrolls.Size()); - } -} - //========================================================================== // // diff --git a/src/p_lnspec.cpp b/src/p_lnspec.cpp index b7dbf1926e..bf3a27333a 100644 --- a/src/p_lnspec.cpp +++ b/src/p_lnspec.cpp @@ -1103,7 +1103,7 @@ FUNC(LS_Teleport) { flags |= TELF_SOURCEFOG; } - return EV_Teleport (arg0, arg1, ln, backSide, it, flags); + return EV_Teleport (Level, arg0, arg1, ln, backSide, it, flags); } FUNC( LS_Teleport_NoStop ) @@ -1114,7 +1114,7 @@ FUNC( LS_Teleport_NoStop ) { flags |= TELF_SOURCEFOG; } - return EV_Teleport( arg0, arg1, ln, backSide, it, flags); + return EV_Teleport(Level, arg0, arg1, ln, backSide, it, flags); } FUNC(LS_Teleport_NoFog) @@ -1144,7 +1144,7 @@ FUNC(LS_Teleport_NoFog) { flags |= TELF_KEEPHEIGHT; } - return EV_Teleport (arg0, arg2, ln, backSide, it, flags); + return EV_Teleport (Level, arg0, arg2, ln, backSide, it, flags); } FUNC(LS_Teleport_ZombieChanger) @@ -1153,7 +1153,7 @@ FUNC(LS_Teleport_ZombieChanger) // This is practically useless outside of Strife, but oh well. if (it != NULL) { - EV_Teleport (arg0, arg1, ln, backSide, it, 0); + EV_Teleport (Level, arg0, arg1, ln, backSide, it, 0); if (it->health >= 0) it->SetState (it->FindState(NAME_Pain)); return true; } @@ -1163,19 +1163,19 @@ FUNC(LS_Teleport_ZombieChanger) FUNC(LS_TeleportOther) // TeleportOther (other_tid, dest_tid, fog?) { - return EV_TeleportOther (arg0, arg1, arg2?true:false); + return EV_TeleportOther (Level, arg0, arg1, arg2?true:false); } FUNC(LS_TeleportGroup) // TeleportGroup (group_tid, source_tid, dest_tid, move_source?, fog?) { - return EV_TeleportGroup (arg0, it, arg1, arg2, arg3?true:false, arg4?true:false); + return EV_TeleportGroup (Level, arg0, it, arg1, arg2, arg3?true:false, arg4?true:false); } FUNC(LS_TeleportInSector) // TeleportInSector (tag, source_tid, dest_tid, bFog, group_tid) { - return EV_TeleportSector (arg0, arg1, arg2, arg3?true:false, arg4); + return EV_TeleportSector (Level, arg0, arg1, arg2, arg3?true:false, arg4); } FUNC(LS_Teleport_EndGame) diff --git a/src/p_pspr.cpp b/src/p_pspr.cpp index 5b5881940f..2275af64ea 100644 --- a/src/p_pspr.cpp +++ b/src/p_pspr.cpp @@ -966,7 +966,7 @@ DAngle P_BulletSlope (AActor *mo, FTranslatedLineTarget *pLineTarget, int aimfla pitch = P_AimLineAttack (mo, an, 16.*64, pLineTarget, 0., aimflags); if (mo->player != NULL && - level.IsFreelookAllowed() && + mo->__GetLevel()->IsFreelookAllowed() && mo->player->userinfo.GetAimDist() <= 0.5) { break; diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index 91d188ffd0..92d4ffc68a 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -331,9 +331,9 @@ FSerializer &Serialize(FSerializer &arc, const char *key, sector_t &p, sector_t // //========================================================================== -void RecalculateDrawnSubsectors() +void RecalculateDrawnSubsectors(FLevelLocals *Level) { - for (auto &sub : level.subsectors) + for (auto &sub : Level->subsectors) { for (unsigned int j = 0; jsubsectors.Size(); if (arc.isWriting()) { TArray encoded(1 + (numsubsectors + 5) / 6); @@ -367,7 +367,7 @@ FSerializer &SerializeSubsectors(FSerializer &arc, const char *key) by = 0; for (unsigned j = 0; j < 6; j++) { - if (i + j < numsubsectors && (level.subsectors[i + j].flags & SSECMF_DRAWN)) + if (i + j < numsubsectors && (Level->subsectors[i + j].flags & SSECMF_DRAWN)) { by |= (1 << j); } @@ -383,7 +383,7 @@ FSerializer &SerializeSubsectors(FSerializer &arc, const char *key) str = &encoded[0]; if (arc.BeginArray(key)) { - auto numvertexes = level.vertexes.Size(); + auto numvertexes = Level->vertexes.Size(); arc(nullptr, numvertexes) (nullptr, numsubsectors) .StringPtr(nullptr, str) @@ -401,7 +401,7 @@ FSerializer &SerializeSubsectors(FSerializer &arc, const char *key) .StringPtr(nullptr, str) .EndArray(); - if (num_verts == (int)level.vertexes.Size() && num_subs == (int)numsubsectors) + if (num_verts == (int)Level->vertexes.Size() && num_subs == (int)numsubsectors) { success = true; int sub = 0; @@ -422,7 +422,7 @@ FSerializer &SerializeSubsectors(FSerializer &arc, const char *key) { if (sub + s < (int)numsubsectors && (by & (1 << s))) { - level.subsectors[sub + s].flags |= SSECMF_DRAWN; + Level->subsectors[sub + s].flags |= SSECMF_DRAWN; } } sub += 6; @@ -430,7 +430,7 @@ FSerializer &SerializeSubsectors(FSerializer &arc, const char *key) } if (!success) { - RecalculateDrawnSubsectors(); + RecalculateDrawnSubsectors(Level); } } @@ -1012,7 +1012,7 @@ void G_SerializeLevel(FSerializer &arc, FLevelLocals *Level, bool hubload) E_SerializeEvents(arc); DThinker::SerializeThinkers(arc, hubload); arc("polyobjs", Level->Polyobjects); - SerializeSubsectors(arc, "subsectors"); + SerializeSubsectors(arc, Level, "subsectors"); StatusBar->SerializeMessages(arc); AM_SerializeMarkers(arc); FRemapTable::StaticSerializeTranslations(arc); diff --git a/src/p_secnodes.cpp b/src/p_secnodes.cpp index c251ca92a7..8ee0afce9d 100644 --- a/src/p_secnodes.cpp +++ b/src/p_secnodes.cpp @@ -468,7 +468,7 @@ FBlockNode *FBlockNode::Create(AActor *who, int x, int y, int group) { block = (FBlockNode *)secnodearena.Alloc(sizeof(FBlockNode)); } - block->BlockIndex = x + y * level.blockmap.bmapwidth; + block->BlockIndex = x + y * who->__GetLevel()->blockmap.bmapwidth; block->Me = who; block->NextActor = nullptr; block->PrevActor = nullptr; diff --git a/src/p_sectors.cpp b/src/p_sectors.cpp index 58aa8d80c3..4b4a919178 100644 --- a/src/p_sectors.cpp +++ b/src/p_sectors.cpp @@ -1530,7 +1530,7 @@ int side_t::GetLightLevel (bool foggy, int baselight, bool is3dlight, int *pfake } auto Level = sector->Level; - if (!foggy || level.flags3 & LEVEL3_FORCEFAKECONTRAST) // Don't do relative lighting in foggy sectors + if (!foggy || Level->flags3 & LEVEL3_FORCEFAKECONTRAST) // Don't do relative lighting in foggy sectors { if (!(Flags & WALLF_NOFAKECONTRAST) && r_fakecontrast != 0) { diff --git a/src/p_spec.cpp b/src/p_spec.cpp index 2a85b49526..1ba52f9984 100644 --- a/src/p_spec.cpp +++ b/src/p_spec.cpp @@ -1489,7 +1489,7 @@ void P_SpawnSpecials (MapLoader *ml) } } // [RH] Start running any open scripts on this map - level.Behaviors.StartTypedScripts (SCRIPT_Open, NULL, false); + Level->Behaviors.StartTypedScripts (SCRIPT_Open, NULL, false); } //////////////////////////////////////////////////////////////////////////// diff --git a/src/p_spec.h b/src/p_spec.h index 6243ab649b..32362dca3b 100644 --- a/src/p_spec.h +++ b/src/p_spec.h @@ -688,11 +688,11 @@ enum void P_SpawnTeleportFog(AActor *mobj, const DVector3 &pos, bool beforeTele = true, bool setTarget = false); bool P_Teleport(AActor *thing, DVector3 pos, DAngle angle, int flags); -bool EV_Teleport (int tid, int tag, line_t *line, int side, AActor *thing, int flags); +bool EV_Teleport (FLevelLocals *Level, int tid, int tag, line_t *line, int side, AActor *thing, int flags); bool EV_SilentLineTeleport (line_t *line, int side, AActor *thing, int id, INTBOOL reverse); -bool EV_TeleportOther (int other_tid, int dest_tid, bool fog); -bool EV_TeleportGroup (int group_tid, AActor *victim, int source_tid, int dest_tid, bool moveSource, bool fog); -bool EV_TeleportSector (int tag, int source_tid, int dest_tid, bool fog, int group_tid); +bool EV_TeleportOther (FLevelLocals *Level, int other_tid, int dest_tid, bool fog); +bool EV_TeleportGroup (FLevelLocals *Level, int group_tid, AActor *victim, int source_tid, int dest_tid, bool moveSource, bool fog); +bool EV_TeleportSector (FLevelLocals *Level, int tag, int source_tid, int dest_tid, bool fog, int group_tid); // diff --git a/src/p_teleport.cpp b/src/p_teleport.cpp index fa3d2c9a76..f27998285e 100644 --- a/src/p_teleport.cpp +++ b/src/p_teleport.cpp @@ -236,7 +236,7 @@ DEFINE_ACTION_FUNCTION(AActor, Teleport) ACTION_RETURN_BOOL(P_Teleport(self, DVector3(x, y, z), an, flags)); } -static AActor *SelectTeleDest (int tid, int tag, bool norandom) +static AActor *SelectTeleDest (FLevelLocals *Level, int tid, int tag, bool norandom) { AActor *searcher; @@ -320,7 +320,7 @@ static AActor *SelectTeleDest (int tid, int tag, bool norandom) TThinkerIterator it2(NAME_TeleportDest); while ((searcher = it2.Next()) != NULL) { - if (searcher->Sector == &level.sectors[secnum]) + if (searcher->Sector == &Level->sectors[secnum]) { return searcher; } @@ -331,7 +331,7 @@ static AActor *SelectTeleDest (int tid, int tag, bool norandom) return NULL; } -bool EV_Teleport (int tid, int tag, line_t *line, int side, AActor *thing, int flags) +bool EV_Teleport (FLevelLocals *Level, int tid, int tag, line_t *line, int side, AActor *thing, int flags) { AActor *searcher; double z; @@ -353,7 +353,7 @@ bool EV_Teleport (int tid, int tag, line_t *line, int side, AActor *thing, int f { // Don't teleport if hit back of line, so you can get out of teleporter. return 0; } - searcher = SelectTeleDest(tid, tag, predicting); + searcher = SelectTeleDest(Level, tid, tag, predicting); if (searcher == NULL) { return false; @@ -427,6 +427,7 @@ bool EV_SilentLineTeleport (line_t *line, int side, AActor *thing, int id, INTBO { int i; line_t *l; + auto Level = thing->__GetLevel(); if (side || thing->flags2 & MF2_NOTELEPORT || !line || line->sidedef[1] == NULL) return false; @@ -437,7 +438,7 @@ bool EV_SilentLineTeleport (line_t *line, int side, AActor *thing, int id, INTBO if (line->Index() == i) continue; - if ((l=&level.lines[i]) != line && l->backsector) + if ((l=&Level->lines[i]) != line && l->backsector) { // Get the thing's position along the source linedef double pos; @@ -601,7 +602,7 @@ bool EV_SilentLineTeleport (line_t *line, int side, AActor *thing, int id, INTBO } // [RH] Teleport anything matching other_tid to dest_tid -bool EV_TeleportOther (int other_tid, int dest_tid, bool fog) +bool EV_TeleportOther (FLevelLocals *Level, int other_tid, int dest_tid, bool fog) { bool didSomething = false; @@ -612,7 +613,7 @@ bool EV_TeleportOther (int other_tid, int dest_tid, bool fog) while ( (victim = iterator.Next ()) ) { - didSomething |= EV_Teleport (dest_tid, 0, NULL, 0, victim, + didSomething |= EV_Teleport (Level, dest_tid, 0, NULL, 0, victim, fog ? (TELF_DESTFOG | TELF_SOURCEFOG) : TELF_KEEPORIENTATION); } } @@ -639,7 +640,7 @@ static bool DoGroupForOne (AActor *victim, AActor *source, AActor *dest, bool fl // [RH] Teleport a group of actors centered around source_tid so // that they become centered around dest_tid instead. -bool EV_TeleportGroup (int group_tid, AActor *victim, int source_tid, int dest_tid, bool moveSource, bool fog) +bool EV_TeleportGroup (FLevelLocals *Level, int group_tid, AActor *victim, int source_tid, int dest_tid, bool moveSource, bool fog) { AActor *sourceOrigin, *destOrigin; { @@ -648,7 +649,7 @@ bool EV_TeleportGroup (int group_tid, AActor *victim, int source_tid, int dest_t } if (sourceOrigin == NULL) { // If there is no source origin, behave like TeleportOther - return EV_TeleportOther (group_tid, dest_tid, fog); + return EV_TeleportOther (Level, group_tid, dest_tid, fog); } { @@ -694,7 +695,7 @@ bool EV_TeleportGroup (int group_tid, AActor *victim, int source_tid, int dest_t // [RH] Teleport a group of actors in a sector. Source_tid is used as a // reference point so that they end up in the same position relative to // dest_tid. Group_tid can be used to not teleport all actors in the sector. -bool EV_TeleportSector (int tag, int source_tid, int dest_tid, bool fog, int group_tid) +bool EV_TeleportSector (FLevelLocals *Level, int tag, int source_tid, int dest_tid, bool fog, int group_tid) { AActor *sourceOrigin, *destOrigin; { @@ -723,7 +724,7 @@ bool EV_TeleportSector (int tag, int source_tid, int dest_tid, bool fog, int gro while ((secnum = itr.Next()) >= 0) { msecnode_t *node; - const sector_t * const sec = &level.sectors[secnum]; + const sector_t * const sec = &Level->sectors[secnum]; for (node = sec->touching_thinglist; node; ) { diff --git a/src/p_things.cpp b/src/p_things.cpp index 00fad62061..d88f56f7c2 100644 --- a/src/p_things.cpp +++ b/src/p_things.cpp @@ -55,6 +55,7 @@ static FRandom pr_leadtarget ("LeadTarget"); bool P_Thing_Spawn (int tid, AActor *source, int type, DAngle angle, bool fog, int newtid) { int rtn = 0; + auto Level = source->__GetLevel(); PClassActor *kind; AActor *spot, *mobj; FActorIterator iterator (tid); @@ -68,7 +69,7 @@ bool P_Thing_Spawn (int tid, AActor *source, int type, DAngle angle, bool fog, i kind = kind->GetReplacement(); if ((GetDefaultByType(kind)->flags3 & MF3_ISMONSTER) && - ((dmflags & DF_NO_MONSTERS) || (level.flags2 & LEVEL2_NOMONSTERS))) + ((dmflags & DF_NO_MONSTERS) || (Level->flags2 & LEVEL2_NOMONSTERS))) return false; if (tid == 0) @@ -261,6 +262,7 @@ bool P_Thing_Projectile (int tid, AActor *source, int type, const char *type_nam bool leadTarget) { int rtn = 0; + auto Level = source->__GetLevel(); PClassActor *kind; AActor *spot, *mobj, *targ = forcedest; FActorIterator iterator (tid); @@ -283,8 +285,8 @@ bool P_Thing_Projectile (int tid, AActor *source, int type, const char *type_nam kind = kind->GetReplacement(); defflags3 = GetDefaultByType(kind)->flags3; - if ((defflags3 & MF3_ISMONSTER) && - ((dmflags & DF_NO_MONSTERS) || (level.flags2 & LEVEL2_NOMONSTERS))) + if ((defflags3 & MF3_ISMONSTER) && + ((dmflags & DF_NO_MONSTERS) || (Level->flags2 & LEVEL2_NOMONSTERS))) return false; if (tid == 0) @@ -316,7 +318,7 @@ bool P_Thing_Projectile (int tid, AActor *source, int type, const char *type_nam { z -= spot->Floorclip; } - mobj = Spawn (spot->__GetLevel(), kind, spot->PosAtZ(z), ALLOW_REPLACE); + mobj = Spawn (Level, kind, spot->PosAtZ(z), ALLOW_REPLACE); if (mobj) { @@ -952,20 +954,22 @@ int P_Thing_Warp(AActor *caller, AActor *reference, double xofs, double yofs, do { caller->Vel.Zero(); } + + auto &Displacements = caller->__GetLevel()->Displacements; // this is no fun with line portals if (flags & WARPF_WARPINTERPOLATION) { // This just translates the movement but doesn't change the vector - DVector3 displacedold = old + level.Displacements.getOffset(oldpgroup, caller->Sector->PortalGroup); + DVector3 displacedold = old + Displacements.getOffset(oldpgroup, caller->Sector->PortalGroup); caller->Prev += caller->Pos() - displacedold; caller->PrevPortalGroup = caller->Sector->PortalGroup; } else if (flags & WARPF_COPYINTERPOLATION) { // Map both positions of the reference actor to the current portal group - DVector3 displacedold = old + level.Displacements.getOffset(reference->PrevPortalGroup, caller->Sector->PortalGroup); - DVector3 displacedref = old + level.Displacements.getOffset(reference->Sector->PortalGroup, caller->Sector->PortalGroup); + DVector3 displacedold = old + Displacements.getOffset(reference->PrevPortalGroup, caller->Sector->PortalGroup); + DVector3 displacedref = old + Displacements.getOffset(reference->Sector->PortalGroup, caller->Sector->PortalGroup); caller->Prev = caller->Pos() + displacedold - displacedref; caller->PrevPortalGroup = caller->Sector->PortalGroup; }