core/ConVarManager.h
author Scott Ehlert <ds@alliedmods.net>
Tue Mar 06 06:49:35 2007 +0000 (2007-03-06)
changeset 580 416aecc7de51
child 582 00c843a1bb18
permissions -rw-r--r--
Renamed CConVarManager to ConVarManager
ds@580
     1
/**
ds@580
     2
* ===============================================================
ds@580
     3
* SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
ds@580
     4
* ===============================================================
ds@580
     5
*
ds@580
     6
* This file is not open source and may not be copied without explicit
ds@580
     7
* written permission of AlliedModders LLC.  This file may not be redistributed 
ds@580
     8
* in whole or significant part.
ds@580
     9
* For information, see LICENSE.txt or http://www.sourcemod.net/license.php
ds@580
    10
*
ds@580
    11
* Version: $Id$
ds@580
    12
*/
ds@580
    13
ds@580
    14
#ifndef _INCLUDE_SOURCEMOD_CONVARMANAGER_H_
ds@580
    15
#define _INCLUDE_SOURCEMOD_CONVARMANAGER_H_
ds@580
    16
ds@580
    17
#include "sm_globals.h"
ds@580
    18
#include "sourcemm_api.h"
ds@580
    19
#include "sm_trie.h"
ds@580
    20
#include <sh_list.h>
ds@580
    21
#include <IPluginSys.h>
ds@580
    22
#include <IForwardSys.h>
ds@580
    23
#include <IHandleSys.h>
ds@580
    24
#include <IRootConsoleMenu.h>
ds@580
    25
ds@580
    26
using namespace SourceHook;
ds@580
    27
ds@580
    28
/**
ds@580
    29
 * Holds SourceMod-specific information about a convar
ds@580
    30
 */
ds@580
    31
struct ConVarInfo
ds@580
    32
{
ds@580
    33
	Handle_t handle;					/**< Handle to convar */
ds@580
    34
	bool sourceMod;						/**< Determines whether or not convar was created by a SourceMod plugin */
ds@580
    35
	IChangeableForward *changeForward;	/**< Forward associated with convar */
ds@580
    36
	FnChangeCallback origCallback;		/**< The original callback function */
ds@580
    37
};
ds@580
    38
ds@580
    39
class ConVarManager :
ds@580
    40
	public SMGlobalClass,
ds@580
    41
	public IHandleTypeDispatch,
ds@580
    42
	public IPluginsListener,
ds@580
    43
	public IRootConsoleCommand
ds@580
    44
{
ds@580
    45
public:
ds@580
    46
	ConVarManager();
ds@580
    47
	~ConVarManager();
ds@580
    48
public: // SMGlobalClass
ds@580
    49
	void OnSourceModAllInitialized();
ds@580
    50
	void OnSourceModShutdown();
ds@580
    51
public: // IHandleTypeDispatch
ds@580
    52
	void OnHandleDestroy(HandleType_t type, void *object);
ds@580
    53
public: // IPluginsListener
ds@580
    54
	void OnPluginDestroyed(IPlugin *plugin);
ds@580
    55
public: //IRootConsoleCommand
ds@580
    56
	void OnRootConsoleCommand(const char *command, unsigned int argcount);
ds@580
    57
public:
ds@580
    58
	/**
ds@580
    59
	 * Get the 'ConVar' handle type ID.
ds@580
    60
	 */
ds@580
    61
	inline HandleType_t GetHandleType()
ds@580
    62
	{
ds@580
    63
		return m_ConVarType;
ds@580
    64
	}
ds@580
    65
ds@580
    66
	/**
ds@580
    67
	 * Get the convar lookup trie.
ds@580
    68
	 */
ds@580
    69
	inline Trie *GetConVarCache()
ds@580
    70
	{
ds@580
    71
		return m_ConVarCache;
ds@580
    72
	}
ds@580
    73
public:
ds@580
    74
	/**
ds@580
    75
	 * Create a convar and return a handle to it.
ds@580
    76
	 */
ds@580
    77
	Handle_t CreateConVar(IPluginContext *pContext, const char *name, const char *defaultVal, const char *helpText,
ds@580
    78
	                      int flags, bool hasMin, float min, bool hasMax, float max);
ds@580
    79
ds@580
    80
	/**
ds@580
    81
	 * Searches for a convar and returns a handle to it
ds@580
    82
	 */
ds@580
    83
	Handle_t FindConVar(const char* name);
ds@580
    84
ds@580
    85
	/**
ds@580
    86
	 * Add a function to call when the specified convar changes.
ds@580
    87
	 */
ds@580
    88
	void HookConVarChange(IPluginContext *pContext, ConVar *pConVar, funcid_t funcid);
ds@580
    89
ds@580
    90
	/**
ds@580
    91
	 * Remove a function from the forward that will be called when the specified convar changes.
ds@580
    92
	 */
ds@580
    93
	void UnhookConVarChange(IPluginContext *pContext, ConVar *pConVar, funcid_t funcid);
ds@580
    94
private:
ds@580
    95
	/**
ds@580
    96
	 * Static callback that Valve's ConVar class executes when the convar's value changes.
ds@580
    97
	 */
ds@580
    98
	static void OnConVarChanged(ConVar *pConVar, const char *oldValue);
ds@580
    99
private:
ds@580
   100
	HandleType_t m_ConVarType;
ds@580
   101
	List<ConVarInfo *> m_ConVars;
ds@580
   102
	Trie *m_ConVarCache;
ds@580
   103
};
ds@580
   104
ds@580
   105
extern ConVarManager g_ConVarManager;
ds@580
   106
ds@580
   107
#endif // _INCLUDE_SOURCEMOD_CONVARMANAGER_H_
ds@580
   108