3 * ===============================================================
4 * SourceMod, Copyright (C) 2004-2007 AlliedModders LLC.
6 * ===============================================================
8 * This file is part of the SourceMod/SourcePawn SDK. This file may only be
9 * used or modified under the Terms and Conditions of its License Agreement,
10 * which is found in public/licenses/LICENSE.txt. As of this notice, derivative
11 * works must be licensed under the GNU General Public License (version 2 or
12 * greater). A copy of the GPL is included under public/licenses/GPL.txt.
14 * To view the latest information, see: http://www.sourcemod.net/license.php
19 #ifndef _INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_
20 #define _INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_
22 #include <IShareSys.h>
23 #include <IForwardSys.h>
25 #define SMINTERFACE_TIMERSYS_NAME "ITimerSys"
26 #define SMINTERFACE_TIMERSYS_VERSION 1
33 * @brief Event callbacks for when a timer is executed.
39 * @brief Called when a timer is executed.
41 * @param pTimer Pointer to the timer instance.
42 * @param pData Private pointer passed from host.
43 * @return Pl_Stop to stop timer, Pl_Continue to continue.
45 virtual ResultType OnTimer(ITimer *pTimer, void *pData) =0;
48 * @brief Called when the timer has been killed.
50 * @param pTimer Pointer to the timer instance.
51 * @param pData Private data pointer passed from host.
53 virtual void OnTimerEnd(ITimer *pTimer, void *pData) =0;
56 #define TIMER_FLAG_REPEAT (1<<0)
58 class ITimerSystem : public SMInterface
61 const char *GetInterfaceName()
63 return SMINTERFACE_TIMERSYS_NAME;
65 unsigned int GetInterfaceVersion()
67 return SMINTERFACE_TIMERSYS_VERSION;
71 * @brief Creates a timed event.
73 * @param pCallbacks Pointer to ITimedEvent callbacks.
74 * @param fInterval Interval, in seconds, of the timed event to occur.
75 * The smallest allowed interval is 0.1 seconds.
76 * @param pData Private data to pass on to the timer.
77 * @param flags Extra flags to pass on to the timer.
78 * @return An ITimer pointer on success, NULL on failure.
80 virtual ITimer *CreateTimer(ITimedEvent *pCallbacks,
86 * @brief Kills a timer.
88 * @param pTimer Pointer to the ITimer structure.
91 virtual void KillTimer(ITimer *pTimer) =0;
94 * @brief Arbitrarily fires a timer. If the timer is not a repeating
95 * timer, this will also kill the timer.
97 * @param pTimer Pointer to the ITimer structure.
98 * @param delayExec If true, and the timer is repeating, the
99 * next execution will be delayed by its interval.
102 virtual void FireTimerOnce(ITimer *pTimer, bool delayExec=false) =0;
106 #endif //_INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_