Make C4ScriptHost have a C4ComponentHost member instead of inheriting

Previously, C4ScriptHost needlessly derived from two classes.
Günther Brammer 2011-02-06 21:37:19 +01:00
parent 489ae8c5b3
commit 7be90977bf
8 changed files with 28 additions and 24 deletions

View File

@ -1947,7 +1947,7 @@ bool C4Game::ReloadFile(const char *szFile)
if ((pDef = ::Definitions.GetByPath(szRelativePath)))
return ReloadDef(pDef->id);
// script?
if (ScriptEngine.ReloadScript(szRelativePath, &::Definitions))
if (ScriptEngine.ReloadScript(szRelativePath, &::Definitions, Config.General.LanguageEx))
{
return true;
}

View File

@ -53,13 +53,14 @@ void C4ComponentHost::Clear()
}
bool C4ComponentHost::Load(C4Group &hGroup,
const char *szFilename,
const char *fname,
const char *szLanguage)
{
// Clear any old stuff
Clear();
// Store filename
SCopy(szFilename, Filename);
if (fname)
SCopy(fname, Filename);
// Load component - try all segmented filenames
char strEntry[_MAX_FNAME+1], strEntryWithLanguage[_MAX_FNAME+1];
for (int iFilename = 0; SCopySegment(Filename, iFilename, strEntry, '|'); iFilename++)
@ -99,13 +100,14 @@ bool C4ComponentHost::Load(C4Group &hGroup,
}
bool C4ComponentHost::Load(C4GroupSet &hGroupSet,
const char *szFilename,
const char *fname,
const char *szLanguage)
{
// Clear any old stuff
Clear();
// Store filename
SCopy(szFilename, Filename);
if (fname)
SCopy(fname, Filename);
// Load component - try all segmented filenames
char strEntry[_MAX_FNAME+1], strEntryWithLanguage[_MAX_FNAME+1];
for (int iFilename = 0; SCopySegment(Filename, iFilename, strEntry, '|'); iFilename++)

View File

@ -33,6 +33,7 @@ public:
void Default();
void Clear();
const char *GetData() const { return Data.getData(); }
const StdStrBuf & GetDataBuf() const { return Data; }
size_t GetDataSize() const { return Data.getLength(); }
bool Load(C4Group &hGroup, const char *szFilename, const char *szLanguage=NULL);
bool Load(C4GroupSet &hGroupSet, const char *szFilename, const char *szLanguage=NULL);

View File

@ -520,7 +520,7 @@ protected:
void AppendTo(C4AulScript &Scr, bool bHighPrio); // append to given script
void UnLink(); // reset to unlinked state
virtual void AfterLink(); // called after linking is completed; presearch common funcs here
virtual bool ReloadScript(const char *szPath); // reload given script
virtual bool ReloadScript(const char *szPath, const char *szLanguage); // reload given script
C4AulScript *FindFirstNonStrictScript(); // find first script that is not #strict
@ -561,7 +561,7 @@ public:
void Link(C4DefList *rDefs); // link and parse all scripts
void ReLink(C4DefList *rDefs); // unlink + relink and parse all scripts
using C4AulScript::ReloadScript;
bool ReloadScript(const char *szScript, C4DefList *pDefs); // search script and reload + relink, if found
bool ReloadScript(const char *szScript, C4DefList *pDefs, const char *szLanguage); // search script and reload + relink, if found
C4AulFunc * GetFirstFunc(const char * Name)
{ return FuncLookUp.GetFirstFunc(Name); }
C4AulFunc * GetFunc(const char * Name, const C4AulScript * Owner, const C4AulFunc * After)

View File

@ -212,11 +212,11 @@ void C4AulScript::AfterLink()
for (C4AulScript *s = Child0; s; s = s->Next) s->AfterLink();
}
bool C4AulScript::ReloadScript(const char *szPath)
bool C4AulScript::ReloadScript(const char *szPath, const char *szLanguage)
{
// call for childs
for (C4AulScript *s = Child0; s; s = s->Next)
if (s->ReloadScript(szPath))
if (s->ReloadScript(szPath, szLanguage))
return true;
return false;
}
@ -305,10 +305,10 @@ void C4AulScriptEngine::ReLink(C4DefList *rDefs)
::MaterialMap.UpdateScriptPointers();
}
bool C4AulScriptEngine::ReloadScript(const char *szScript, C4DefList *pDefs)
bool C4AulScriptEngine::ReloadScript(const char *szScript, C4DefList *pDefs, const char *szLanguage)
{
// reload
if (!C4AulScript::ReloadScript(szScript))
if (!C4AulScript::ReloadScript(szScript, szLanguage))
return false;
// relink
ReLink(pDefs);

View File

@ -3112,7 +3112,7 @@ bool C4AulScript::Parse()
{
C4ScriptHost * scripthost = 0;
if (Def) scripthost = &Def->Script;
if (scripthost) fprintf(stderr, "parsing %s...\n", scripthost->GetFilePath());
if (scripthost) fprintf(stderr, "parsing %s...\n", scripthost->ScriptName.getData());
else fprintf(stderr, "parsing unknown...\n");
}
// parse children

View File

@ -40,13 +40,13 @@ C4ScriptHost::~C4ScriptHost() { Clear(); }
void C4ScriptHost::Default()
{
C4AulScript::Default();
C4ComponentHost::Default();
ComponentHost.Default();
}
void C4ScriptHost::Clear()
{
C4AulScript::Clear();
C4ComponentHost::Clear();
ComponentHost.Clear();
}
bool C4ScriptHost::Load(C4Group &hGroup, const char *szFilename,
@ -55,14 +55,14 @@ bool C4ScriptHost::Load(C4Group &hGroup, const char *szFilename,
// Set definition and id
Def = pDef;
// Base load
bool fSuccess = C4ComponentHost::Load(hGroup,szFilename,szLanguage);
bool fSuccess = ComponentHost.Load(hGroup,szFilename,szLanguage);
// String Table
stringTable = pLocalTable;
// load it if specified
if (stringTable && fLoadTable)
stringTable->LoadEx(hGroup, C4CFN_ScriptStringTbl, szLanguage);
// set name
ScriptName.Format("%s" DirSep "%s", hGroup.GetFullName().getData(), Filename);
ScriptName.Ref(ComponentHost.GetFilePath());
// preparse script
MakeScript();
// Success
@ -78,11 +78,11 @@ void C4ScriptHost::MakeScript()
// create script
if (stringTable)
{
stringTable->ReplaceStrings(Data, Script, FilePath);
stringTable->ReplaceStrings(ComponentHost.GetDataBuf(), Script, ComponentHost.GetFilePath());
}
else
{
Script.Ref(Data);
Script.Ref(ComponentHost.GetDataBuf());
}
// preparse script
@ -127,20 +127,20 @@ C4Value C4ScriptHost::Call(const char *szFunction, C4Object *pObj, C4AulParSet *
return pFn->Exec(pObj,Pars, fPassError);
}
bool C4ScriptHost::ReloadScript(const char *szPath)
bool C4ScriptHost::ReloadScript(const char *szPath, const char *szLanguage)
{
// this?
if (SEqualNoCase(szPath, FilePath) || (stringTable && SEqualNoCase(szPath, stringTable->GetFilePath())))
if (SEqualNoCase(szPath, ComponentHost.GetFilePath()) || (stringTable && SEqualNoCase(szPath, stringTable->GetFilePath())))
{
// try reload
char szParentPath[_MAX_PATH + 1]; C4Group ParentGrp;
if (GetParentPath(szPath, szParentPath))
if (ParentGrp.Open(szParentPath))
if (Load(ParentGrp, Filename, Config.General.Language, NULL, stringTable))
if (Load(ParentGrp, NULL, szLanguage, NULL, stringTable))
return true;
}
// call for childs
return C4AulScript::ReloadScript(szPath);
return C4AulScript::ReloadScript(szPath, szLanguage);
}
void C4ScriptHost::SetError(const char *szMessage)

View File

@ -33,7 +33,7 @@ const int32_t C4SCR_MaxIDLen = 100,
// generic script host for objects
class C4ScriptHost : public C4AulScript, public C4ComponentHost
class C4ScriptHost : public C4AulScript
{
public:
C4ScriptHost();
@ -51,7 +51,8 @@ public:
protected:
void SetError(const char *szMessage);
void MakeScript();
bool ReloadScript(const char *szPath);
bool ReloadScript(const char *szPath, const char *szLanguage);
C4ComponentHost ComponentHost;
};