- eliminated the two global FraggleScript variables by moving them into DFraggleThinker.

This commit is contained in:
Christoph Oelckers 2018-12-29 01:18:21 +01:00
parent 496dd4ee68
commit f31b1b92c9
9 changed files with 27 additions and 69 deletions

View file

@ -2713,7 +2713,6 @@ void D_DoomMain (void)
S_Shutdown(); // free all channels and delete playlist
C_ClearAliases(); // CCMDs won't be reinitialized so these need to be deleted here
DestroyCVarsFlagged(CVAR_MOD); // Delete any cvar left by mods
FS_Close(); // destroy the global FraggleScript.
DeinitMenus();
LightDefaults.DeleteAndClear(); // this can leak heap memory if it isn't cleared.

View file

@ -11,6 +11,5 @@ void T_PreprocessScripts();
void T_LoadScripts(MapData * map);
void T_AddSpawnedThing(AActor * );
bool T_RunScript(int snum, AActor * t_trigger);
void FS_Close();
#endif

View file

@ -4046,16 +4046,16 @@ void FParser::SF_ScriptRunning()
//
//==========================================================================
static int zoom=1; // Dummy - no longer needed!
void init_functions(void)
void DFraggleThinker::InitFunctions()
{
cycle_t clock;
for(unsigned i=0;i<countof(ActorNames_init);i++)
{
ActorTypes[i]=PClass::FindActor(ActorNames_init[i]);
}
DFsScript * gscr = global_script;
DFsScript * gscr = GlobalScript;
// add all the functions
gscr->NewVariable("consoleplayer", svt_pInt)->value.pI = &consoleplayer;

View file

@ -34,8 +34,6 @@
#include "g_levellocals.h"
#include "xlat/xlat.h"
void T_Init();
class FScriptLoader
{
enum
@ -253,8 +251,8 @@ bool FScriptLoader::ParseInfo(MapData * map)
}
if (HasScripts)
{
Create<DFraggleThinker>();
DFraggleThinker::ActiveThinker->LevelScript->data = copystring(scriptsrc.GetChars());
auto th = Create<DFraggleThinker>();
th->LevelScript->data = copystring(scriptsrc.GetChars());
if (drownflag==-1) drownflag = (level.maptype != MAPTYPE_DOOM || fsglobal);
if (!drownflag) level.airsupply=0; // Legacy doesn't to water damage so we need to check if it has to be disabled here.
@ -276,8 +274,6 @@ void T_LoadScripts(MapData *map)
{
FScriptLoader parser;
T_Init();
bool HasScripts = parser.ParseInfo(map);
// Hack for Legacy compatibility: Since 272 is normally an MBF sky transfer we have to patch it.
@ -289,9 +285,7 @@ void T_LoadScripts(MapData *map)
if ((gameinfo.gametype == GAME_Doom || gameinfo.gametype == GAME_Heretic) && level.info->Translator.IsEmpty() &&
level.maptype == MAPTYPE_DOOM && SimpleLineTranslations.Size() > 272 && SimpleLineTranslations[272 - 2*HasScripts].special == FS_Execute)
{
FLineTrans t = SimpleLineTranslations[270];
SimpleLineTranslations[270] = SimpleLineTranslations[272];
SimpleLineTranslations[272] = t;
std::swap(SimpleLineTranslations[270], SimpleLineTranslations[272]);
}
}

View file

@ -40,19 +40,6 @@
#include "serializer.h"
#include "g_levellocals.h"
//==========================================================================
//
// global variables
// These two are the last remaining ones:
// - The global script contains static data so it must be global
// - The trigger is referenced by a global variable. However, it is set
// each time a script is started so that's not a problem.
//
//==========================================================================
DFsScript *global_script;
AActor *trigger_obj;
//==========================================================================
//
//
@ -190,7 +177,7 @@ void DFsScript::Serialize(FSerializer &arc)
{
Super::Serialize(arc);
// don't save a reference to the global script
if (parent == global_script) parent = nullptr;
if (parent == DFraggleThinker::ActiveThinker->GlobalScript) parent = nullptr;
arc("data", data)
("scriptnum", scriptnum)
@ -202,7 +189,7 @@ void DFsScript::Serialize(FSerializer &arc)
.Array("variables", variables, VARIABLESLOTS)
.Array("children", children, MAXSCRIPTS);
if (parent == nullptr) parent = global_script;
if (parent == nullptr) parent = DFraggleThinker::ActiveThinker->GlobalScript;
}
//==========================================================================
@ -228,7 +215,7 @@ void DFsScript::ParseScript(char *position)
return;
}
trigger_obj = trigger; // set trigger
DFraggleThinker::ActiveThinker->trigger_obj = trigger; // set trigger
try
{
@ -369,6 +356,7 @@ IMPLEMENT_CLASS(DFraggleThinker, false, true)
IMPLEMENT_POINTERS_START(DFraggleThinker)
IMPLEMENT_POINTER(RunningScripts)
IMPLEMENT_POINTER(LevelScript)
IMPLEMENT_POINTER(GlobalScript)
IMPLEMENT_POINTERS_END
TObjPtr<DFraggleThinker*> DFraggleThinker::ActiveThinker;
@ -390,10 +378,13 @@ DFraggleThinker::DFraggleThinker()
{
ActiveThinker = this;
RunningScripts = Create<DRunningScript>();
LevelScript = Create<DFsScript>();
LevelScript->parent = global_script;
GC::WriteBarrier(this, RunningScripts);
GlobalScript = Create<DFsScript>();
GC::WriteBarrier(this, GlobalScript);
LevelScript = Create<DFsScript>();
LevelScript->parent = GlobalScript;
GC::WriteBarrier(this, LevelScript);
InitFunctions();
}
}
@ -415,6 +406,9 @@ void DFraggleThinker::OnDestroy()
}
RunningScripts = NULL;
GlobalScript->Destroy();
GlobalScript = NULL;
LevelScript->Destroy();
LevelScript = NULL;
@ -431,6 +425,7 @@ void DFraggleThinker::OnDestroy()
void DFraggleThinker::Serialize(FSerializer &arc)
{
// The global script is not serialized because the data it points to is not serializable.
Super::Serialize(arc);
arc("levelscript", LevelScript)
("runningscripts", RunningScripts)
@ -664,34 +659,6 @@ bool T_RunScript(int snum, AActor * t_trigger)
//
//==========================================================================
void FS_Close()
{
if (global_script != NULL)
{
GC::DelSoftRoot(global_script);
global_script->Destroy();
global_script = NULL;
}
}
void T_Init()
{
void init_functions();
if (global_script == NULL)
{
global_script = Create<DFsScript>();
GC::AddSoftRoot(global_script);
init_functions();
}
}
//==========================================================================
//
//
//
//==========================================================================
CCMD(fpuke)
{
int argc = argv.argc();

View file

@ -678,6 +678,9 @@ class DFraggleThinker : public DThinker
HAS_OBJECT_POINTERS
public:
int zoom = 1;
AActor *trigger_obj; // this is a transient pointer not being subjected to GC.
TObjPtr<DFsScript*> GlobalScript;
TObjPtr<DFsScript*> LevelScript;
TObjPtr<DRunningScript*> RunningScripts;
TArray<TObjPtr<AActor*> > SpawnedThings;
@ -688,6 +691,7 @@ public:
void Serialize(FSerializer & arc);
void Tick();
void InitFunctions();
size_t PropagateMark();
size_t PointerSubstitution (DObject *old, DObject *notOld);
bool wait_finished(DRunningScript *script);
@ -707,9 +711,5 @@ public:
void script_error(const char *s, ...) GCCPRINTF(1,2);
void FS_EmulateCmd(char * string);
extern AActor *trigger_obj;
extern DFsScript *global_script;
#endif

View file

@ -467,7 +467,7 @@ void FParser::EvaluateFunction(svalue_t &result, int start, int stop)
}
// all the functions are stored in the global script
else if( !(func = global_script->VariableForName (Tokens[start])) )
else if( !(func = DFraggleThinker::ActiveThinker->GlobalScript->VariableForName (Tokens[start])) )
{
script_error("no such function: '%s'\n",Tokens[start]);
}
@ -551,7 +551,7 @@ void FParser::OPstructure(svalue_t &result, int start, int n, int stop)
svalue_t argv[MAXARGS];
// all the functions are stored in the global script
if( !(func = global_script->VariableForName (Tokens[n+1])) )
if( !(func = DFraggleThinker::ActiveThinker->GlobalScript->VariableForName (Tokens[n+1])) )
{
script_error("no such function: '%s'\n",Tokens[n+1]);
}

View file

@ -619,7 +619,7 @@ void FBlockLinesIterator::StartBlock(int x, int y)
cury = y;
if (level.blockmap.isValidBlock(x, y))
{
int offset = y*level.blockmap.bmapwidth + x;
unsigned offset = y*level.blockmap.bmapwidth + x;
polyLink = level.PolyBlockMap.Size() > offset? level.PolyBlockMap[offset] : nullptr;
polyIndex = 0;

View file

@ -512,7 +512,6 @@ static void P_Shutdown ()
// [ZZ] delete global event handlers
E_Shutdown(false);
ST_Clear();
FS_Close();
for (auto &p : players)
{
if (p.psprites != nullptr) p.psprites->Destroy();