public/ITimerSystem.h
author David Anderson <dvander@alliedmods.net>
Wed Jun 06 17:34:35 2007 +0000 (2007-06-06)
changeset 888 b3c080b0e9bb
parent 620 e329c942cb00
child 1108 fafe809b16ca
permissions -rw-r--r--
- fixed a serious bug where %T arguments were read backwards (they now match the wiki documentation of phrase and then client)
- fixed a bug where the argument count for %T was not checked properly
     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)
    63 
    64 	class ITimerSystem : public SMInterface
    65 	{
    66 	public:
    67 		const char *GetInterfaceName()
    68 		{
    69 			return SMINTERFACE_TIMERSYS_NAME;
    70 		}
    71 		unsigned int GetInterfaceVersion()
    72 		{
    73 			return SMINTERFACE_TIMERSYS_VERSION;
    74 		}
    75 	public:
    76 		/**
    77 		 * @brief Creates a timed event.
    78 		 *
    79 		 * @param pCallbacks		Pointer to ITimedEvent callbacks.
    80 		 * @param fInterval			Interval, in seconds, of the timed event to occur.
    81 		 *							The smallest allowed interval is 0.1 seconds.
    82 		 * @param pData				Private data to pass on to the timer.
    83 		 * @param flags				Extra flags to pass on to the timer.
    84 		 * @return					An ITimer pointer on success, NULL on failure.
    85 		 */
    86 		virtual ITimer *CreateTimer(ITimedEvent *pCallbacks, 
    87 										 float fInterval, 
    88 										 void *pData,
    89 										 int flags) =0;
    90 
    91 		/**
    92 		 * @brief Kills a timer.
    93 		 *
    94 		 * @param pTimer			Pointer to the ITimer structure.
    95 		 * @return
    96 		 */
    97 		virtual void KillTimer(ITimer *pTimer) =0;
    98 
    99 		/**
   100 		 * @brief Arbitrarily fires a timer.  If the timer is not a repeating 
   101 		 * timer, this will also kill the timer.
   102 		 *
   103 		 * @param pTimer			Pointer to the ITimer structure.
   104 		 * @param delayExec			If true, and the timer is repeating, the
   105 		 *							next execution will be delayed by its interval.
   106 		 * @return
   107 		 */
   108 		virtual void FireTimerOnce(ITimer *pTimer, bool delayExec=false) =0;
   109 	};
   110 }
   111 
   112 #endif //_INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_