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:
Scott Ehlert 2007-02-14 01:25:45 +00:00
parent 20441b70d3
commit bb79b1e6a9
5 changed files with 45 additions and 41 deletions

View File

@ -12,10 +12,12 @@
*/ */
#include "CConVarManager.h" #include "CConVarManager.h"
#include "CLogger.h"
#include "PluginSys.h" #include "PluginSys.h"
#include "ForwardSys.h"
#include "HandleSys.h"
#include "sm_srvcmds.h" #include "sm_srvcmds.h"
#include "sm_stringutil.h" #include "sm_stringutil.h"
#include <sh_vector.h>
CConVarManager g_ConVarManager; CConVarManager g_ConVarManager;
@ -81,6 +83,17 @@ void CConVarManager::OnSourceModShutdown()
g_HandleSys.RemoveType(m_ConVarType, g_pCoreIdent); 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) void CConVarManager::OnHandleDestroy(HandleType_t type, void *object)
{ {
ConVarInfo *info; ConVarInfo *info;
@ -116,10 +129,13 @@ void CConVarManager::OnRootConsoleCommand(const char *command, unsigned int argc
// Get plugin object // Get plugin object
CPlugin *pl = g_PluginSys.GetPluginByOrder(num); CPlugin *pl = g_PluginSys.GetPluginByOrder(num);
// Get number of convars created by plugin CVector<ConVar *> *cvarList = NULL;
int convarnum = pl->GetConVarCount();
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); g_RootMenu.ConsolePrint("[SM] No convars for \"%s\"", pl->GetPublicInfo()->name);
return; 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); g_RootMenu.ConsolePrint("[SM] Displaying convars for \"%s\"", pl->GetPublicInfo()->name);
// Iterate convar list and display each one // 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()); 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; ConVar *cvar = NULL;
ConVarInfo *info = NULL; ConVarInfo *info = NULL;
CVector<ConVar *> *cvarList = NULL;
Handle_t hndl = 0; Handle_t hndl = 0;
// Find out if the convar exists already // 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! // 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); 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 // 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 // Create a handle from the new convar
hndl = g_HandleSys.CreateHandle(m_ConVarType, cvar, NULL, g_pCoreIdent, NULL); hndl = g_HandleSys.CreateHandle(m_ConVarType, cvar, NULL, g_pCoreIdent, NULL);

View File

@ -16,10 +16,11 @@
#include "sm_globals.h" #include "sm_globals.h"
#include "sourcemm_api.h" #include "sourcemm_api.h"
#include "HandleSys.h"
#include "ForwardSys.h"
#include "sm_trie.h" #include "sm_trie.h"
#include <sh_list.h> #include <sh_list.h>
#include <IPluginSys.h>
#include <IForwardSys.h>
#include <IHandleSys.h>
#include <IRootConsoleMenu.h> #include <IRootConsoleMenu.h>
using namespace SourceHook; using namespace SourceHook;
@ -38,6 +39,7 @@ struct ConVarInfo
class CConVarManager : class CConVarManager :
public SMGlobalClass, public SMGlobalClass,
public IHandleTypeDispatch, public IHandleTypeDispatch,
public IPluginsListener,
public IRootConsoleCommand public IRootConsoleCommand
{ {
public: public:
@ -48,6 +50,8 @@ public: // SMGlobalClass
void OnSourceModShutdown(); void OnSourceModShutdown();
public: // IHandleTypeDispatch public: // IHandleTypeDispatch
void OnHandleDestroy(HandleType_t type, void *object); void OnHandleDestroy(HandleType_t type, void *object);
public: // IPluginsListener
void OnPluginDestroyed(IPlugin *plugin);
public: //IRootConsoleCommand public: //IRootConsoleCommand
void OnRootConsoleCommand(const char *command, unsigned int argcount); void OnRootConsoleCommand(const char *command, unsigned int argcount);
public: public:

View File

@ -40,7 +40,7 @@
* *
* The second vector is the identity linked list. An identity has its own handle, so * 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 * 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. * that list. This lets owning identities be unloaded in O(n) time.
* *
* Eventually, there may be a third list for type chains. * Eventually, there may be a third list for type chains.

View File

@ -531,21 +531,6 @@ unsigned int CPlugin::GetLangFileByIndex(unsigned int index) const
return m_PhraseFiles.at(index); 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 * * PLUGIN ITERATOR *
*******************/ *******************/

View File

@ -210,21 +210,6 @@ public:
* Returns true if the plugin was running, but is now invalid. * Returns true if the plugin was running, but is now invalid.
*/ */
bool WasRunning(); 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: protected:
void UpdateInfo(); void UpdateInfo();
void SetTimeStamp(time_t t); void SetTimeStamp(time_t t);
@ -242,7 +227,6 @@ private:
Handle_t m_handle; Handle_t m_handle;
bool m_WasRunning; bool m_WasRunning;
CVector<unsigned int> m_PhraseFiles; CVector<unsigned int> m_PhraseFiles;
CVector<ConVar *> m_ConVarList;
Trie *m_pProps; Trie *m_pProps;
}; };