diff --git a/src/am_map.cpp b/src/am_map.cpp index 8d0fbecfe..2a603be7b 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -2824,7 +2824,7 @@ void DAutomap::drawKeys () mpoint_t p; DAngle angle; - TThinkerIterator it(NAME_Key); + auto it = Level->GetThinkerIterator(NAME_Key); AActor *key; while ((key = it.Next()) != nullptr) diff --git a/src/b_func.cpp b/src/b_func.cpp index 36bbcf5c2..ddc491986 100644 --- a/src/b_func.cpp +++ b/src/b_func.cpp @@ -73,7 +73,7 @@ bool DBot::Reachable (AActor *rtarget) double estimated_dist = player->mo->Distance2D(rtarget); bool reachable = true; - FPathTraverse it(&level, player->mo->X()+player->mo->Vel.X, player->mo->Y()+player->mo->Vel.Y, rtarget->X(), rtarget->Y(), PT_ADDLINES|PT_ADDTHINGS); + FPathTraverse it(Level, player->mo->X()+player->mo->Vel.X, player->mo->Y()+player->mo->Vel.Y, rtarget->X(), rtarget->Y(), PT_ADDLINES|PT_ADDTHINGS); intercept_t *in; while ((in = it.Next())) { diff --git a/src/b_think.cpp b/src/b_think.cpp index 82954d83e..a0a30180d 100644 --- a/src/b_think.cpp +++ b/src/b_think.cpp @@ -289,7 +289,7 @@ void DBot::ThinkForMove (ticcmd_t *cmd) r = pr_botmove(); if (r < 128) { - TThinkerIterator it (NAME_Inventory, MAX_STATNUM+1, bglobal.firstthing); + auto it = player->mo->Level->GetThinkerIterator(NAME_Inventory, MAX_STATNUM+1, bglobal.firstthing); auto item = it.Next(); if (item != NULL || (item = it.Next()) != NULL) diff --git a/src/d_net.cpp b/src/d_net.cpp index a5b144b86..f062e8ddf 100644 --- a/src/d_net.cpp +++ b/src/d_net.cpp @@ -2697,7 +2697,7 @@ static void RunScript(uint8_t **stream, AActor *pawn, int snum, int argn, int al arg[i] = argval; } } - P_StartScript(pawn, NULL, snum, level.MapName, arg, MIN(countof(arg), argn), ACS_NET | always); + P_StartScript(pawn->Level, pawn, NULL, snum, level.MapName, arg, MIN(countof(arg), argn), ACS_NET | always); } void Net_SkipCommand (int type, uint8_t **stream) diff --git a/src/fragglescript/t_func.cpp b/src/fragglescript/t_func.cpp index 2797191bc..7d3fc89ae 100644 --- a/src/fragglescript/t_func.cpp +++ b/src/fragglescript/t_func.cpp @@ -560,7 +560,7 @@ void FParser::SF_Include(void) else mysnprintf(tempstr, countof(tempstr), "%i", (int)t_argv[0].value.i); - Script->ParseInclude(tempstr); + Script->ParseInclude(Level, tempstr); } } diff --git a/src/fragglescript/t_prepro.cpp b/src/fragglescript/t_prepro.cpp index d5667d7c7..4c75b95f0 100644 --- a/src/fragglescript/t_prepro.cpp +++ b/src/fragglescript/t_prepro.cpp @@ -333,13 +333,13 @@ char *DFsScript::ProcessFindChar(char *datap, char find) // //========================================================================== -void DFsScript::DryRunScript() +void DFsScript::DryRunScript(FLevelLocals *Level) { char *end = data + len; char *rover = data; // allocate space for the tokens - FParser parse(&level, this); + FParser parse(Level, this); try { while(rover < end && *rover) @@ -387,11 +387,11 @@ void DFsScript::DryRunScript() // //========================================================================== -void DFsScript::Preprocess() +void DFsScript::Preprocess(FLevelLocals *Level) { len = (int)strlen(data); ProcessFindChar(data, 0); // fill in everything - DryRunScript(); + DryRunScript(Level); } //========================================================================== @@ -406,7 +406,7 @@ void DFsScript::Preprocess() // //========================================================================== -void DFsScript::ParseInclude(char *lumpname) +void DFsScript::ParseInclude(FLevelLocals *Level, char *lumpname) { int lumpnum; char *lump; @@ -429,7 +429,7 @@ void DFsScript::ParseInclude(char *lumpname) ProcessFindChar(lump, 0); // now parse the lump - FParser parse(&level, this); + FParser parse(Level, this); parse.Run(lump, lump, lump+lumplen); // free the lump diff --git a/src/fragglescript/t_script.cpp b/src/fragglescript/t_script.cpp index 818323eef..534eb5fa4 100644 --- a/src/fragglescript/t_script.cpp +++ b/src/fragglescript/t_script.cpp @@ -196,7 +196,7 @@ void DFsScript::Serialize(FSerializer &arc) // //========================================================================== -void DFsScript::ParseScript(char *position, AActor **pTrigger) +void DFsScript::ParseScript(char *position, DFraggleThinker *th) { if (position == nullptr) { @@ -211,11 +211,11 @@ void DFsScript::ParseScript(char *position, AActor **pTrigger) return; } - *pTrigger = trigger; // set trigger variable. + th->trigger_obj = trigger; // set trigger variable. try { - FParser parse(&level, this); + FParser parse(th->Level, this); parse.Run(position, data, data + len); } catch (CFraggleScriptError &err) @@ -528,7 +528,7 @@ void DFraggleThinker::Tick() next = current->next; // save before freeing // continue the script - current->script->ParseScript (current->script->data + current->save_point, &trigger_obj); + current->script->ParseScript (current->script->data + current->save_point, this); // free current->Destroy(); @@ -618,8 +618,8 @@ void T_PreprocessScripts(FLevelLocals *Level) // levelscript started by player 0 'superplayer' th->LevelScript->trigger = players[0].mo; - th->LevelScript->Preprocess(); - th->LevelScript->ParseScript(nullptr, &th->trigger_obj); + th->LevelScript->Preprocess(Level); + th->LevelScript->ParseScript(nullptr, th); } } @@ -667,6 +667,6 @@ CCMD(fpuke) } else { - T_RunScript(&level, atoi(argv[1]), players[consoleplayer].mo); + T_RunScript(currentUILevel, atoi(argv[1]), players[consoleplayer].mo); } } diff --git a/src/fragglescript/t_script.h b/src/fragglescript/t_script.h index 6d09d0d01..f21300887 100644 --- a/src/fragglescript/t_script.h +++ b/src/fragglescript/t_script.h @@ -35,6 +35,8 @@ #pragma pointers_to_members( full_generality, single_inheritance ) #endif +class DFraggleThinker; + class CFraggleScriptError : public CDoomError { @@ -360,10 +362,10 @@ public: DFsSection *FindSectionStart(const char *brace); DFsSection *FindSectionEnd(const char *brace); char *ProcessFindChar(char *data, char find); - void DryRunScript(); - void Preprocess(); - void ParseInclude(char *lumpname); - void ParseScript(char *rover, AActor **pTrigger); + void DryRunScript(FLevelLocals *Level); + void Preprocess(FLevelLocals *Level); + void ParseInclude(FLevelLocals *Level, char *lumpname); + void ParseScript(char *rover, DFraggleThinker *th); void ParseData(char *rover, char *data, char *end); }; diff --git a/src/fragglescript/t_spec.cpp b/src/fragglescript/t_spec.cpp index c52f4cd29..5361c7c1e 100644 --- a/src/fragglescript/t_spec.cpp +++ b/src/fragglescript/t_spec.cpp @@ -429,7 +429,7 @@ void FParser::spec_script() newscript->parent = Script; // remember parent // preprocess the newscript now - newscript->Preprocess(); + newscript->Preprocess(Level); // we dont want to run the newscript, only add it // jump past the newscript in parsing diff --git a/src/g_level.cpp b/src/g_level.cpp index 4f57af68a..1eabc17a8 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -2012,11 +2012,11 @@ void FLevelLocals::AddScroller (int secnum) void FLevelLocals::SetInterMusic(const char *nextmap) { - auto mus = level.info->MapInterMusic.CheckKey(nextmap); + auto mus = info->MapInterMusic.CheckKey(nextmap); if (mus != nullptr) S_ChangeMusic(mus->first, mus->second); - else if (level.info->InterMusic.IsNotEmpty()) - S_ChangeMusic(level.info->InterMusic, level.info->intermusicorder); + else if (info->InterMusic.IsNotEmpty()) + S_ChangeMusic(info->InterMusic, info->intermusicorder); else S_ChangeMusic(gameinfo.intermissionMusic.GetChars(), gameinfo.intermissionOrder); } diff --git a/src/g_levellocals.h b/src/g_levellocals.h index 79012fb58..fcf92642e 100644 --- a/src/g_levellocals.h +++ b/src/g_levellocals.h @@ -286,6 +286,10 @@ public: if (subtype == NAME_None) return TThinkerIterator(statnum); else return TThinkerIterator(subtype, statnum); } + template TThinkerIterator GetThinkerIterator(FName subtype, int statnum, AActor *prev) + { + return TThinkerIterator(subtype, statnum, prev); + } FActorIterator GetActorIterator(int tid) { return FActorIterator(TIDHash, tid); @@ -524,7 +528,8 @@ extern FLevelLocals *currentUILevel; // level for which to display the user inte inline FSectorPortal *line_t::GetTransferredPortal() { - return portaltransferred >= level.sectorPortals.Size() ? (FSectorPortal*)nullptr : &level.sectorPortals[portaltransferred]; + auto Level = GetLevel(); + return portaltransferred >= Level->sectorPortals.Size() ? (FSectorPortal*)nullptr : &Level->sectorPortals[portaltransferred]; } inline FSectorPortal *sector_t::GetPortal(int plane) @@ -580,7 +585,7 @@ inline bool sector_t::PortalIsLinked(int plane) inline FLevelLocals *line_t::GetLevel() const { - return &level; + return frontsector->Level; } inline FLinePortal *line_t::getPortal() const { diff --git a/src/g_shared/a_decals.cpp b/src/g_shared/a_decals.cpp index a2283852c..8373231a8 100644 --- a/src/g_shared/a_decals.cpp +++ b/src/g_shared/a_decals.cpp @@ -407,7 +407,7 @@ void DBaseDecal::SpreadLeft (double r, vertex_t *v1, side_t *feelwall, F3DFloor double x = v1->fX(); double y = v1->fY(); - feelwall = &level.sides[feelwall->LeftSide]; + feelwall = &feelwall->GetLevel()->sides[feelwall->LeftSide]; GetWallStuff (feelwall, v1, ldx, ldy); double wallsize = Length (ldx, ldy); r += spread->DecalLeft; @@ -447,7 +447,7 @@ void DBaseDecal::SpreadRight (double r, side_t *feelwall, double wallsize, F3DFl while (r > wallsize && feelwall->RightSide != NO_SIDE) { - feelwall = &level.sides[feelwall->RightSide]; + feelwall = &feelwall->GetLevel()->sides[feelwall->RightSide]; side_t *nextwall = NextWall (feelwall); if (nextwall != NULL && nextwall->LeftSide != NO_SIDE) diff --git a/src/g_shared/a_lightning.cpp b/src/g_shared/a_lightning.cpp index e1610e6ee..d52bd1b92 100644 --- a/src/g_shared/a_lightning.cpp +++ b/src/g_shared/a_lightning.cpp @@ -196,9 +196,9 @@ void DLightningThinker::ForceLightning (int mode) } } -static DLightningThinker *LocateLightning () +static DLightningThinker *LocateLightning (FLevelLocals *Level) { - TThinkerIterator iterator (STAT_LIGHTNING); + auto iterator = Level->GetThinkerIterator(NAME_None, STAT_LIGHTNING); return iterator.Next (); } @@ -230,7 +230,7 @@ void FLevelLocals::StartLightning () } } - DLightningThinker *lightning = LocateLightning (); + DLightningThinker *lightning = LocateLightning (this); if (lightning == nullptr) { CreateThinker(); @@ -239,7 +239,7 @@ void FLevelLocals::StartLightning () void FLevelLocals::ForceLightning (int mode) { - DLightningThinker *lightning = LocateLightning (); + DLightningThinker *lightning = LocateLightning (this); if (lightning == nullptr) { lightning = CreateThinker(); diff --git a/src/g_shared/a_quake.cpp b/src/g_shared/a_quake.cpp index 892ba586b..a00307f7e 100644 --- a/src/g_shared/a_quake.cpp +++ b/src/g_shared/a_quake.cpp @@ -288,7 +288,7 @@ int DEarthquake::StaticGetQuakeIntensities(double ticFrac, AActor *victim, FQuak return 0; } - TThinkerIterator iterator(STAT_EARTHQUAKE); + auto iterator = victim->Level->GetThinkerIterator(NAME_None, STAT_EARTHQUAKE); DEarthquake *quake; int count = 0; diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index 378af905f..6a17fda2f 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -788,7 +788,7 @@ void DBaseStatusBar::RefreshViewBorder () { return; } - auto tex = GetBorderTexture(&level); + auto tex = GetBorderTexture(currentUILevel); screen->DrawBorder (tex, 0, 0, Width, viewwindowy); screen->DrawBorder (tex, 0, viewwindowy, viewwindowx, viewheight + viewwindowy); screen->DrawBorder (tex, viewwindowx + viewwidth, viewwindowy, Width, viewheight + viewwindowy); @@ -814,7 +814,7 @@ void DBaseStatusBar::RefreshBackground () const if (x == 0 && y == SCREENHEIGHT) return; - auto tex = GetBorderTexture(&level); + auto tex = GetBorderTexture(currentUILevel); if(!CompleteBorder) { diff --git a/src/gl/renderer/gl_renderer.cpp b/src/gl/renderer/gl_renderer.cpp index aed0be31a..b459685ba 100644 --- a/src/gl/renderer/gl_renderer.cpp +++ b/src/gl/renderer/gl_renderer.cpp @@ -254,7 +254,7 @@ sector_t *FGLRenderer::RenderView(player_t* player) bool saved_niv = NoInterpolateView; NoInterpolateView = false; // prepare all camera textures that have been used in the last frame - auto Level = &level; + auto Level = r_viewpoint.ViewLevel; gl_RenderState.CheckTimer(Level->ShaderStartTime); Level->canvasTextureInfo.UpdateAll([&](AActor *camera, FCanvasTexture *camtex, double fov) { diff --git a/src/maploader/polyobjects.cpp b/src/maploader/polyobjects.cpp index 61b2bcb5d..2bc931d1c 100644 --- a/src/maploader/polyobjects.cpp +++ b/src/maploader/polyobjects.cpp @@ -351,6 +351,10 @@ void MapLoader::PO_Init (void) InitSideLists (); Level->Polyobjects.Resize(NumPolyobjs); + for (auto p : Level->Polyobjects) + { + p.Level = Level; + } polyIndex = 0; // index polyobj number // Find the startSpot points, and spawn each polyobj diff --git a/src/nodebuild.cpp b/src/nodebuild.cpp index a352a8f0a..81d841c1b 100644 --- a/src/nodebuild.cpp +++ b/src/nodebuild.cpp @@ -54,17 +54,17 @@ const int AAPreference = 16; #define D(x) do{}while(0) #endif -FNodeBuilder::FNodeBuilder(FLevel &level) -: Level(level), GLNodes(false), SegsStuffed(0) +FNodeBuilder::FNodeBuilder(FLevel &lev) +: Level(lev), GLNodes(false), SegsStuffed(0) { VertexMap = NULL; OldVertexTable = NULL; } -FNodeBuilder::FNodeBuilder (FLevel &level, +FNodeBuilder::FNodeBuilder (FLevel &lev, TArray &polyspots, TArray &anchors, bool makeGLNodes) - : Level(level), GLNodes(makeGLNodes), SegsStuffed(0) + : Level(lev), GLNodes(makeGLNodes), SegsStuffed(0) { VertexMap = new FVertexMap (*this, Level.MinX, Level.MinY, Level.MaxX, Level.MaxY); FindUsedVertices (Level.Vertices, Level.NumVertices); diff --git a/src/nodebuild.h b/src/nodebuild.h index 8a8f133e0..0618f7247 100644 --- a/src/nodebuild.h +++ b/src/nodebuild.h @@ -228,13 +228,13 @@ public: fixed_t x, y; }; - FNodeBuilder (FLevel &level); - FNodeBuilder (FLevel &level, + FNodeBuilder (FLevel &lev); + FNodeBuilder (FLevel &lev, TArray &polyspots, TArray &anchors, bool makeGLNodes); ~FNodeBuilder (); - void Extract(FLevelLocals &level); + void Extract(FLevelLocals &lev); const int *GetOldVertexTable(); // These are used for building sub-BSP trees for polyobjects. diff --git a/src/p_acs.cpp b/src/p_acs.cpp index e589d8d07..c2dd9a3c9 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -6795,7 +6795,7 @@ int DLevelScript::RunScript() case SCRIPT_PolyWait: // Wait for polyobj(s) to stop moving, then enter state running - if (!PO_Busy (&level, statedata)) + if (!PO_Busy (Level, statedata)) { state = SCRIPT_Running; } @@ -9908,7 +9908,7 @@ scriptwait: int flags = STACK(1); sp -= 5; - P_SectorDamage(&level, tag, amount, type, protectClass, flags); + P_SectorDamage(Level, tag, amount, type, protectClass, flags); } break; @@ -10354,14 +10354,14 @@ static void addDefered (level_info_t *i, acsdefered_t::EType type, int script, c EXTERN_CVAR (Bool, sv_cheats) -int P_StartScript (AActor *who, line_t *where, int script, const char *map, const int *args, int argcount, int flags) +int P_StartScript (FLevelLocals *Level, AActor *who, line_t *where, int script, const char *map, const int *args, int argcount, int flags) { - if (map == NULL || 0 == strnicmp (level.MapName, map, 8)) + if (map == NULL || 0 == strnicmp (Level->MapName, map, 8)) { FBehavior *module = NULL; const ScriptPtr *scriptdata; - if ((scriptdata = level.Behaviors.FindScript (script, module)) != NULL) + if ((scriptdata = Level->Behaviors.FindScript (script, module)) != NULL) { if ((flags & ACS_NET) && netgame && !sv_cheats) { @@ -10379,7 +10379,7 @@ int P_StartScript (AActor *who, line_t *where, int script, const char *map, cons return false; } } - DLevelScript *runningScript = P_GetScriptGoing (&level, who, where, script, + DLevelScript *runningScript = P_GetScriptGoing (Level, who, where, script, scriptdata, module, args, argcount, flags); if (runningScript != NULL) { @@ -10409,20 +10409,20 @@ int P_StartScript (AActor *who, line_t *where, int script, const char *map, cons return false; } -void P_SuspendScript (int script, const char *map) +void P_SuspendScript (FLevelLocals *Level, int script, const char *map) { - if (strnicmp (level.MapName, map, 8)) + if (strnicmp (Level->MapName, map, 8)) addDefered (FindLevelInfo (map), acsdefered_t::defsuspend, script, NULL, 0, NULL); else - SetScriptState (level.ACSThinker, script, DLevelScript::SCRIPT_Suspended); + SetScriptState (Level->ACSThinker, script, DLevelScript::SCRIPT_Suspended); } -void P_TerminateScript (int script, const char *map) +void P_TerminateScript (FLevelLocals *Level, int script, const char *map) { - if (strnicmp (level.MapName, map, 8)) + if (strnicmp (Level->MapName, map, 8)) addDefered (FindLevelInfo (map), acsdefered_t::defterminate, script, NULL, 0, NULL); else - SetScriptState (level.ACSThinker, script, DLevelScript::SCRIPT_PleaseRemove); + SetScriptState (Level->ACSThinker, script, DLevelScript::SCRIPT_PleaseRemove); } FSerializer &Serialize(FSerializer &arc, const char *key, acsdefered_t &defer, acsdefered_t *def) diff --git a/src/p_actionfunctions.cpp b/src/p_actionfunctions.cpp index 347b6ee01..9afe3597e 100644 --- a/src/p_actionfunctions.cpp +++ b/src/p_actionfunctions.cpp @@ -3049,7 +3049,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_Teleport) } } - DSpotState *state = GetSpotState(&level, false); + DSpotState *state = GetSpotState(self->Level, false); if (state == NULL) { return numret; diff --git a/src/p_conversation.cpp b/src/p_conversation.cpp index ed25f3c9c..5265b1010 100644 --- a/src/p_conversation.cpp +++ b/src/p_conversation.cpp @@ -739,7 +739,7 @@ void P_StartConversation (AActor *npc, AActor *pc, bool facetalker, bool saveang // Make sure this is actually a player. if (pc == nullptr || pc->player == nullptr || npc == nullptr) return; - auto Level = &level; + auto Level = pc->Level; // [CW] If an NPC is talking to a PC already, then don't let // anyone else talk to the NPC. @@ -887,7 +887,7 @@ static void HandleReply(player_t *player, bool isconsole, int nodenum, int reply AActor *npc; bool takestuff; int i; - auto Level = &level; + auto Level = player->mo->Level; if (player->ConversationNPC == nullptr || (unsigned)nodenum >= Level->StrifeDialogues.Size()) { return; diff --git a/src/p_lnspec.cpp b/src/p_lnspec.cpp index ceebb43ee..c60343045 100644 --- a/src/p_lnspec.cpp +++ b/src/p_lnspec.cpp @@ -1923,7 +1923,7 @@ FUNC(LS_ACS_Execute) { return false; } - return P_StartScript(it, ln, arg0, mapname, args, 3, flags); + return P_StartScript(Level, it, ln, arg0, mapname, args, 3, flags); } FUNC(LS_ACS_ExecuteAlways) @@ -1946,7 +1946,7 @@ FUNC(LS_ACS_ExecuteAlways) { return false; } - return P_StartScript(it, ln, arg0, mapname, args, 3, flags); + return P_StartScript(Level, it, ln, arg0, mapname, args, 3, flags); } FUNC(LS_ACS_LockedExecute) @@ -1976,7 +1976,7 @@ FUNC(LS_ACS_ExecuteWithResult) int args[4] = { arg1, arg2, arg3, arg4 }; int flags = (backSide ? ACS_BACKSIDE : 0) | ACS_ALWAYS | ACS_WANTRESULT; - return P_StartScript (it, ln, arg0, Level->MapName, args, 4, flags); + return P_StartScript (Level, it, ln, arg0, Level->MapName, args, 4, flags); } FUNC(LS_ACS_Suspend) @@ -1985,9 +1985,9 @@ FUNC(LS_ACS_Suspend) level_info_t *info; if (arg1 == 0) - P_SuspendScript (arg0, Level->MapName); + P_SuspendScript (Level, arg0, Level->MapName); else if ((info = FindLevelByNum (arg1)) ) - P_SuspendScript (arg0, info->MapName); + P_SuspendScript (Level, arg0, info->MapName); return true; } @@ -1998,9 +1998,9 @@ FUNC(LS_ACS_Terminate) level_info_t *info; if (arg1 == 0) - P_TerminateScript (arg0, Level->MapName); + P_TerminateScript (Level, arg0, Level->MapName); else if ((info = FindLevelByNum (arg1)) ) - P_TerminateScript (arg0, info->MapName); + P_TerminateScript (Level, arg0, info->MapName); return true; } @@ -2016,7 +2016,7 @@ FUNC(LS_FS_Execute) { if (arg1 && ln && backSide) return false; if (arg2!=0 && !P_CheckKeys(it, arg2, !!arg3)) return false; - return T_RunScript(&level, arg0, it); + return T_RunScript(Level, arg0, it); } @@ -2251,7 +2251,7 @@ FUNC(LS_Sector_SetCurrent) FUNC(LS_Sector_SetFriction) // Sector_SetFriction (tag, amount) { - P_SetSectorFriction (&level, arg0, arg1, true); + P_SetSectorFriction (Level, arg0, arg1, true); return true; } @@ -2310,7 +2310,7 @@ FUNC(LS_Scroll_Texture_Both) sidechoice = 0; } - SetWallScroller (&level, arg0, sidechoice, dx, dy, scw_all); + SetWallScroller (Level, arg0, sidechoice, dx, dy, scw_all); return true; } @@ -2321,7 +2321,7 @@ FUNC(LS_Scroll_Wall) if (arg0 == 0) return false; - SetWallScroller (&level, arg0, !!arg3, arg1 / 65536., arg2 / 65536., EScrollPos(arg4)); + SetWallScroller (Level, arg0, !!arg3, arg1 / 65536., arg2 / 65536., EScrollPos(arg4)); return true; } @@ -2337,19 +2337,19 @@ FUNC(LS_Scroll_Floor) if (arg3 == 0 || arg3 == 2) { - SetScroller (&level, arg0, EScroll::sc_floor, -dx, dy); + SetScroller (Level, arg0, EScroll::sc_floor, -dx, dy); } else { - SetScroller (&level, arg0, EScroll::sc_floor, 0, 0); + SetScroller (Level, arg0, EScroll::sc_floor, 0, 0); } if (arg3 > 0) { - SetScroller (&level, arg0, EScroll::sc_carry, dx, dy); + SetScroller (Level, arg0, EScroll::sc_carry, dx, dy); } else { - SetScroller (&level, arg0, EScroll::sc_carry, 0, 0); + SetScroller (Level, arg0, EScroll::sc_carry, 0, 0); } return true; } @@ -2360,7 +2360,7 @@ FUNC(LS_Scroll_Ceiling) double dx = arg1 / 32.; double dy = arg2 / 32.; - SetScroller (&level, arg0, EScroll::sc_ceiling, -dx, dy); + SetScroller (Level, arg0, EScroll::sc_ceiling, -dx, dy); return true; } diff --git a/src/p_map.cpp b/src/p_map.cpp index 7fb261ce7..2166831c5 100644 --- a/src/p_map.cpp +++ b/src/p_map.cpp @@ -2928,7 +2928,7 @@ void FSlide::HitSlideLine(line_t* ld) void FSlide::SlideTraverse(const DVector2 &start, const DVector2 &end) { FLineOpening open; - FPathTraverse it(&level, start.X, start.Y, end.X, end.Y, PT_ADDLINES); + FPathTraverse it(slidemo->Level, start.X, start.Y, end.X, end.Y, PT_ADDLINES); intercept_t *in; while ((in = it.Next())) @@ -3285,7 +3285,7 @@ const secplane_t * P_CheckSlopeWalk(AActor *actor, DVector2 &move) bool FSlide::BounceTraverse(const DVector2 &start, const DVector2 &end) { FLineOpening open; - FPathTraverse it(&level, start.X, start.Y, end.X, end.Y, PT_ADDLINES); + FPathTraverse it(slidemo->Level, start.X, start.Y, end.X, end.Y, PT_ADDLINES); intercept_t *in; while ((in = it.Next())) @@ -3977,7 +3977,7 @@ struct aim_t if (ceilingportalstate) EnterSectorPortal(sector_t::ceiling, 0, lastsector, toppitch, MIN(0., bottompitch)); if (floorportalstate) EnterSectorPortal(sector_t::floor, 0, lastsector, MAX(0., toppitch), bottompitch); - FPathTraverse it(&level, startpos.X, startpos.Y, aimtrace.X, aimtrace.Y, PT_ADDLINES | PT_ADDTHINGS | PT_COMPATIBLE | PT_DELTA, startfrac); + FPathTraverse it(lastsector->Level, startpos.X, startpos.Y, aimtrace.X, aimtrace.Y, PT_ADDLINES | PT_ADDTHINGS | PT_COMPATIBLE | PT_DELTA, startfrac); intercept_t *in; if (aimdebug) @@ -5376,7 +5376,7 @@ bool P_TalkFacing(AActor *player) bool P_UseTraverse(AActor *usething, const DVector2 &start, const DVector2 &end, bool &foundline) { - FPathTraverse it(&level, start.X, start.Y, end.X, end.Y, PT_ADDLINES | PT_ADDTHINGS); + FPathTraverse it(usething->Level, start.X, start.Y, end.X, end.Y, PT_ADDLINES | PT_ADDTHINGS); intercept_t *in; DVector3 xpos = { start.X, start.Y, usething->Z() }; @@ -5519,7 +5519,7 @@ bool P_UseTraverse(AActor *usething, const DVector2 &start, const DVector2 &end, bool P_NoWayTraverse(AActor *usething, const DVector2 &start, const DVector2 &end) { - FPathTraverse it(&level, start.X, start.Y, end.X, end.Y, PT_ADDLINES); + FPathTraverse it(usething->Level, start.X, start.Y, end.X, end.Y, PT_ADDLINES); intercept_t *in; while ((in = it.Next())) @@ -5596,7 +5596,7 @@ int P_UsePuzzleItem(AActor *PuzzleItemUser, int PuzzleItemType) start = PuzzleItemUser->GetPortalTransition(PuzzleItemUser->Height / 2); end = PuzzleItemUser->Angles.Yaw.ToVector(usedist); - FPathTraverse it(&level, start.X, start.Y, end.X, end.Y, PT_DELTA | PT_ADDLINES | PT_ADDTHINGS); + FPathTraverse it(PuzzleItemUser->Level, start.X, start.Y, end.X, end.Y, PT_DELTA | PT_ADDLINES | PT_ADDTHINGS); intercept_t *in; while ((in = it.Next())) @@ -5624,7 +5624,7 @@ int P_UsePuzzleItem(AActor *PuzzleItemUser, int PuzzleItemType) return false; } int args[3] = { in->d.line->args[2], in->d.line->args[3], in->d.line->args[4] }; - P_StartScript(PuzzleItemUser, in->d.line, in->d.line->args[1], NULL, args, 3, ACS_ALWAYS); + P_StartScript(PuzzleItemUser->Level, PuzzleItemUser, in->d.line, in->d.line->args[1], NULL, args, 3, ACS_ALWAYS); in->d.line->special = 0; return true; } @@ -5639,7 +5639,7 @@ int P_UsePuzzleItem(AActor *PuzzleItemUser, int PuzzleItemType) continue; } int args[3] = { mobj->args[2], mobj->args[3], mobj->args[4] }; - P_StartScript(PuzzleItemUser, NULL, mobj->args[1], NULL, args, 3, ACS_ALWAYS); + P_StartScript(PuzzleItemUser->Level, PuzzleItemUser, NULL, mobj->args[1], NULL, args, 3, ACS_ALWAYS); mobj->special = 0; return true; } diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 311a7cb4e..3017d6aed 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -143,7 +143,7 @@ static void PrecacheLevel(FLevelLocals *Level) memset(hitlist.Data(), 0, cnt); AActor *actor; - TThinkerIterator iterator; + auto iterator = Level->GetThinkerIterator(); while ((actor = iterator.Next())) { @@ -485,7 +485,7 @@ void P_SetupLevel(FLevelLocals *Level, int position, bool newGame) // Don't count monsters in end-of-level sectors if option is on if (dmflags2 & DF2_NOCOUNTENDMONST) { - TThinkerIterator it; + auto it = Level->GetThinkerIterator(); AActor * mo; while ((mo = it.Next())) @@ -500,7 +500,7 @@ void P_SetupLevel(FLevelLocals *Level, int position, bool newGame) } } - T_PreprocessScripts(&level); // preprocess FraggleScript scripts + T_PreprocessScripts(Level); // preprocess FraggleScript scripts // build subsector connect matrix // UNUSED P_ConnectSubsectors (); @@ -513,8 +513,8 @@ void P_SetupLevel(FLevelLocals *Level, int position, bool newGame) // preload graphics and sounds if (precache) { - PrecacheLevel(&level); - S_PrecacheLevel(); + PrecacheLevel(Level); + S_PrecacheLevel(Level); } if (deathmatch) @@ -663,7 +663,7 @@ CUSTOM_CVAR(Bool, forcewater, false, CVAR_ARCHIVE | CVAR_SERVERINFO) { if (gamestate == GS_LEVEL) { - auto Level = &level; + auto Level = currentUILevel; for (auto &sec : Level->sectors) { sector_t *hsec = sec.GetHeightSec(); diff --git a/src/p_spec.cpp b/src/p_spec.cpp index f60e61468..942441890 100644 --- a/src/p_spec.cpp +++ b/src/p_spec.cpp @@ -435,7 +435,7 @@ void P_PlayerInSpecialSector (player_t *player, sector_t * sector) // Has hit ground. AActor *ironfeet; - auto Level = &level; + auto Level = sector->Level; // [RH] Apply any customizable damage if (sector->damageamount > 0) @@ -630,7 +630,7 @@ DEFINE_ACTION_FUNCTION(FLevelLocals, GiveSecret) void P_PlayerOnSpecialFlat (player_t *player, int floorType) { - auto Level = &level; + auto Level = player->mo->Level; if (Terrains[floorType].DamageAmount && !(Level->time & Terrains[floorType].DamageTimeMask)) @@ -707,7 +707,6 @@ void DLightTransfer::Construct(sector_t *srcSec, int target, bool copyFloor) CopyFloor = copyFloor; DoTransfer (LastLight = srcSec->lightlevel, target, copyFloor); - auto Level = &level; if (copyFloor) { auto itr = Level->GetSectorTagIterator(target); @@ -737,7 +736,6 @@ void DLightTransfer::DoTransfer (int llevel, int target, bool floor) { int secnum; - auto Level = &level; if (floor) { auto itr = Level->GetSectorTagIterator(target); @@ -783,7 +781,6 @@ void DWallLightTransfer::Construct(sector_t *srcSec, int target, uint8_t flags) wallflags = WALLF_ABSLIGHTING | WALLF_NOFAKECONTRAST; } - auto Level = &level; auto itr = Level->GetLineIdIterator(target); while ((linenum = itr.Next()) >= 0) { @@ -814,7 +811,6 @@ void DWallLightTransfer::DoTransfer (short lightlevel, int target, uint8_t flags { int linenum; - auto Level = &level; auto itr = Level->GetLineIdIterator(target); while ((linenum = itr.Next()) >= 0) { diff --git a/src/p_spec.h b/src/p_spec.h index d959bf6ba..be1b710b9 100644 --- a/src/p_spec.h +++ b/src/p_spec.h @@ -595,9 +595,9 @@ bool P_Teleport(AActor *thing, DVector3 pos, DAngle angle, int flags); #define ACS_WANTRESULT 4 #define ACS_NET 8 -int P_StartScript (AActor *who, line_t *where, int script, const char *map, const int *args, int argcount, int flags); -void P_SuspendScript (int script, const char *map); -void P_TerminateScript (int script, const char *map); +int P_StartScript (FLevelLocals *Level, AActor *who, line_t *where, int script, const char *map, const int *args, int argcount, int flags); +void P_SuspendScript (FLevelLocals *Level, int script, const char *map); +void P_TerminateScript (FLevelLocals *Level, int script, const char *map); // // [RH] p_quake.c diff --git a/src/p_switch.cpp b/src/p_switch.cpp index 918a76d60..bfb8478a4 100644 --- a/src/p_switch.cpp +++ b/src/p_switch.cpp @@ -85,7 +85,7 @@ protected: static bool P_StartButton (side_t *side, int Where, FSwitchDef *Switch, const DVector2 &pos, bool useagain) { DActiveButton *button; - TThinkerIterator iterator; + auto iterator = side->GetLevel()->GetThinkerIterator(); // See if button is already pressed while ( (button = iterator.Next ()) ) @@ -97,7 +97,7 @@ static bool P_StartButton (side_t *side, int Where, FSwitchDef *Switch, const DV } } - side->sector->Level->CreateThinker (side, Where, Switch, pos, useagain); + side->GetLevel()->CreateThinker (side, Where, Switch, pos, useagain); return true; } diff --git a/src/p_teleport.cpp b/src/p_teleport.cpp index 4c423bdc8..63e5d3353 100644 --- a/src/p_teleport.cpp +++ b/src/p_teleport.cpp @@ -316,7 +316,7 @@ AActor *FLevelLocals::SelectTeleDest (int tid, int tag, bool norandom) // teleport destination. This means if 50 sectors have a matching tag and // only the last one has a destination, *every* actor is scanned at least 49 // times. Yuck. - TThinkerIterator it2(NAME_TeleportDest); + auto it2 = GetThinkerIterator(NAME_TeleportDest); while ((searcher = it2.Next()) != NULL) { if (searcher->Sector == §ors[secnum]) diff --git a/src/p_things.cpp b/src/p_things.cpp index a65ff70b8..7f72ed19d 100644 --- a/src/p_things.cpp +++ b/src/p_things.cpp @@ -754,7 +754,7 @@ int P_Thing_CheckProximity(AActor *self, PClass *classname, double distance, int const bool ptrWillChange = !!(flags & (CPXF_SETTARGET | CPXF_SETMASTER | CPXF_SETTRACER)); const bool ptrDistPref = !!(flags & (CPXF_CLOSEST | CPXF_FARTHEST)); - TThinkerIterator it; + auto it = self->Level->GetThinkerIterator(); AActor *mo, *dist = nullptr; // [MC] Process of elimination, I think, will get through this as quickly and diff --git a/src/po_man.cpp b/src/po_man.cpp index b5d90f364..9f52f5a89 100644 --- a/src/po_man.cpp +++ b/src/po_man.cpp @@ -741,11 +741,6 @@ int FPolyObj::GetMirror() return MirrorNum; } -FLevelLocals *FPolyObj::GetLevel() const -{ - return &level; -} - //========================================================================== // // ThrustMobj @@ -756,7 +751,6 @@ void FPolyObj::ThrustMobj (AActor *actor, side_t *side) { DAngle thrustAngle; DPolyAction *pe; - auto Level = GetLevel(); double force; @@ -811,7 +805,6 @@ void FPolyObj::UpdateLinks() { if (bHasPortals == 2) { - auto Level = GetLevel(); TMap processed; for (unsigned i = 0; i < Linedefs.Size(); i++) { @@ -1000,7 +993,6 @@ void FPolyObj::UnLinkPolyobj () polyblock_t *link; int i, j; int index; - auto Level = GetLevel(); // remove the polyobj from each blockmap section for(j = bbox[BOXBOTTOM]; j <= bbox[BOXTOP]; j++) @@ -1033,7 +1025,6 @@ void FPolyObj::UnLinkPolyobj () bool FPolyObj::CheckMobjBlocking (side_t *sd) { - auto Level = GetLevel(); static TArray checker; FBlockNode *block; AActor *mobj; @@ -1169,7 +1160,6 @@ void FPolyObj::LinkPolyobj () { polyblock_t **link; polyblock_t *tempLink; - auto Level = GetLevel(); int bmapwidth = Level->blockmap.bmapwidth; int bmapheight = Level->blockmap.bmapheight; @@ -1666,7 +1656,6 @@ static void SplitPoly(FPolyNode *pnode, void *node, float bbox[4]) void FPolyObj::CreateSubsectorLinks() { - auto Level = GetLevel(); FPolyNode *node = NewPolyNode(); // Even though we don't care about it, we need to initialize this // bounding box to something so that Valgrind won't complain about it @@ -1846,7 +1835,7 @@ FPolyObj *FPolyMirrorIterator::NextMirror() if (i == NumUsedPolys) { // No, it has not been returned. UsedPolys[NumUsedPolys++] = mirror; - nextpoly = poly->GetLevel()->GetPolyobj(mirror); + nextpoly = poly->Level->GetPolyobj(mirror); if (nextpoly == nullptr) { Printf("Invalid mirror polyobj num %d for polyobj num %d\n", mirror, UsedPolys[i - 1]); diff --git a/src/po_man.h b/src/po_man.h index 70f437443..cc8f5fbf9 100644 --- a/src/po_man.h +++ b/src/po_man.h @@ -67,6 +67,7 @@ struct FPolyNode // ===== Polyobj data ===== struct FPolyObj { + FLevelLocals *Level; TArray Sidedefs; TArray Linedefs; TArray Vertices; @@ -108,9 +109,6 @@ struct FPolyObj void UpdateLinks(); static void ClearAllSubsectorLinks(); - FLevelLocals *GetLevel() const; - - private: void ThrustMobj (AActor *actor, side_t *side); diff --git a/src/polyrenderer/poly_renderer.cpp b/src/polyrenderer/poly_renderer.cpp index 8cc8aa616..87642d831 100644 --- a/src/polyrenderer/poly_renderer.cpp +++ b/src/polyrenderer/poly_renderer.cpp @@ -136,7 +136,7 @@ void PolyRenderer::RenderActorView(AActor *actor, bool dontmaplines) R_SetupFrame(Viewpoint, Viewwindow, actor); Level = Viewpoint.ViewLevel; P_FindParticleSubsectors(); - PO_LinkToSubsectors(&level); + PO_LinkToSubsectors(Level); static bool firstcall = true; if (firstcall) diff --git a/src/r_utility.cpp b/src/r_utility.cpp index 26d8d4f6d..9278a94d3 100644 --- a/src/r_utility.cpp +++ b/src/r_utility.cpp @@ -1034,7 +1034,7 @@ void R_SetupFrame (FRenderViewpoint &viewpoint, FViewWindow &viewwindow, AActor viewpoint.HWAngles.Pitch = RAD2DEG((float)asin(angy / alen)); viewpoint.HWAngles.Roll.Degrees = (float)viewpoint.Angles.Roll.Degrees; // copied for convenience. - viewpoint.ViewLevel = &level; + viewpoint.ViewLevel = actor->Level; // ViewActor only gets set, if the camera actor should not be rendered if (actor->player && actor->player - players == consoleplayer && diff --git a/src/s_sound.cpp b/src/s_sound.cpp index 6dbb6ff88..20a287ae7 100644 --- a/src/s_sound.cpp +++ b/src/s_sound.cpp @@ -471,11 +471,11 @@ void S_Start () // //========================================================================== -void S_PrecacheLevel () +void S_PrecacheLevel (FLevelLocals *Level) { unsigned int i; - if (GSnd) + if (GSnd && Level == currentUILevel) { for (i = 0; i < S_sfx.Size(); ++i) { @@ -483,7 +483,7 @@ void S_PrecacheLevel () } AActor *actor; - TThinkerIterator iterator; + auto iterator = Level->GetThinkerIterator(); // Precache all sounds known to be used by the currently spawned actors. while ( (actor = iterator.Next()) != NULL ) @@ -1371,7 +1371,7 @@ void S_SoundMinMaxDist(AActor *ent, int channel, FSoundID sound_id, float volume void S_Sound (const FPolyObj *poly, int channel, FSoundID sound_id, float volume, float attenuation) { - if (poly->GetLevel() != currentUILevel) return; + if (poly->Level != currentUILevel) return; S_StartSound (nullptr, nullptr, poly, nullptr, channel, sound_id, volume, attenuation); } diff --git a/src/s_sound.h b/src/s_sound.h index a5f3c17a0..411896716 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -218,7 +218,7 @@ void S_Shutdown (); void S_Start (); // Called after a level is loaded. Ensures that most sounds are loaded. -void S_PrecacheLevel (); +void S_PrecacheLevel (FLevelLocals *l); // Loads a sound, including any random sounds it might reference. void S_CacheSound (sfxinfo_t *sfx); diff --git a/src/scripting/vmthunks_actors.cpp b/src/scripting/vmthunks_actors.cpp index d52e6e28e..dd833e744 100644 --- a/src/scripting/vmthunks_actors.cpp +++ b/src/scripting/vmthunks_actors.cpp @@ -1330,7 +1330,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(AActor, CheckSight, P_CheckSight) static void GiveSecret(AActor *self, bool printmessage, bool playsound) { - P_GiveSecret(&level, self, printmessage, playsound, -1); + P_GiveSecret(self->Level, self, printmessage, playsound, -1); } DEFINE_ACTION_FUNCTION_NATIVE(AActor, GiveSecret, GiveSecret) diff --git a/src/statistics.cpp b/src/statistics.cpp index 2c155f5fb..04c780f34 100644 --- a/src/statistics.cpp +++ b/src/statistics.cpp @@ -577,7 +577,7 @@ FString GetStatString() CCMD(printstats) { - StoreLevelStats(&level); // Refresh the current level's results. + StoreLevelStats(currentUILevel); // Refresh the current level's results. Printf("%s", GetStatString().GetChars()); } @@ -596,6 +596,6 @@ CCMD(finishgame) ADD_STAT(statistics) { - StoreLevelStats(&level); // Refresh the current level's results. + StoreLevelStats(currentUILevel); // Refresh the current level's results. return GetStatString(); }