ds@576: /** ds@576: * =============================================================== ds@576: * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. ds@576: * =============================================================== ds@576: * ds@576: * This file is not open source and may not be copied without explicit ds@576: * written permission of AlliedModders LLC. This file may not be redistributed ds@576: * in whole or significant part. ds@576: * For information, see LICENSE.txt or http://www.sourcemod.net/license.php ds@576: * ds@577: * Version: $Id$ ds@576: */ ds@576: ds@582: #ifndef _INCLUDE_SOURCEMOD_EVENTMANAGER_H_ ds@582: #define _INCLUDE_SOURCEMOD_EVENTMANAGER_H_ ds@576: ds@576: #include "sm_globals.h" ds@576: #include "sourcemm_api.h" ds@576: #include "sm_trie.h" ds@576: #include ds@577: #include ds@576: #include ds@576: #include ds@576: #include ds@576: ds@576: using namespace SourceHook; ds@576: ds@576: //#define EVENT_PASSTHRU (1<<0) ds@576: #define EVENT_PASSTHRU_ALL (1<<1) ds@576: ds@576: struct EventInfo ds@576: { ds@576: IGameEvent *pEvent; ds@577: IdentityToken_t *pOwner; ds@576: }; ds@576: ds@576: struct EventHook ds@576: { ds@576: EventHook() ds@576: { ds@576: pPreHook = NULL; ds@576: pPostHook = NULL; ds@576: postCopy = false; ds@576: refCount = 0; ds@576: } ds@576: IChangeableForward *pPreHook; ds@576: IChangeableForward *pPostHook; ds@576: bool postCopy; ds@576: unsigned int refCount; ds@576: }; ds@576: ds@576: enum EventHookMode ds@576: { ds@576: EventHookMode_Pre, ds@576: EventHookMode_Post, ds@576: EventHookMode_PostNoCopy ds@576: }; ds@576: ds@576: enum EventHookError ds@576: { ds@576: EventHookErr_Okay = 0, /**< No error */ ds@576: EventHookErr_InvalidEvent, /**< Specified event does not exist */ ds@576: EventHookErr_NotActive, /**< Specified event has no active hook */ ds@576: EventHookErr_InvalidCallback, /**< Specified event does not fire specified callback */ ds@576: }; ds@576: ds@576: class EventManager : ds@576: public SMGlobalClass, ds@576: public IHandleTypeDispatch, ds@576: public IPluginsListener, ds@576: public IGameEventListener2 ds@576: { ds@576: public: ds@576: EventManager(); ds@576: ~EventManager(); ds@576: public: // SMGlobalClass ds@576: void OnSourceModAllInitialized(); ds@576: void OnSourceModShutdown(); ds@576: public: // IHandleTypeDispatch ds@576: void OnHandleDestroy(HandleType_t type, void *object); ds@576: public: // IPluginsListener ds@576: void OnPluginUnloaded(IPlugin *plugin); ds@576: public: // IGameEventListener2 ds@576: void FireGameEvent(IGameEvent *pEvent); ds@576: public: ds@576: /** ds@576: * Get the 'GameEvent' handle type ID. ds@576: */ ds@576: inline HandleType_t GetHandleType() ds@576: { ds@577: return m_EventType; ds@576: } ds@576: public: ds@576: EventHookError HookEvent(const char *name, IPluginFunction *pFunction, EventHookMode mode=EventHookMode_Post); ds@576: EventHookError UnhookEvent(const char *name, IPluginFunction *pFunction, EventHookMode mode=EventHookMode_Post); ds@577: EventInfo *CreateEvent(IPluginContext *pContext, const char *name); ds@578: void FireEvent(EventInfo *pInfo, int flags=0, bool bDontBroadcast=false); ds@576: private: // IGameEventManager2 hooks ds@576: bool OnFireEvent(IGameEvent *pEvent, bool bDontBroadcast); ds@576: bool OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast); ds@576: private: ds@576: HandleType_t m_EventType; ds@581: bool m_NotifyPlugins; ds@581: const char *m_EventName; ds@581: IGameEvent *m_EventCopy; ds@576: Trie *m_EventHooks; ds@577: CStack m_FreeEvents; ds@576: }; ds@576: ds@576: extern EventManager g_EventManager; ds@576: ds@582: #endif // _INCLUDE_SOURCEMOD_EVENTMANAGER_H_