public/ITimerSystem.h
author Phong Dang <teame06@gmail.com>
Sun Jul 29 19:20:42 2007 +0000 (2007-07-29)
changeset 1211 990912ee1e1e
parent 1108 fafe809b16ca
child 1226 478550a4d5ec
permissions -rw-r--r--
Added amb<536> requested for using sm_kick without putting quotes around reason.
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod, Copyright (C) 2004-2007 AlliedModders LLC. 
     5  * All rights reserved.
     6  * ===============================================================
     7  *
     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.
    13  * 
    14  * To view the latest information, see: http://www.sourcemod.net/license.php
    15  *
    16  * Version: $Id$
    17  */
    18 
    19 #ifndef _INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_
    20 #define _INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_
    21 
    22 /**
    23  * @file ITimerSystem.h
    24  * @brief Contains functions for creating and managing timers.
    25  */
    26 
    27 
    28 #include <IShareSys.h>
    29 #include <IForwardSys.h>
    30 
    31 #define SMINTERFACE_TIMERSYS_NAME		"ITimerSys"
    32 #define SMINTERFACE_TIMERSYS_VERSION	1
    33 
    34 namespace SourceMod
    35 {
    36 	class ITimer;
    37 
    38 	/**
    39 	 * @brief Event callbacks for when a timer is executed.
    40 	 */
    41 	class ITimedEvent
    42 	{
    43 	public:
    44 		/**
    45 		 * @brief Called when a timer is executed.
    46 		 *
    47 		 * @param pTimer		Pointer to the timer instance.
    48 		 * @param pData			Private pointer passed from host.
    49 		 * @return				Pl_Stop to stop timer, Pl_Continue to continue.
    50 		 */
    51 		virtual ResultType OnTimer(ITimer *pTimer, void *pData) =0;
    52 
    53 		/**
    54 		 * @brief Called when the timer has been killed.
    55 		 *
    56 		 * @param pTimer		Pointer to the timer instance.
    57 		 * @param pData			Private data pointer passed from host.
    58 		 */
    59 		virtual void OnTimerEnd(ITimer *pTimer, void *pData) =0;
    60 	};
    61 
    62 	#define TIMER_FLAG_REPEAT			(1<<0)		/**< Timer will repeat until stopped */
    63 	#define TIMER_FLAG_NO_MAPCHANGE		(1<<1)		/**< Timer will not carry over mapchanges */
    64 
    65 	class ITimerSystem : public SMInterface
    66 	{
    67 	public:
    68 		const char *GetInterfaceName()
    69 		{
    70 			return SMINTERFACE_TIMERSYS_NAME;
    71 		}
    72 		unsigned int GetInterfaceVersion()
    73 		{
    74 			return SMINTERFACE_TIMERSYS_VERSION;
    75 		}
    76 	public:
    77 		/**
    78 		 * @brief Creates a timed event.
    79 		 *
    80 		 * @param pCallbacks		Pointer to ITimedEvent callbacks.
    81 		 * @param fInterval			Interval, in seconds, of the timed event to occur.
    82 		 *							The smallest allowed interval is 0.1 seconds.
    83 		 * @param pData				Private data to pass on to the timer.
    84 		 * @param flags				Extra flags to pass on to the timer.
    85 		 * @return					An ITimer pointer on success, NULL on failure.
    86 		 */
    87 		virtual ITimer *CreateTimer(ITimedEvent *pCallbacks, 
    88 										 float fInterval, 
    89 										 void *pData,
    90 										 int flags) =0;
    91 
    92 		/**
    93 		 * @brief Kills a timer.
    94 		 *
    95 		 * @param pTimer			Pointer to the ITimer structure.
    96 		 * @return
    97 		 */
    98 		virtual void KillTimer(ITimer *pTimer) =0;
    99 
   100 		/**
   101 		 * @brief Arbitrarily fires a timer.  If the timer is not a repeating 
   102 		 * timer, this will also kill the timer.
   103 		 *
   104 		 * @param pTimer			Pointer to the ITimer structure.
   105 		 * @param delayExec			If true, and the timer is repeating, the
   106 		 *							next execution will be delayed by its interval.
   107 		 * @return
   108 		 */
   109 		virtual void FireTimerOnce(ITimer *pTimer, bool delayExec=false) =0;
   110 	};
   111 }
   112 
   113 #endif //_INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_