public/ITimerSystem.h
author David Anderson <dvander@alliedmods.net>
Thu Mar 15 20:44:23 2007 +0000 (2007-03-15)
changeset 619 6934bf39171e
parent 587 e9f3bbe8ba5d
child 620 e329c942cb00
permissions -rw-r--r--
random touchups that might not be so great
     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 #include <IShareSys.h>
    23 #include <IForwardSys.h>
    24 
    25 #define SMINTERFACE_TIMERSYS_NAME		"ITimerSys"
    26 #define SMINTERFACE_TIMERSYS_VERSION	1
    27 
    28 namespace SourceMod
    29 {
    30 	class ITimer;
    31 
    32 	/**
    33 	 * @brief Event callbacks for when a timer is executed.
    34 	 */
    35 	class ITimedEvent
    36 	{
    37 	public:
    38 		/**
    39 		 * @brief Called when a timer is executed.
    40 		 *
    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.
    44 		 */
    45 		virtual ResultType OnTimer(ITimer *pTimer, void *pData) =0;
    46 
    47 		/**
    48 		 * @brief Called when the timer has been killed.
    49 		 *
    50 		 * @param pTimer		Pointer to the timer instance.
    51 		 * @param pData			Private data pointer passed from host.
    52 		 */
    53 		virtual void OnTimerEnd(ITimer *pTimer, void *pData) =0;
    54 	};
    55 
    56 	#define TIMER_FLAG_REPEAT		(1<<0)
    57 
    58 	class ITimerSystem : public SMInterface
    59 	{
    60 	public:
    61 		const char *GetInterfaceName()
    62 		{
    63 			return SMINTERFACE_TIMERSYS_NAME;
    64 		}
    65 		unsigned int GetInterfaceVersion()
    66 		{
    67 			return SMINTERFACE_TIMERSYS_VERSION;
    68 		}
    69 	public:
    70 		/**
    71 		 * @brief Creates a timed event.
    72 		 *
    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.
    79 		 */
    80 		virtual ITimer *CreateTimer(ITimedEvent *pCallbacks, 
    81 										 float fInterval, 
    82 										 void *pData,
    83 										 int flags) =0;
    84 
    85 		/**
    86 		 * @brief Kills a timer.
    87 		 *
    88 		 * @param pTimer			Pointer to the ITimer structure.
    89 		 * @return
    90 		 */
    91 		virtual void KillTimer(ITimer *pTimer) =0;
    92 
    93 		/**
    94 		 * @brief Arbitrarily fires a timer.  If the timer is not a repeating 
    95 		 * timer, this will also kill the timer.
    96 		 *
    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.
   100 		 * @return
   101 		 */
   102 		virtual void FireTimerOnce(ITimer *pTimer, bool delayExec=false) =0;
   103 	};
   104 }
   105 
   106 #endif //_INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_