- fix handling of the global script in FraggleScript.

Depending on serialization order is not a good idea here, so now it's no longer stored as a parent in the main level script but explicitly checked for when looking for a variable.
This commit is contained in:
Christoph Oelckers 2019-01-27 21:03:25 +01:00
parent 4d98c10ea3
commit 11c453a71f
5 changed files with 25 additions and 22 deletions

View file

@ -31,6 +31,7 @@
/* includes ************************/
#include "t_script.h"
#include "g_levellocals.h"
#define evaluate_leftnright(a, b, c) {\
@ -84,7 +85,7 @@ void FParser::OPequals(svalue_t &result, int start, int n, int stop)
{
DFsVariable *var;
var = Script->FindVariable(Tokens[start]);
var = Script->FindVariable(Tokens[start], Level->FraggleScriptThinker->GlobalScript);
if(var)
{
@ -478,7 +479,7 @@ void FParser::OPincrement(svalue_t &result, int start, int n, int stop)
{
DFsVariable *var;
var = Script->FindVariable(Tokens[stop]);
var = Script->FindVariable(Tokens[stop], Level->FraggleScriptThinker->GlobalScript);
if(!var)
{
script_error("unknown variable '%s'\n", Tokens[stop]);
@ -503,7 +504,7 @@ void FParser::OPincrement(svalue_t &result, int start, int n, int stop)
svalue_t newvalue;
DFsVariable *var;
var = Script->FindVariable(Tokens[start]);
var = Script->FindVariable(Tokens[start], Level->FraggleScriptThinker->GlobalScript);
if(!var)
{
script_error("unknown variable '%s'\n", Tokens[start]);
@ -541,7 +542,7 @@ void FParser::OPdecrement(svalue_t &result, int start, int n, int stop)
{
DFsVariable *var;
var = Script->FindVariable(Tokens[stop]);
var = Script->FindVariable(Tokens[stop], Level->FraggleScriptThinker->GlobalScript);
if(!var)
{
script_error("unknown variable '%s'\n", Tokens[stop]);
@ -567,7 +568,7 @@ void FParser::OPdecrement(svalue_t &result, int start, int n, int stop)
svalue_t newvalue;
DFsVariable *var;
var = Script->FindVariable(Tokens[start]);
var = Script->FindVariable(Tokens[start], Level->FraggleScriptThinker->GlobalScript);
if(!var)
{
script_error("unknown variable '%s'\n", Tokens[start]);

View file

@ -34,7 +34,7 @@
#include <stdarg.h>
#include "t_script.h"
#include "v_text.h"
#include "g_levellocals.h"""
CVAR(Bool, script_debug, false, 0)
@ -561,7 +561,7 @@ void FParser::SimpleEvaluate(svalue_t &returnvar, int n)
break;
case name_:
var = Script->FindVariable(Tokens[n]);
var = Script->FindVariable(Tokens[n], Level->FraggleScriptThinker->GlobalScript);
if(!var)
{
script_error("unknown variable '%s'\n", Tokens[n]);

View file

@ -176,8 +176,6 @@ void DFsScript::OnDestroy()
void DFsScript::Serialize(FSerializer &arc)
{
Super::Serialize(arc);
// don't save a reference to the global script, which contains unserializable data.
if (parent == level.FraggleScriptThinker->GlobalScript) parent = nullptr;
arc("data", data)
("scriptnum", scriptnum)
@ -188,8 +186,6 @@ void DFsScript::Serialize(FSerializer &arc)
.Array("sections", sections, SECTIONSLOTS)
.Array("variables", variables, VARIABLESLOTS)
.Array("children", children, MAXSCRIPTS);
if (parent == nullptr) parent = level.FraggleScriptThinker->GlobalScript;
}
//==========================================================================
@ -200,7 +196,7 @@ void DFsScript::Serialize(FSerializer &arc)
//
//==========================================================================
void DFsScript::ParseScript(char *position)
void DFsScript::ParseScript(char *position, AActor **pTrigger)
{
if (position == nullptr)
{
@ -215,7 +211,7 @@ void DFsScript::ParseScript(char *position)
return;
}
level.FraggleScriptThinker->trigger_obj = trigger; // set trigger
*pTrigger = trigger; // set trigger variable.
try
{
@ -387,7 +383,7 @@ void DFraggleThinker::Construct()
RunningScripts = Create<DRunningScript>();
GC::WriteBarrier(this, RunningScripts);
LevelScript = Create<DFsScript>();
LevelScript->parent = GlobalScript;
LevelScript->parent = nullptr;
GC::WriteBarrier(this, LevelScript);
}
@ -465,10 +461,10 @@ bool DFraggleThinker::wait_finished(DRunningScript *script)
case wt_tagwait:
{
int secnum;
auto itr = level.GetSectorTagIterator(script->wait_data);
auto itr = Level->GetSectorTagIterator(script->wait_data);
while ((secnum = itr.Next()) >= 0)
{
sector_t *sec = &level.sectors[secnum];
sector_t *sec = &Level->sectors[secnum];
if(sec->floordata || sec->ceilingdata || sec->lightingdata)
return false; // not finished
}
@ -532,7 +528,7 @@ void DFraggleThinker::Tick()
next = current->next; // save before freeing
// continue the script
current->script->ParseScript (current->script->data + current->save_point);
current->script->ParseScript (current->script->data + current->save_point, &trigger_obj);
// free
current->Destroy();
@ -623,7 +619,7 @@ void T_PreprocessScripts(FLevelLocals *Level)
th->LevelScript->trigger = players[0].mo;
th->LevelScript->Preprocess();
th->LevelScript->ParseScript();
th->LevelScript->ParseScript(nullptr, &th->trigger_obj);
}
}

View file

@ -341,7 +341,7 @@ public:
void NewFunction(const char *name, void (FParser::*handler)());
DFsVariable *VariableForName(const char *name);
DFsVariable *FindVariable(const char *name);
DFsVariable *FindVariable(const char *name, DFsScript *global);
void ClearVariables(bool complete= false);
DFsVariable *NewLabel(char *labelptr);
char *LabelValue(const svalue_t &v);
@ -363,7 +363,7 @@ public:
void DryRunScript();
void Preprocess();
void ParseInclude(char *lumpname);
void ParseScript(char *rover = NULL);
void ParseScript(char *rover, AActor **pTrigger);
void ParseData(char *rover, char *data, char *end);
};

View file

@ -364,7 +364,7 @@ DFsVariable *DFsScript::VariableForName(const char *name)
//
//==========================================================================
DFsVariable *DFsScript::FindVariable(const char *name)
DFsVariable *DFsScript::FindVariable(const char *name, DFsScript *GlobalScript)
{
DFsVariable *var;
DFsScript *current = this;
@ -374,7 +374,13 @@ DFsVariable *DFsScript::FindVariable(const char *name)
// check this script
if ((var = current->VariableForName(name)))
return var;
current = current->parent; // try the parent of this one
// Since the global script cannot be serialized, we cannot store a pointer to it, because this cannot be safely restored during deserialization.
// To compensate we need to check the relationship explicitly here.
if (current->parent == nullptr && current != GlobalScript)
current = GlobalScript;
else
current = current->parent; // try the parent of this one
}
return NULL; // no variable