public/ITimerSystem.h
changeset 564 6c0daa856f04
child 587 e9f3bbe8ba5d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/public/ITimerSystem.h	Fri Mar 02 23:54:26 2007 +0000
     1.3 @@ -0,0 +1,109 @@
     1.4 +/**
     1.5 + * vim: set ts=4 :
     1.6 + * ===============================================================
     1.7 + * SourceMod, Copyright (C) 2004-2007 AlliedModders LLC. 
     1.8 + * All rights reserved.
     1.9 + * ===============================================================
    1.10 + *
    1.11 + *  This file is part of the SourceMod/SourcePawn SDK.  This file may only be 
    1.12 + * used or modified under the Terms and Conditions of its License Agreement, 
    1.13 + * which is found in public/licenses/LICENSE.txt.  As of this notice, derivative 
    1.14 + * works must be licensed under the GNU General Public License (version 2 or 
    1.15 + * greater).  A copy of the GPL is included under public/licenses/GPL.txt.
    1.16 + * 
    1.17 + * To view the latest information, see: http://www.sourcemod.net/license.php
    1.18 + *
    1.19 + * Version: $Id$
    1.20 + */
    1.21 +
    1.22 +#ifndef _INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_
    1.23 +#define _INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_
    1.24 +
    1.25 +#include <IShareSys.h>
    1.26 +
    1.27 +//:TODO: this is a placeholder and not yet implemented
    1.28 +//remove these lines and uncomment once we're done!
    1.29 +//#define SMINTERFACE_TIMERSYS_NAME		"ITimerSys"
    1.30 +//#define SMINTERFACE_TIMERSYS_VERSION	1
    1.31 +
    1.32 +namespace SourceMod
    1.33 +{
    1.34 +	class ITimer;
    1.35 +
    1.36 +	/**
    1.37 +	 * @brief Event callbacks for when a timer is executed.
    1.38 +	 */
    1.39 +	class ITimedEvent
    1.40 +	{
    1.41 +	public:
    1.42 +		/**
    1.43 +		 * @brief Called when a timer is executed.
    1.44 +		 *
    1.45 +		 * @param pTimer		Pointer to the timer instance.
    1.46 +		 * @param pData			Private pointer passed from host.
    1.47 +		 * @return				Pl_Handle to stop timer, Pl_Continue to continue.
    1.48 +		 *						Passing Pl_Continue when a timer's repeat count
    1.49 +		 *						has been exhausted will not extend it.
    1.50 +		 */
    1.51 +		virtual ResultType OnTimer(ITimer *pTimer, void *pData) =0;
    1.52 +
    1.53 +		/**
    1.54 +		 * @brief Called when the timer has been killed.
    1.55 +		 *
    1.56 +		 * @param pTimer		Pointer to the timer instance.
    1.57 +		 * @param pData			Private data pointer passed from host.
    1.58 +		 */
    1.59 +		virtual void OnTimerEnd() =0;
    1.60 +	};
    1.61 +
    1.62 +	#define TIMER_FLAG_REPEAT		(1<<0)
    1.63 +
    1.64 +	class ITimerSystem : public SMInterface
    1.65 +	{
    1.66 +	public:
    1.67 +		const char *GetInterfaceName()
    1.68 +		{
    1.69 +			return SMINTERFACE_TIMERSYS_NAME;
    1.70 +		}
    1.71 +		unsigned int GetInterfaceVersion()
    1.72 +		{
    1.73 +			return SMINTERFACE_TIMERSYS_VERSION;
    1.74 +		}
    1.75 +	public:
    1.76 +		/**
    1.77 +		 * @brief Creates a timed event.
    1.78 +		 *
    1.79 +		 * @param pCallbacks		Pointer to ITimedEvent callbacks.
    1.80 +		 * @param fInterval			Interval, in seconds, of the timed event to occur.
    1.81 +		 *							The smallest allowed interval is 0.1 seconds.
    1.82 +		 * @param pData				Private data to pass on to the timer.
    1.83 +		 * @param flags				Extra flags to pass on to the timer.
    1.84 +		 * @return					An ITimer pointer on success, NULL on failure.
    1.85 +		 */
    1.86 +		virtual ITimer *CreateTimer(ITimedEvent *pCallbacks, 
    1.87 +										 float fInterval, 
    1.88 +										 void *pData,
    1.89 +										 int flags) =0;
    1.90 +
    1.91 +		/**
    1.92 +		 * @brief Kills a timer.
    1.93 +		 *
    1.94 +		 * @param pTimer			Pointer to the ITimer structure.
    1.95 +		 * @return
    1.96 +		 */
    1.97 +		virtual void KillTimer(ITimer *pTimer) =0;
    1.98 +
    1.99 +		/**
   1.100 +		 * @brief Arbitrarily fires a timer.  If the timer is not a repeating 
   1.101 +		 * timer, this will also kill the timer.
   1.102 +		 *
   1.103 +		 * @param pTimer			Pointer to the ITimer structure.
   1.104 +		 * @param delayExec			If true, and the timer is repeating, the
   1.105 +		 *							next execution will be delayed by its interval.
   1.106 +		 * @return
   1.107 +		 */
   1.108 +		virtual void FireTimerOnce(ITimer *pTimer, bool delayExec=false) =0;
   1.109 +	};
   1.110 +}
   1.111 +
   1.112 +#endif //_INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_