ds@576: /** ds@653: * vim: set ts=4 : ds@1330: * ============================================================================= dvander@1231: * SourceMod dvander@1231: * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. ds@1330: * ============================================================================= ds@653: * ds@1330: * This program is free software; you can redistribute it and/or modify it under ds@1330: * the terms of the GNU General Public License, version 3.0, as published by the ds@1330: * Free Software Foundation. dvander@1231: * ds@1330: * This program is distributed in the hope that it will be useful, but WITHOUT ds@1330: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ds@1330: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ds@1330: * details. dvander@1231: * ds@1330: * You should have received a copy of the GNU General Public License along with ds@1330: * this program. If not, see . dvander@1231: * ds@1330: * As a special exception, AlliedModders LLC gives you permission to link the ds@1330: * code of this program (as well as its derivative works) to "Half-Life 2," the ds@1330: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software ds@1330: * by the Valve Corporation. You must obey the GNU General Public License in ds@1330: * all respects for all other code used. Additionally, AlliedModders LLC grants ds@1330: * this exception to all derivative works. AlliedModders LLC defines further ds@1330: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), ds@1330: * or . 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_