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