ds@576: /** ds@653: * vim: set ts=4 : ds@653: * =============================================================== ds@653: * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. ds@653: * =============================================================== ds@653: * ds@653: * This file is not open source and may not be copied without explicit ds@653: * written permission of AlliedModders LLC. This file may not be redistributed ds@653: * in whole or significant part. ds@653: * For information, see LICENSE.txt or http://www.sourcemod.net/license.php ds@653: * ds@653: * Version: $Id$ ds@653: */ 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: 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@684: pEventCopy = NULL; ds@576: refCount = 0; ds@576: } ds@576: IChangeableForward *pPreHook; ds@576: IChangeableForward *pPostHook; ds@576: bool postCopy; ds@684: IGameEvent *pEventCopy; 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@713: EventInfo *CreateEvent(IPluginContext *pContext, const char *name, bool force=false); ds@712: void FireEvent(EventInfo *pInfo, bool bDontBroadcast=false); ds@687: void CancelCreatedEvent(EventInfo *pInfo); 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@576: Trie *m_EventHooks; ds@577: CStack m_FreeEvents; ds@684: CStack m_EventNames; ds@576: }; ds@576: ds@576: extern EventManager g_EventManager; ds@576: ds@582: #endif // _INCLUDE_SOURCEMOD_EVENTMANAGER_H_