public/ITimerSystem.h
author David Anderson <dvander@alliedmods.net>
Wed Aug 08 02:44:36 2007 +0000 (2007-08-08)
changeset 1271 22f1534f2a61
parent 1226 478550a4d5ec
child 1330 ab94316bb52b
permissions -rw-r--r--
added a menu parameter to the vote callback
     1 /**
     2  * vim: set ts=4 :
     3  * ================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
     6  * ================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or 
     9  * modify it under the terms of the GNU General Public License, 
    10  * version 3.0, as published by the Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful,
    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15  * GNU General Public License for more details.
    16  *
    17  * You should have received a copy of the GNU General Public License
    18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to 
    21  * link the code of this program (as well as its derivative works) to 
    22  * "Half-Life 2," the "Source Engine," the "SourcePawn JIT," and any 
    23  * Game MODs that run on software by the Valve Corporation.  You must 
    24  * obey the GNU General Public License in all respects for all other 
    25  * code used. Additionally, AlliedModders LLC grants this exception 
    26  * to all derivative works. AlliedModders LLC defines further 
    27  * exceptions, found in LICENSE.txt (as of this writing, version 
    28  * JULY-31-2007), or <http://www.sourcemod.net/license.php>.
    29  *
    30  * Version: $Id$
    31  */
    32 
    33 #ifndef _INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_
    34 #define _INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_
    35 
    36 /**
    37  * @file ITimerSystem.h
    38  * @brief Contains functions for creating and managing timers.
    39  */
    40 
    41 
    42 #include <IShareSys.h>
    43 #include <IForwardSys.h>
    44 
    45 #define SMINTERFACE_TIMERSYS_NAME		"ITimerSys"
    46 #define SMINTERFACE_TIMERSYS_VERSION	1
    47 
    48 namespace SourceMod
    49 {
    50 	class ITimer;
    51 
    52 	/**
    53 	 * @brief Event callbacks for when a timer is executed.
    54 	 */
    55 	class ITimedEvent
    56 	{
    57 	public:
    58 		/**
    59 		 * @brief Called when a timer is executed.
    60 		 *
    61 		 * @param pTimer		Pointer to the timer instance.
    62 		 * @param pData			Private pointer passed from host.
    63 		 * @return				Pl_Stop to stop timer, Pl_Continue to continue.
    64 		 */
    65 		virtual ResultType OnTimer(ITimer *pTimer, void *pData) =0;
    66 
    67 		/**
    68 		 * @brief Called when the timer has been killed.
    69 		 *
    70 		 * @param pTimer		Pointer to the timer instance.
    71 		 * @param pData			Private data pointer passed from host.
    72 		 */
    73 		virtual void OnTimerEnd(ITimer *pTimer, void *pData) =0;
    74 	};
    75 
    76 	#define TIMER_FLAG_REPEAT			(1<<0)		/**< Timer will repeat until stopped */
    77 	#define TIMER_FLAG_NO_MAPCHANGE		(1<<1)		/**< Timer will not carry over mapchanges */
    78 
    79 	class ITimerSystem : public SMInterface
    80 	{
    81 	public:
    82 		const char *GetInterfaceName()
    83 		{
    84 			return SMINTERFACE_TIMERSYS_NAME;
    85 		}
    86 		unsigned int GetInterfaceVersion()
    87 		{
    88 			return SMINTERFACE_TIMERSYS_VERSION;
    89 		}
    90 	public:
    91 		/**
    92 		 * @brief Creates a timed event.
    93 		 *
    94 		 * @param pCallbacks		Pointer to ITimedEvent callbacks.
    95 		 * @param fInterval			Interval, in seconds, of the timed event to occur.
    96 		 *							The smallest allowed interval is 0.1 seconds.
    97 		 * @param pData				Private data to pass on to the timer.
    98 		 * @param flags				Extra flags to pass on to the timer.
    99 		 * @return					An ITimer pointer on success, NULL on failure.
   100 		 */
   101 		virtual ITimer *CreateTimer(ITimedEvent *pCallbacks, 
   102 										 float fInterval, 
   103 										 void *pData,
   104 										 int flags) =0;
   105 
   106 		/**
   107 		 * @brief Kills a timer.
   108 		 *
   109 		 * @param pTimer			Pointer to the ITimer structure.
   110 		 * @return
   111 		 */
   112 		virtual void KillTimer(ITimer *pTimer) =0;
   113 
   114 		/**
   115 		 * @brief Arbitrarily fires a timer.  If the timer is not a repeating 
   116 		 * timer, this will also kill the timer.
   117 		 *
   118 		 * @param pTimer			Pointer to the ITimer structure.
   119 		 * @param delayExec			If true, and the timer is repeating, the
   120 		 *							next execution will be delayed by its interval.
   121 		 * @return
   122 		 */
   123 		virtual void FireTimerOnce(ITimer *pTimer, bool delayExec=false) =0;
   124 	};
   125 }
   126 
   127 #endif //_INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_