From 64ac6dbc6e19e4040c6cf77f41f415e947649aa4 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 30 Jan 2019 19:09:21 +0100 Subject: [PATCH] - moved thinker storage into FLevelLocals. --- src/d_main.cpp | 2 +- src/dobjgc.cpp | 1 - src/dthinker.cpp | 22 ++++++++-------------- src/dthinker.h | 26 +++++++++----------------- src/g_level.cpp | 6 +++--- src/g_levellocals.h | 7 ++++--- src/p_saveg.cpp | 2 +- src/p_setup.cpp | 5 ++--- src/p_tick.cpp | 2 +- src/scripting/vmiterators.cpp | 8 ++++---- 10 files changed, 33 insertions(+), 48 deletions(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index 29086572b..ef9c18e11 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2724,7 +2724,7 @@ void D_DoomMain (void) // clean up game state ST_Clear(); D_ErrorCleanup (); - Thinkers.DestroyThinkersInList(STAT_STATIC); + level.Thinkers.DestroyThinkersInList(STAT_STATIC); E_Shutdown(false); P_FreeLevelData(); diff --git a/src/dobjgc.cpp b/src/dobjgc.cpp index f9c1e2293..e0531be7d 100644 --- a/src/dobjgc.cpp +++ b/src/dobjgc.cpp @@ -282,7 +282,6 @@ static void MarkRoot() Mark(StatusBar); M_MarkMenus(); Mark(DIntermissionController::CurrentIntermission); - Thinkers.MarkRoots(); Mark(E_FirstEventHandler); Mark(E_LastEventHandler); for (auto Level : AllLevels()) diff --git a/src/dthinker.cpp b/src/dthinker.cpp index 3157b567f..7b286ebec 100644 --- a/src/dthinker.cpp +++ b/src/dthinker.cpp @@ -65,7 +65,6 @@ struct ProfileInfo static TMap Profiles; static unsigned int profilethinkers, profilelimit; -FThinkerCollection Thinkers; DThinker *NextToThink; //========================================================================== @@ -750,16 +749,12 @@ DThinker *FLevelLocals::FirstThinker (int statnum) void DThinker::ChangeStatNum (int statnum) { - FThinkerList *list; - - FThinkerCollection *collection = &Thinkers; //Todo: get from level - if ((unsigned)statnum > MAX_STATNUM) { statnum = MAX_STATNUM; } Remove(); - Thinkers.Link(this, statnum); + Level->Thinkers.Link(this, statnum); } static void ChangeStatNum(DThinker *thinker, int statnum) @@ -771,7 +766,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(DThinker, ChangeStatNum, ChangeStatNum) { PARAM_SELF_PROLOGUE(DThinker); PARAM_INT(stat); - self->ChangeStatNum(stat); + ChangeStatNum(self, stat); return 0; } @@ -884,7 +879,7 @@ size_t DThinker::PropagateMark() // //========================================================================== -FThinkerIterator::FThinkerIterator (const PClass *type, int statnum) +FThinkerIterator::FThinkerIterator (FLevelLocals *l, const PClass *type, int statnum) : Level(l) { if ((unsigned)statnum > MAX_STATNUM) { @@ -897,8 +892,7 @@ FThinkerIterator::FThinkerIterator (const PClass *type, int statnum) m_SearchStats = false; } m_ParentType = type; - m_CurrThinker = Thinkers.Thinkers[m_Stat].GetHead(); - m_SearchingFresh = false; + Reinit(); } //========================================================================== @@ -907,7 +901,7 @@ FThinkerIterator::FThinkerIterator (const PClass *type, int statnum) // //========================================================================== -FThinkerIterator::FThinkerIterator (const PClass *type, int statnum, DThinker *prev) +FThinkerIterator::FThinkerIterator (FLevelLocals *l, const PClass *type, int statnum, DThinker *prev) : Level(l) { if ((unsigned)statnum > MAX_STATNUM) { @@ -939,7 +933,7 @@ FThinkerIterator::FThinkerIterator (const PClass *type, int statnum, DThinker *p void FThinkerIterator::Reinit () { - m_CurrThinker = Thinkers.Thinkers[m_Stat].GetHead(); + m_CurrThinker = Level->Thinkers.Thinkers[m_Stat].GetHead(); m_SearchingFresh = false; } @@ -980,7 +974,7 @@ DThinker *FThinkerIterator::Next (bool exact) } if ((m_SearchingFresh = !m_SearchingFresh)) { - m_CurrThinker = Thinkers.FreshThinkers[m_Stat].GetHead(); + m_CurrThinker = Level->Thinkers.FreshThinkers[m_Stat].GetHead(); } } while (m_SearchingFresh); if (m_SearchStats) @@ -991,7 +985,7 @@ DThinker *FThinkerIterator::Next (bool exact) m_Stat = STAT_FIRST_THINKING; } } - m_CurrThinker = Thinkers.Thinkers[m_Stat].GetHead(); + m_CurrThinker = Level->Thinkers.Thinkers[m_Stat].GetHead(); m_SearchingFresh = false; } while (m_SearchStats && m_Stat != STAT_FIRST_THINKING); return nullptr; diff --git a/src/dthinker.h b/src/dthinker.h index 5d322409c..26b4e06ac 100644 --- a/src/dthinker.h +++ b/src/dthinker.h @@ -131,14 +131,15 @@ class FThinkerIterator protected: const PClass *m_ParentType; private: + FLevelLocals *Level; DThinker *m_CurrThinker; uint8_t m_Stat; bool m_SearchStats; bool m_SearchingFresh; public: - FThinkerIterator (const PClass *type, int statnum=MAX_STATNUM+1); - FThinkerIterator (const PClass *type, int statnum, DThinker *prev); + FThinkerIterator (FLevelLocals *Level, const PClass *type, int statnum=MAX_STATNUM+1); + FThinkerIterator (FLevelLocals *Level, const PClass *type, int statnum, DThinker *prev); DThinker *Next (bool exact = false); void Reinit (); @@ -149,28 +150,19 @@ protected: template class TThinkerIterator : public FThinkerIterator { public: - TThinkerIterator (int statnum=MAX_STATNUM+1) : FThinkerIterator (RUNTIME_CLASS(T), statnum) + TThinkerIterator (FLevelLocals *Level, int statnum=MAX_STATNUM+1) : FThinkerIterator (Level, RUNTIME_CLASS(T), statnum) { } - TThinkerIterator (int statnum, DThinker *prev) : FThinkerIterator (RUNTIME_CLASS(T), statnum, prev) + TThinkerIterator (FLevelLocals *Level, int statnum, DThinker *prev) : FThinkerIterator (Level, RUNTIME_CLASS(T), statnum, prev) { } - TThinkerIterator (const PClass *subclass, int statnum=MAX_STATNUM+1) : FThinkerIterator(subclass, statnum) + TThinkerIterator (FLevelLocals *Level, const PClass *subclass, int statnum=MAX_STATNUM+1) : FThinkerIterator(Level, subclass, statnum) { } - TThinkerIterator (FName subclass, int statnum=MAX_STATNUM+1) : FThinkerIterator(PClass::FindClass(subclass), statnum) + TThinkerIterator (FLevelLocals *Level, FName subclass, int statnum=MAX_STATNUM+1) : FThinkerIterator(Level, PClass::FindClass(subclass), statnum) { } - TThinkerIterator (ENamedName subclass, int statnum=MAX_STATNUM+1) : FThinkerIterator(PClass::FindClass(subclass), statnum) - { - } - TThinkerIterator (FName subclass, int statnum, DThinker *prev) : FThinkerIterator(PClass::FindClass(subclass), statnum, prev) - { - } - TThinkerIterator (ENamedName subclass, int statnum, DThinker *prev) : FThinkerIterator(PClass::FindClass(subclass), statnum, prev) - { - } - TThinkerIterator (const char *subclass, int statnum=MAX_STATNUM+1) : FThinkerIterator(PClass::FindClass(subclass), statnum) + TThinkerIterator (FLevelLocals *Level, FName subclass, int statnum, DThinker *prev) : FThinkerIterator(Level, PClass::FindClass(subclass), statnum, prev) { } T *Next (bool exact = false) @@ -179,5 +171,5 @@ public: } }; -extern FThinkerCollection Thinkers; + #endif //__DTHINKER_H__ diff --git a/src/g_level.cpp b/src/g_level.cpp index 07e7df6d9..c3c26a03e 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -356,7 +356,7 @@ void G_NewInit () int i; // Destory all old player refrences that may still exist - TThinkerIterator it(NAME_PlayerPawn, STAT_TRAVELLING); + TThinkerIterator it(&level, NAME_PlayerPawn, STAT_TRAVELLING); AActor *pawn, *next; next = it.Next(); @@ -469,7 +469,7 @@ void G_InitNew (const char *mapname, bool bTitleLevel) UnlatchCVars (); G_VerifySkill(); UnlatchCVars (); - Thinkers.DestroyThinkersInList(STAT_STATIC); + level.Thinkers.DestroyThinkersInList(STAT_STATIC); if (paused) { @@ -2117,7 +2117,7 @@ void FLevelLocals::Mark() GC::Mark(BotInfo.firstthing); GC::Mark(BotInfo.body1); GC::Mark(BotInfo.body2); - + Thinkers.MarkRoots(); canvasTextureInfo.Mark(); for (auto &c : CorpseQueue) { diff --git a/src/g_levellocals.h b/src/g_levellocals.h index 9ab21d52d..74011f9e1 100644 --- a/src/g_levellocals.h +++ b/src/g_levellocals.h @@ -269,12 +269,12 @@ public: } template TThinkerIterator GetThinkerIterator(FName subtype = NAME_None, int statnum = MAX_STATNUM+1) { - if (subtype == NAME_None) return TThinkerIterator(statnum); - else return TThinkerIterator(subtype, statnum); + if (subtype == NAME_None) return TThinkerIterator(this, statnum); + else return TThinkerIterator(this, subtype, statnum); } template TThinkerIterator GetThinkerIterator(FName subtype, int statnum, AActor *prev) { - return TThinkerIterator(subtype, statnum, prev); + return TThinkerIterator(this, subtype, statnum, prev); } FActorIterator GetActorIterator(int tid) { @@ -590,6 +590,7 @@ public: uint32_t InactiveParticles; TArray Particles; TArray ParticlesInSubsec; + FThinkerCollection Thinkers; TArray Scrolls; // NULL if no DScrollers in this level diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index d792b338f..d363e08c9 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -1013,7 +1013,7 @@ void FLevelLocals::Serialize(FSerializer &arc, bool hubload) if (arc.isReading()) { for (auto &sec : sectors) - { + { P_Recalculate3DFloors(&sec); } for (int i = 0; i < MAXPLAYERS; ++i) diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 01b84ed6d..8656507eb 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -253,6 +253,7 @@ void FLevelLocals::ClearPortals() void FLevelLocals::ClearLevelData() { + Thinkers.DestroyAllThinkers(); ClearAllSubsectorLinks(); // can't be done as part of the polyobj deletion process. total_monsters = total_items = total_secrets = @@ -349,8 +350,6 @@ void P_FreeLevelData () E_Shutdown(true); R_FreePastViewers(); - Thinkers.DestroyAllThinkers (); - level.ClearLevelData(); } @@ -574,7 +573,7 @@ void P_Init () static void P_Shutdown () { - Thinkers.DestroyThinkersInList(STAT_STATIC); + level.Thinkers.DestroyThinkersInList(STAT_STATIC); P_FreeLevelData (); // [ZZ] delete global event handlers E_Shutdown(false); diff --git a/src/p_tick.cpp b/src/p_tick.cpp index cfd6064f3..6b7b42b1c 100644 --- a/src/p_tick.cpp +++ b/src/p_tick.cpp @@ -151,7 +151,7 @@ void P_Ticker (void) E_WorldTick(); StatusBar->CallTick (); // [RH] moved this here level.Tick (); // [RH] let the level tick - Thinkers.RunThinkers(&level); + level.Thinkers.RunThinkers(&level); //if added by MC: Freeze mode. if (!level.isFrozen()) diff --git a/src/scripting/vmiterators.cpp b/src/scripting/vmiterators.cpp index 825dbef04..7e2ad47ad 100644 --- a/src/scripting/vmiterators.cpp +++ b/src/scripting/vmiterators.cpp @@ -41,8 +41,8 @@ class DThinkerIterator : public DObject, public FThinkerIterator DECLARE_ABSTRACT_CLASS(DThinkerIterator, DObject) public: - DThinkerIterator(PClass *cls, int statnum = MAX_STATNUM + 1) - : FThinkerIterator(cls, statnum) + DThinkerIterator(FLevelLocals *Level, PClass *cls, int statnum = MAX_STATNUM + 1) + : FThinkerIterator(Level, cls, statnum) { } }; @@ -51,7 +51,7 @@ IMPLEMENT_CLASS(DThinkerIterator, true, false); static DThinkerIterator *CreateThinkerIterator(PClass *type, int statnum) { - return Create(type, statnum); + return Create(&level, type, statnum); } DEFINE_ACTION_FUNCTION_NATIVE(DThinkerIterator, Create, CreateThinkerIterator) @@ -59,7 +59,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(DThinkerIterator, Create, CreateThinkerIterator) PARAM_PROLOGUE; PARAM_CLASS(type, DThinker); PARAM_INT(statnum); - ACTION_RETURN_OBJECT(Create(type, statnum)); + ACTION_RETURN_OBJECT(CreateThinkerIterator(type, statnum)); } static DThinker *NextThinker(DThinkerIterator *self, bool exact)