3 * =============================================================================
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #ifndef _INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_
33 #define _INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_
36 * @file ITimerSystem.h
37 * @brief Contains functions for creating and managing timers.
41 #include <IShareSys.h>
42 #include <IForwardSys.h>
44 #define SMINTERFACE_TIMERSYS_NAME "ITimerSys"
45 #define SMINTERFACE_TIMERSYS_VERSION 1
51 typedef float (*SM_TIMELEFT_FUNCTION)();
54 * @brief Event callbacks for when a timer is executed.
60 * @brief Called when a timer is executed.
62 * @param pTimer Pointer to the timer instance.
63 * @param pData Private pointer passed from host.
64 * @return Pl_Stop to stop timer, Pl_Continue to continue.
66 virtual ResultType OnTimer(ITimer *pTimer, void *pData) =0;
69 * @brief Called when the timer has been killed.
71 * @param pTimer Pointer to the timer instance.
72 * @param pData Private data pointer passed from host.
74 virtual void OnTimerEnd(ITimer *pTimer, void *pData) =0;
77 #define TIMER_FLAG_REPEAT (1<<0) /**< Timer will repeat until stopped */
78 #define TIMER_FLAG_NO_MAPCHANGE (1<<1) /**< Timer will not carry over mapchanges */
79 #define TIMER_FLAG_BEFORE_MAP_END (1<<2) /**< Timer will fire <interval> seconds before map end.
80 This flag is cannot be used with REPEAT,
81 and TIMER_FLAG_NO_MAPCHANGE is implied.
84 class ITimerSystem : public SMInterface
87 const char *GetInterfaceName()
89 return SMINTERFACE_TIMERSYS_NAME;
91 unsigned int GetInterfaceVersion()
93 return SMINTERFACE_TIMERSYS_VERSION;
97 * @brief Creates a timed event.
99 * @param pCallbacks Pointer to ITimedEvent callbacks.
100 * @param fInterval Interval, in seconds, of the timed event to occur.
101 * The smallest allowed interval is 0.1 seconds.
102 * @param pData Private data to pass on to the timer.
103 * @param flags Extra flags to pass on to the timer.
104 * @return An ITimer pointer on success, NULL on
107 virtual ITimer *CreateTimer(ITimedEvent *pCallbacks,
113 * @brief Kills a timer.
115 * @param pTimer Pointer to the ITimer structure.
118 virtual void KillTimer(ITimer *pTimer) =0;
121 * @brief Arbitrarily fires a timer. If the timer is not a repeating
122 * timer, this will also kill the timer.
124 * @param pTimer Pointer to the ITimer structure.
125 * @param delayExec If true, and the timer is repeating, the
126 * next execution will be delayed by its
130 virtual void FireTimerOnce(ITimer *pTimer, bool delayExec=false) =0;
133 * @brief Sets the function which is used to find the time left in the map.
135 * @param fn Function that returns the time left in seconds.
136 * @return The previous SM_TIMELEFT_FUNCTION pointer.
138 virtual SM_TIMELEFT_FUNCTION SetTimeLeftFunction(SM_TIMELEFT_FUNCTION fn) =0;
142 #endif //_INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_