Remove some redundant Default methods

Using the same method for the constructing and clearing an instance just
leads to leaks and subtle bugs.
Günther Brammer 2011-03-05 03:24:11 +01:00
parent 01e9dce9ce
commit f4ee636072
7 changed files with 8 additions and 47 deletions

View File

@ -647,7 +647,6 @@ void C4Game::Clear()
QuitLogPos = GetLogPos(); QuitLogPos = GetLogPos();
fPreinited = false; fPreinited = false;
::GameScript.Default();
// FIXME: remove this // FIXME: remove this
Default(); Default();
} }

View File

@ -28,21 +28,6 @@
#include <C4Application.h> #include <C4Application.h>
#include <StdRegistry.h> #include <StdRegistry.h>
C4ComponentHost::C4ComponentHost()
{
}
C4ComponentHost::~C4ComponentHost()
{
Clear();
}
void C4ComponentHost::Clear()
{
Data.Clear();
OnLoad();
}
bool C4ComponentHost::Load(C4Group &hGroup, bool C4ComponentHost::Load(C4Group &hGroup,
const char *fname, const char *fname,
const char *szLanguage) const char *szLanguage)

View File

@ -28,10 +28,10 @@
class C4ComponentHost class C4ComponentHost
{ {
public: public:
C4ComponentHost(); C4ComponentHost() { }
virtual ~C4ComponentHost(); virtual ~C4ComponentHost() { Clear(); }
const char *GetFilePath() const { return FilePath.getData(); } const char *GetFilePath() const { return FilePath.getData(); }
void Clear(); void Clear() { Data.Clear(); OnLoad(); }
const char *GetData() const { return Data.getData(); } const char *GetData() const { return Data.getData(); }
const StdStrBuf & GetDataBuf() const { return Data; } const StdStrBuf & GetDataBuf() const { return Data; }
size_t GetDataSize() const { return Data.getLength(); } size_t GetDataSize() const { return Data.getLength(); }

View File

@ -336,7 +336,7 @@ void C4Def::Default()
Count=0; Count=0;
TimerCall=NULL; TimerCall=NULL;
MainFace.Set(NULL,0,0,0,0); MainFace.Set(NULL,0,0,0,0);
Script.Default(); Script.Clear();
StringTable.Clear(); StringTable.Clear();
pClonkNames=NULL; pClonkNames=NULL;
pRankNames=NULL; pRankNames=NULL;

View File

@ -163,7 +163,6 @@ StdStrBuf C4AulScriptFunc::GetFullName()
C4AulScript::C4AulScript() C4AulScript::C4AulScript()
{ {
// init defaults
// not compiled // not compiled
State = ASS_NONE; State = ASS_NONE;
Script = NULL; Script = NULL;

View File

@ -34,15 +34,9 @@
/*--- C4ScriptHost ---*/ /*--- C4ScriptHost ---*/
C4ScriptHost::C4ScriptHost() { Default(); } C4ScriptHost::C4ScriptHost() { }
C4ScriptHost::~C4ScriptHost() { Clear(); } C4ScriptHost::~C4ScriptHost() { Clear(); }
void C4ScriptHost::Default()
{
C4AulScript::Clear();
ComponentHost.Clear();
}
void C4ScriptHost::Clear() void C4ScriptHost::Clear()
{ {
C4AulScript::Clear(); C4AulScript::Clear();
@ -118,12 +112,6 @@ void C4ScriptHost::SetError(const char *szMessage)
/*--- C4DefScriptHost ---*/ /*--- C4DefScriptHost ---*/
void C4DefScriptHost::Default()
{
C4ScriptHost::Default();
SFn_CalcValue = SFn_SellTo = SFn_ControlTransfer = SFn_CustomComponents = NULL;
}
void C4DefScriptHost::AfterLink() void C4DefScriptHost::AfterLink()
{ {
C4AulScript::AfterLink(); C4AulScript::AfterLink();
@ -146,14 +134,6 @@ void C4DefScriptHost::AfterLink()
C4GameScriptHost::C4GameScriptHost(): Counter(0), Go(false) { } C4GameScriptHost::C4GameScriptHost(): Counter(0), Go(false) { }
C4GameScriptHost::~C4GameScriptHost() { } C4GameScriptHost::~C4GameScriptHost() { }
void C4GameScriptHost::Default()
{
C4ScriptHost::Default();
Counter=0;
Go=false;
}
bool C4GameScriptHost::Execute() bool C4GameScriptHost::Execute()
{ {
if (!Script) return false; if (!Script) return false;

View File

@ -40,7 +40,6 @@ public:
~C4ScriptHost(); ~C4ScriptHost();
bool Delete() { return true; } bool Delete() { return true; }
public: public:
void Default();
void Clear(); void Clear();
bool Load(C4Group &hGroup, const char *szFilename, bool Load(C4Group &hGroup, const char *szFilename,
const char *szLanguage/*=NULL*/, C4Def *pDef/*=NULL*/, class C4LangStringTable *pLocalTable); const char *szLanguage/*=NULL*/, C4Def *pDef/*=NULL*/, class C4LangStringTable *pLocalTable);
@ -57,9 +56,8 @@ protected:
class C4DefScriptHost : public C4ScriptHost class C4DefScriptHost : public C4ScriptHost
{ {
public: public:
C4DefScriptHost() : C4ScriptHost() { Default(); } C4DefScriptHost() : C4ScriptHost() { SFn_CalcValue = SFn_SellTo = SFn_ControlTransfer = SFn_CustomComponents = NULL; }
void Clear() { SFn_CalcValue = SFn_SellTo = SFn_ControlTransfer = SFn_CustomComponents = NULL; C4ScriptHost::Clear(); }
void Default();
bool Delete() { return false; } // do NOT delete this - it's just a class member! bool Delete() { return false; } // do NOT delete this - it's just a class member!
protected: protected:
@ -79,7 +77,6 @@ public:
C4GameScriptHost(); C4GameScriptHost();
~C4GameScriptHost(); ~C4GameScriptHost();
bool Delete() { return false; } // do NOT delete this - it's a global! bool Delete() { return false; } // do NOT delete this - it's a global!
void Default();
C4Value GRBroadcast(const char *szFunction, C4AulParSet *pPars = 0, bool fPassError=false, bool fRejectTest=false); // call function in scenario script and all goals/rules/environment objects C4Value GRBroadcast(const char *szFunction, C4AulParSet *pPars = 0, bool fPassError=false, bool fRejectTest=false); // call function in scenario script and all goals/rules/environment objects
// Global script data // Global script data
@ -87,6 +84,7 @@ public:
int32_t Counter; int32_t Counter;
bool Go; bool Go;
bool Execute(); bool Execute();
void Clear() { Counter = 0; Go = false; C4ScriptHost::Clear(); }
// Compile scenario script data // Compile scenario script data
void CompileFunc(StdCompiler *pComp); void CompileFunc(StdCompiler *pComp);