Clean up CPlugin member variables.
This commit is contained in:
parent
3430962cbe
commit
2adae27557
@ -52,23 +52,26 @@ HandleType_t g_PluginType = 0;
|
||||
IdentityType_t g_PluginIdent = 0;
|
||||
|
||||
CPlugin::CPlugin(const char *file)
|
||||
: m_serial(0),
|
||||
m_status(Plugin_Uncompiled),
|
||||
m_SilentFailure(false),
|
||||
m_FakeNativesMissing(false),
|
||||
m_LibraryMissing(false),
|
||||
m_pContext(nullptr),
|
||||
m_MaxClientsVar(nullptr),
|
||||
m_ident(nullptr),
|
||||
m_bGotAllLoaded(false),
|
||||
m_FileVersion(0),
|
||||
m_LastAccess(0),
|
||||
m_handle(BAD_HANDLE)
|
||||
{
|
||||
static int MySerial = 0;
|
||||
|
||||
m_type = PluginType_Private;
|
||||
m_status = Plugin_Uncompiled;
|
||||
m_bSilentlyFailed = false;
|
||||
m_serial = ++MySerial;
|
||||
m_pRuntime = NULL;
|
||||
m_errormsg[sizeof(m_errormsg) - 1] = '\0';
|
||||
m_errormsg[0] = '\0';
|
||||
ke::SafeSprintf(m_filename, sizeof(m_filename), "%s", file);
|
||||
m_handle = 0;
|
||||
m_ident = NULL;
|
||||
m_FakeNativesMissing = false;
|
||||
m_LibraryMissing = false;
|
||||
m_bGotAllLoaded = false;
|
||||
|
||||
m_pPhrases = g_Translator.CreatePhraseCollection();
|
||||
m_MaxClientsVar = NULL;
|
||||
}
|
||||
|
||||
CPlugin::~CPlugin()
|
||||
@ -83,22 +86,9 @@ CPlugin::~CPlugin()
|
||||
g_ShareSys.DestroyIdentity(m_ident);
|
||||
}
|
||||
|
||||
if (m_pRuntime != NULL)
|
||||
{
|
||||
delete m_pRuntime;
|
||||
m_pRuntime = NULL;
|
||||
}
|
||||
|
||||
for (size_t i=0; i<m_configs.size(); i++)
|
||||
{
|
||||
delete m_configs[i];
|
||||
}
|
||||
m_configs.clear();
|
||||
if (m_pPhrases != NULL)
|
||||
{
|
||||
m_pPhrases->Destroy();
|
||||
m_pPhrases = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void CPlugin::InitIdentity()
|
||||
@ -120,25 +110,16 @@ unsigned int CPlugin::CalcMemUsage()
|
||||
+ (m_configs.size() * (sizeof(AutoConfig *) + sizeof(AutoConfig)))
|
||||
+ m_Props.mem_usage();
|
||||
|
||||
for (unsigned int i = 0; i < m_configs.size(); i++)
|
||||
{
|
||||
for (unsigned int i = 0; i < m_configs.size(); i++) {
|
||||
base_size += m_configs[i]->autocfg.size();
|
||||
base_size += m_configs[i]->folder.size();
|
||||
}
|
||||
|
||||
for (List<String>::iterator i = m_Libraries.begin();
|
||||
i != m_Libraries.end();
|
||||
i++)
|
||||
{
|
||||
for (auto i = m_Libraries.begin(); i != m_Libraries.end(); i++)
|
||||
base_size += (*i).size();
|
||||
}
|
||||
|
||||
for (List<String>::iterator i = m_RequiredLibs.begin();
|
||||
i != m_RequiredLibs.end();
|
||||
i++)
|
||||
{
|
||||
for (auto i = m_RequiredLibs.begin(); i != m_RequiredLibs.end(); i++)
|
||||
base_size += (*i).size();
|
||||
}
|
||||
|
||||
return base_size;
|
||||
}
|
||||
@ -156,12 +137,9 @@ CPlugin *CPlugin::CreatePlugin(const char *file, char *error, size_t maxlength)
|
||||
|
||||
CPlugin *pPlugin = new CPlugin(file);
|
||||
|
||||
if (!fp)
|
||||
{
|
||||
if (!fp) {
|
||||
if (error)
|
||||
{
|
||||
ke::SafeSprintf(error, maxlength, "Unable to open file");
|
||||
}
|
||||
pPlugin->m_status = Plugin_BadLoad;
|
||||
return pPlugin;
|
||||
}
|
||||
@ -481,7 +459,7 @@ const char *CPlugin::GetFilename()
|
||||
|
||||
PluginType CPlugin::GetType()
|
||||
{
|
||||
return m_type;
|
||||
return PluginType_MapUpdated;
|
||||
}
|
||||
|
||||
const sm_plugininfo_t *CPlugin::GetPublicInfo()
|
||||
@ -505,7 +483,7 @@ PluginStatus CPlugin::GetStatus()
|
||||
|
||||
bool CPlugin::IsSilentlyFailed()
|
||||
{
|
||||
return m_bSilentlyFailed;
|
||||
return m_SilentFailure;
|
||||
}
|
||||
|
||||
bool CPlugin::IsDebugging()
|
||||
@ -518,9 +496,9 @@ bool CPlugin::IsDebugging()
|
||||
return true;
|
||||
}
|
||||
|
||||
void CPlugin::SetSilentlyFailed(bool sf)
|
||||
void CPlugin::SetSilentlyFailed()
|
||||
{
|
||||
m_bSilentlyFailed = sf;
|
||||
m_SilentFailure = true;
|
||||
}
|
||||
|
||||
void CPlugin::LibraryActions(LibraryAction action)
|
||||
@ -922,8 +900,6 @@ LoadRes CPluginManager::_LoadPlugin(CPlugin **aResult, const char *path, bool de
|
||||
pPlugin = CPlugin::CreatePlugin(path, error, maxlength);
|
||||
assert(pPlugin != NULL);
|
||||
|
||||
pPlugin->m_type = PluginType_MapUpdated;
|
||||
|
||||
if (pPlugin->m_status == Plugin_Uncompiled)
|
||||
{
|
||||
char fullpath[PLATFORM_MAX_PATH];
|
||||
@ -1001,7 +977,7 @@ LoadRes CPluginManager::_LoadPlugin(CPlugin **aResult, const char *path, bool de
|
||||
case APLRes_SilentFailure:
|
||||
pPlugin->SetErrorState(Plugin_Failed, "%s", error);
|
||||
loadFailure = LoadRes_SilentFailure;
|
||||
pPlugin->SetSilentlyFailed(true);
|
||||
pPlugin->SetSilentlyFailed();
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
|
@ -50,6 +50,7 @@
|
||||
#include "IGameConfigs.h"
|
||||
#include "NativeOwner.h"
|
||||
#include "ShareSys.h"
|
||||
#include "PhraseCollection.h"
|
||||
#include <bridge/include/IScriptManager.h>
|
||||
|
||||
class CPlayer;
|
||||
@ -140,7 +141,7 @@ public:
|
||||
bool IsDebugging();
|
||||
PluginStatus GetStatus();
|
||||
bool IsSilentlyFailed();
|
||||
void SetSilentlyFailed(bool sf);
|
||||
void SetSilentlyFailed();
|
||||
const sm_plugininfo_t *GetPublicInfo();
|
||||
bool SetPauseState(bool paused);
|
||||
unsigned int GetSerial();
|
||||
@ -251,31 +252,40 @@ protected:
|
||||
bool UpdateInfo();
|
||||
void SetTimeStamp(time_t t);
|
||||
void DependencyDropped(CPlugin *pOwner);
|
||||
|
||||
private:
|
||||
PluginType m_type;
|
||||
// This information is static for the lifetime of the plugin.
|
||||
char m_filename[PLATFORM_MAX_PATH];
|
||||
PluginStatus m_status;
|
||||
bool m_bSilentlyFailed;
|
||||
unsigned int m_serial;
|
||||
sm_plugininfo_t m_info;
|
||||
char m_errormsg[256];
|
||||
time_t m_LastAccess;
|
||||
IdentityToken_t *m_ident;
|
||||
Handle_t m_handle;
|
||||
bool m_WasRunning;
|
||||
IPhraseCollection *m_pPhrases;
|
||||
List<String> m_RequiredLibs;
|
||||
List<String> m_Libraries;
|
||||
StringHashMap<void *> m_Props;
|
||||
|
||||
PluginStatus m_status;
|
||||
|
||||
// Statuses that are set during failure.
|
||||
bool m_SilentFailure;
|
||||
bool m_FakeNativesMissing;
|
||||
bool m_LibraryMissing;
|
||||
CVector<AutoConfig *> m_configs;
|
||||
bool m_bGotAllLoaded;
|
||||
int m_FileVersion;
|
||||
char m_DateTime[256];
|
||||
IPluginRuntime *m_pRuntime;
|
||||
char m_errormsg[256];
|
||||
|
||||
// Internal properties that must by reset if the runtime is evicted.
|
||||
ke::AutoPtr<IPluginRuntime> m_pRuntime;
|
||||
ke::AutoPtr<CPhraseCollection> m_pPhrases;
|
||||
IPluginContext *m_pContext;
|
||||
sp_pubvar_t *m_MaxClientsVar;
|
||||
StringHashMap<void *> m_Props;
|
||||
CVector<AutoConfig *> m_configs;
|
||||
IdentityToken_t *m_ident;
|
||||
bool m_bGotAllLoaded;
|
||||
int m_FileVersion;
|
||||
|
||||
// Information that survives past eviction.
|
||||
List<String> m_RequiredLibs;
|
||||
List<String> m_Libraries;
|
||||
time_t m_LastAccess;
|
||||
Handle_t m_handle;
|
||||
char m_DateTime[256];
|
||||
|
||||
// Cached.
|
||||
sm_plugininfo_t m_info;
|
||||
};
|
||||
|
||||
class CPluginManager :
|
||||
|
@ -991,7 +991,7 @@ unsigned int Translator::GetInterfaceVersion()
|
||||
return SMINTERFACE_TRANSLATOR_VERSION;
|
||||
}
|
||||
|
||||
IPhraseCollection *Translator::CreatePhraseCollection()
|
||||
CPhraseCollection *Translator::CreatePhraseCollection()
|
||||
{
|
||||
return new CPhraseCollection();
|
||||
}
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include "sm_memtable.h"
|
||||
#include "ITextParsers.h"
|
||||
#include <ITranslator.h>
|
||||
#include "PhraseCollection.h"
|
||||
|
||||
/* :TODO: write a templatized version of tries? */
|
||||
|
||||
@ -127,7 +128,7 @@ public: //ITranslator
|
||||
unsigned int GetClientLanguage(int client);
|
||||
const char *GetInterfaceName();
|
||||
unsigned int GetInterfaceVersion();
|
||||
IPhraseCollection *CreatePhraseCollection();
|
||||
CPhraseCollection *CreatePhraseCollection();
|
||||
int SetGlobalTarget(int index);
|
||||
int GetGlobalTarget() const;
|
||||
size_t FormatString(
|
||||
|
Loading…
Reference in New Issue
Block a user