Removed convar stuff from CPlugin, now uses plugin properties for convar listing
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40493
This commit is contained in:
parent
20441b70d3
commit
bb79b1e6a9
@ -12,10 +12,12 @@
|
||||
*/
|
||||
|
||||
#include "CConVarManager.h"
|
||||
#include "CLogger.h"
|
||||
#include "PluginSys.h"
|
||||
#include "ForwardSys.h"
|
||||
#include "HandleSys.h"
|
||||
#include "sm_srvcmds.h"
|
||||
#include "sm_stringutil.h"
|
||||
#include <sh_vector.h>
|
||||
|
||||
CConVarManager g_ConVarManager;
|
||||
|
||||
@ -81,6 +83,17 @@ void CConVarManager::OnSourceModShutdown()
|
||||
g_HandleSys.RemoveType(m_ConVarType, g_pCoreIdent);
|
||||
}
|
||||
|
||||
void CConVarManager::OnPluginDestroyed(IPlugin *plugin)
|
||||
{
|
||||
CVector<ConVar *> *cvarList;
|
||||
|
||||
// If plugin has a convar list, free its memory
|
||||
if (plugin->GetProperty("ConVar", reinterpret_cast<void **>(&cvarList), true))
|
||||
{
|
||||
delete cvarList;
|
||||
}
|
||||
}
|
||||
|
||||
void CConVarManager::OnHandleDestroy(HandleType_t type, void *object)
|
||||
{
|
||||
ConVarInfo *info;
|
||||
@ -116,10 +129,13 @@ void CConVarManager::OnRootConsoleCommand(const char *command, unsigned int argc
|
||||
// Get plugin object
|
||||
CPlugin *pl = g_PluginSys.GetPluginByOrder(num);
|
||||
|
||||
// Get number of convars created by plugin
|
||||
int convarnum = pl->GetConVarCount();
|
||||
CVector<ConVar *> *cvarList = NULL;
|
||||
|
||||
if (convarnum == 0)
|
||||
// Get convar list from 'ConVar' property
|
||||
pl->GetProperty("ConVar", reinterpret_cast<void **>(&cvarList));
|
||||
|
||||
// If no cvar list...
|
||||
if (cvarList == NULL)
|
||||
{
|
||||
g_RootMenu.ConsolePrint("[SM] No convars for \"%s\"", pl->GetPublicInfo()->name);
|
||||
return;
|
||||
@ -128,9 +144,9 @@ void CConVarManager::OnRootConsoleCommand(const char *command, unsigned int argc
|
||||
g_RootMenu.ConsolePrint("[SM] Displaying convars for \"%s\"", pl->GetPublicInfo()->name);
|
||||
|
||||
// Iterate convar list and display each one
|
||||
for (int i = 0; i < convarnum; i++, id++)
|
||||
for (size_t i = 0; i < cvarList->size(); i++, id++)
|
||||
{
|
||||
ConVar *cvar = pl->GetConVarByIndex(i);
|
||||
ConVar *cvar = (*cvarList)[i];
|
||||
g_RootMenu.ConsolePrint(" %02d \"%s\" = \"%s\"", id, cvar->GetName(), cvar->GetString());
|
||||
}
|
||||
|
||||
@ -145,6 +161,7 @@ Handle_t CConVarManager::CreateConVar(IPluginContext *pContext, const char *name
|
||||
{
|
||||
ConVar *cvar = NULL;
|
||||
ConVarInfo *info = NULL;
|
||||
CVector<ConVar *> *cvarList = NULL;
|
||||
Handle_t hndl = 0;
|
||||
|
||||
// Find out if the convar exists already
|
||||
@ -190,8 +207,22 @@ Handle_t CConVarManager::CreateConVar(IPluginContext *pContext, const char *name
|
||||
// Since we didn't find an existing convar (or concmd with the same name), now we can finally create it!
|
||||
cvar = new ConVar(name, defaultVal, flags, helpText, hasMin, min, hasMax, max);
|
||||
|
||||
// Find plugin creating convar
|
||||
IPlugin *pl = g_PluginSys.FindPluginByContext(pContext->GetContext());
|
||||
|
||||
// Get convar list from 'ConVar' property of plugin
|
||||
pl->GetProperty("ConVar", reinterpret_cast<void **>(&cvarList));
|
||||
|
||||
// If 'ConVar' property doesn't exist...
|
||||
if (cvarList == NULL)
|
||||
{
|
||||
// Then create it
|
||||
cvarList = new CVector<ConVar *>;
|
||||
pl->SetProperty("ConVar", cvarList);
|
||||
}
|
||||
|
||||
// Add new convar to plugin's list
|
||||
g_PluginSys.GetPluginByCtx(pContext->GetContext())->AddConVar(cvar);
|
||||
cvarList->push_back(cvar);
|
||||
|
||||
// Create a handle from the new convar
|
||||
hndl = g_HandleSys.CreateHandle(m_ConVarType, cvar, NULL, g_pCoreIdent, NULL);
|
||||
|
@ -16,10 +16,11 @@
|
||||
|
||||
#include "sm_globals.h"
|
||||
#include "sourcemm_api.h"
|
||||
#include "HandleSys.h"
|
||||
#include "ForwardSys.h"
|
||||
#include "sm_trie.h"
|
||||
#include <sh_list.h>
|
||||
#include <IPluginSys.h>
|
||||
#include <IForwardSys.h>
|
||||
#include <IHandleSys.h>
|
||||
#include <IRootConsoleMenu.h>
|
||||
|
||||
using namespace SourceHook;
|
||||
@ -38,6 +39,7 @@ struct ConVarInfo
|
||||
class CConVarManager :
|
||||
public SMGlobalClass,
|
||||
public IHandleTypeDispatch,
|
||||
public IPluginsListener,
|
||||
public IRootConsoleCommand
|
||||
{
|
||||
public:
|
||||
@ -48,6 +50,8 @@ public: // SMGlobalClass
|
||||
void OnSourceModShutdown();
|
||||
public: // IHandleTypeDispatch
|
||||
void OnHandleDestroy(HandleType_t type, void *object);
|
||||
public: // IPluginsListener
|
||||
void OnPluginDestroyed(IPlugin *plugin);
|
||||
public: //IRootConsoleCommand
|
||||
void OnRootConsoleCommand(const char *command, unsigned int argcount);
|
||||
public:
|
||||
|
@ -40,7 +40,7 @@
|
||||
*
|
||||
* The second vector is the identity linked list. An identity has its own handle, so
|
||||
* these handles are used as sentinel nodes for index linking. They point to the first and last
|
||||
* index into the handle array. Each subsequent Handle who is owned by that indentity is mapped into
|
||||
* index into the handle array. Each subsequent Handle who is owned by that identity is mapped into
|
||||
* that list. This lets owning identities be unloaded in O(n) time.
|
||||
*
|
||||
* Eventually, there may be a third list for type chains.
|
||||
|
@ -531,21 +531,6 @@ unsigned int CPlugin::GetLangFileByIndex(unsigned int index) const
|
||||
return m_PhraseFiles.at(index);
|
||||
}
|
||||
|
||||
void CPlugin::AddConVar(ConVar *convar)
|
||||
{
|
||||
m_ConVarList.push_back(convar);
|
||||
}
|
||||
|
||||
size_t CPlugin::GetConVarCount() const
|
||||
{
|
||||
return m_ConVarList.size();
|
||||
}
|
||||
|
||||
ConVar *CPlugin::GetConVarByIndex(size_t index) const
|
||||
{
|
||||
return m_ConVarList.at(index);
|
||||
}
|
||||
|
||||
/*******************
|
||||
* PLUGIN ITERATOR *
|
||||
*******************/
|
||||
|
@ -210,21 +210,6 @@ public:
|
||||
* Returns true if the plugin was running, but is now invalid.
|
||||
*/
|
||||
bool WasRunning();
|
||||
|
||||
/**
|
||||
* Adds a convar to the plugin's list
|
||||
*/
|
||||
void AddConVar(ConVar *convar);
|
||||
|
||||
/**
|
||||
* Get convar count for this plugin.
|
||||
*/
|
||||
size_t GetConVarCount() const;
|
||||
|
||||
/**
|
||||
* Get convar pointer based on the vector index.
|
||||
*/
|
||||
ConVar *GetConVarByIndex(size_t index) const;
|
||||
protected:
|
||||
void UpdateInfo();
|
||||
void SetTimeStamp(time_t t);
|
||||
@ -242,7 +227,6 @@ private:
|
||||
Handle_t m_handle;
|
||||
bool m_WasRunning;
|
||||
CVector<unsigned int> m_PhraseFiles;
|
||||
CVector<ConVar *> m_ConVarList;
|
||||
Trie *m_pProps;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user