Script reloading does not clear local variable defaults

The defaults are filled in by the preparser, which is only invoked for
changed scripts.
Günther Brammer 2011-10-04 22:16:27 +02:00
parent 8185d318bf
commit b3aff643f3
5 changed files with 50 additions and 35 deletions

View File

@ -121,39 +121,6 @@ bool C4Def::LoadDefCore(C4Group &hGroup)
if ((PictureRect.Wdt==0) || (PictureRect.Hgt==0))
PictureRect.Set(0,0,Shape.Wdt,Shape.Hgt);
// Check category
if (!GetPlane() && Category & (C4D_SortLimit | C4D_BackgroundOrForeground))
{
int Plane; bool gotplane = true;
switch (Category & (C4D_SortLimit | C4D_BackgroundOrForeground))
{
case C4D_StaticBack: Plane = 100; break;
case C4D_Structure: Plane = C4Plane_Structure; break;
case C4D_Vehicle: Plane = 300; break;
case C4D_Living: Plane = 400; break;
case C4D_Object: Plane = 500; break;
case C4D_StaticBack | C4D_Background: Plane = -500; break;
case C4D_Structure | C4D_Background: Plane = -400; break;
case C4D_Vehicle | C4D_Background: Plane = -300; break;
case C4D_Living | C4D_Background: Plane = -200; break;
case C4D_Object | C4D_Background: Plane = -100; break;
case C4D_StaticBack | C4D_Foreground: Plane = 1100; break;
case C4D_Structure | C4D_Foreground: Plane = 1200; break;
case C4D_Vehicle | C4D_Foreground: Plane = 1300; break;
case C4D_Living | C4D_Foreground: Plane = 1400; break;
case C4D_Object | C4D_Foreground: Plane = 1500; break;
default:
DebugLogF("WARNING: Def %s (%s) at %s has invalid category!", GetName(), id.ToString(), hGroup.GetFullName().getData());
gotplane = false;
break;
}
if (gotplane) SetProperty(P_Plane, C4VInt(Plane));
}
if (!GetPlane())
{
DebugLogF("WARNING: Def %s (%s) at %s has invalid Plane!", GetName(), id.ToString(), hGroup.GetFullName().getData());
SetProperty(P_Plane, C4VInt(60));
}
// Check mass
if (Mass < 0)
{

View File

@ -161,7 +161,6 @@ void C4AulScript::UnLink()
// do not unlink temporary (e.g., DirectExec-script in ReloadDef)
if (Temporary) return;
if (GetPropList()) GetPropList()->C4PropList::Clear();
// delete included/appended functions
C4AulFunc* pFunc = Func0;

View File

@ -825,6 +825,13 @@ bool C4ScriptHost::Preparse()
// clear stuff
Includes.clear(); Appends.clear();
if (GetPropList())
{
GetPropList()->C4PropList::Clear();
GetPropList()->SetProperty(P_Prototype, C4VPropList(Engine->GetPropList()));
}
// reset code
ClearCode();
while (Func0)

View File

@ -119,6 +119,47 @@ void C4ScriptHost::SetError(const char *szMessage)
/*--- C4DefScriptHost ---*/
bool C4DefScriptHost::Load(C4Group & g, const char * f, const char * l, C4LangStringTable * t)
{
bool r = C4ScriptHost::Load(g, f, l, t);
assert(Def);
// Check category
if (!Def->GetPlane() && Def->Category & (C4D_SortLimit | C4D_BackgroundOrForeground))
{
int Plane; bool gotplane = true;
switch (Def->Category & (C4D_SortLimit | C4D_BackgroundOrForeground))
{
case C4D_StaticBack: Plane = 100; break;
case C4D_Structure: Plane = C4Plane_Structure; break;
case C4D_Vehicle: Plane = 300; break;
case C4D_Living: Plane = 400; break;
case C4D_Object: Plane = 500; break;
case C4D_StaticBack | C4D_Background: Plane = -500; break;
case C4D_Structure | C4D_Background: Plane = -400; break;
case C4D_Vehicle | C4D_Background: Plane = -300; break;
case C4D_Living | C4D_Background: Plane = -200; break;
case C4D_Object | C4D_Background: Plane = -100; break;
case C4D_StaticBack | C4D_Foreground: Plane = 1100; break;
case C4D_Structure | C4D_Foreground: Plane = 1200; break;
case C4D_Vehicle | C4D_Foreground: Plane = 1300; break;
case C4D_Living | C4D_Foreground: Plane = 1400; break;
case C4D_Object | C4D_Foreground: Plane = 1500; break;
default:
DebugLogF("WARNING: Def %s (%s) at %s has invalid category!", Def->GetName(), Def->id.ToString(), g.GetFullName().getData());
gotplane = false;
break;
}
if (gotplane) Def->SetProperty(P_Plane, C4VInt(Plane));
}
if (!Def->GetPlane())
{
DebugLogF("WARNING: Def %s (%s) at %s has invalid Plane!", Def->GetName(), Def->id.ToString(), g.GetFullName().getData());
Def->SetProperty(P_Plane, C4VInt(1));
}
return r;
}
void C4DefScriptHost::AfterLink()
{
C4AulScript::AfterLink();

View File

@ -36,7 +36,7 @@ public:
bool Delete() { return true; }
public:
void Clear();
bool Load(C4Group &hGroup, const char *szFilename,
virtual bool Load(C4Group &hGroup, const char *szFilename,
const char *szLanguage, C4LangStringTable *pLocalTable);
const char *GetScript() const { return Script.getData(); }
virtual C4ScriptHost * GetScriptHost() { return this; }
@ -75,6 +75,7 @@ public:
void Clear() { SFn_CalcValue = SFn_SellTo = SFn_ControlTransfer = NULL; C4ScriptHost::Clear(); }
bool Delete() { return false; } // do NOT delete this - it's just a class member!
virtual bool Load(C4Group &, const char *, const char *, C4LangStringTable *);
virtual C4PropList * GetPropList();
protected:
C4Def *Def; // owning def file