public/ITimerSystem.h
author Scott Ehlert <ds@alliedmods.net>
Wed Jun 11 08:07:17 2008 +0000 (2008-06-11)
changeset 2112 2a83a521287c
parent 1952 b7aa2b626807
child 2289 44045ead61cd
permissions -rw-r--r--
All natives that use a recipient filter now actually validate the clients passed to them.
This includes StartMessage(), StartMessageEx() from Core as well as EmitSound(), EmitSentence(), and TE_Send() from SDKTools

(Warning: This may potentially cause a minor compatibility problem with plugins that don't check client validity before passing to these natives)
ds@1952
     1
/**
ds@1952
     2
 * vim: set ts=4 :
ds@1952
     3
 * =============================================================================
ds@1952
     4
 * SourceMod
ds@1952
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
ds@1952
     6
 * =============================================================================
ds@1952
     7
 *
ds@1952
     8
 * This program is free software; you can redistribute it and/or modify it under
ds@1952
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952
    10
 * Free Software Foundation.
ds@1952
    11
 * 
ds@1952
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1952
    15
 * details.
ds@1952
    16
 *
ds@1952
    17
 * You should have received a copy of the GNU General Public License along with
ds@1952
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1952
    19
 *
ds@1952
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1952
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1952
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1952
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952
    27
 * or <http://www.sourcemod.net/license.php>.
ds@1952
    28
 *
ds@1952
    29
 * Version: $Id$
ds@1952
    30
 */
ds@1952
    31
ds@1952
    32
#ifndef _INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_
ds@1952
    33
#define _INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_
ds@1952
    34
ds@1952
    35
/**
ds@1952
    36
 * @file ITimerSystem.h
ds@1952
    37
 * @brief Contains functions for creating and managing timers.
ds@1952
    38
 */
ds@1952
    39
ds@1952
    40
ds@1952
    41
#include <IShareSys.h>
ds@1952
    42
#include <IForwardSys.h>
ds@1952
    43
ds@1952
    44
#define SMINTERFACE_TIMERSYS_NAME		"ITimerSys"
ds@1952
    45
#define SMINTERFACE_TIMERSYS_VERSION	3
ds@1952
    46
ds@1952
    47
namespace SourceMod
ds@1952
    48
{
ds@1952
    49
	class ITimer;
ds@1952
    50
ds@1952
    51
	/**
ds@1952
    52
	 * @brief Interface for map timers.
ds@1952
    53
	 */
ds@1952
    54
	class IMapTimer
ds@1952
    55
	{
ds@1952
    56
	public:
ds@1952
    57
		/**
ds@1952
    58
		 * Returns the current map time limit in seconds.
ds@1952
    59
		 *
ds@1952
    60
		 * @return				Time limit, in seconds, or 
ds@1952
    61
		 *						0 if there is no limit.
ds@1952
    62
		 */
ds@1952
    63
		virtual int GetMapTimeLimit() =0;
ds@1952
    64
		
ds@1952
    65
		/**
ds@1952
    66
		 * Extends the map limit (either positively or negatively) in seconds.
ds@1952
    67
		 *
ds@1952
    68
		 * @param extra_time	Time to extend map by.  If 0, the map will 
ds@1952
    69
		 *						be set to have no time limit.
ds@1952
    70
		 */
ds@1952
    71
		virtual void ExtendMapTimeLimit(int extra_time) =0;
ds@1952
    72
ds@1952
    73
		/**
ds@1952
    74
		 * Tells the map timer whether it is being used or not.
ds@1952
    75
		 *
ds@1952
    76
		 * Map timers are automatically enabled when they are set, and 
ds@1952
    77
		 * automatically disabled if being un-set.
ds@1952
    78
		 *
ds@1952
    79
		 * @param enabled		True if enabling, false if disabling.
ds@1952
    80
		 */
ds@1952
    81
		virtual void SetMapTimerStatus(bool enabled) =0;
ds@1952
    82
	};
ds@1952
    83
ds@1952
    84
	/**
ds@1952
    85
	 * @brief Event callbacks for when a timer is executed.
ds@1952
    86
	 */
ds@1952
    87
	class ITimedEvent
ds@1952
    88
	{
ds@1952
    89
	public:
ds@1952
    90
		/**
ds@1952
    91
		 * @brief Called when a timer is executed.
ds@1952
    92
		 *
ds@1952
    93
		 * @param pTimer		Pointer to the timer instance.
ds@1952
    94
		 * @param pData			Private pointer passed from host.
ds@1952
    95
		 * @return				Pl_Stop to stop timer, Pl_Continue to continue.
ds@1952
    96
		 */
ds@1952
    97
		virtual ResultType OnTimer(ITimer *pTimer, void *pData) =0;
ds@1952
    98
ds@1952
    99
		/**
ds@1952
   100
		 * @brief Called when the timer has been killed.
ds@1952
   101
		 *
ds@1952
   102
		 * @param pTimer		Pointer to the timer instance.
ds@1952
   103
		 * @param pData			Private data pointer passed from host.
ds@1952
   104
		 */
ds@1952
   105
		virtual void OnTimerEnd(ITimer *pTimer, void *pData) =0;
ds@1952
   106
	};
ds@1952
   107
ds@1952
   108
	#define TIMER_FLAG_REPEAT			(1<<0)		/**< Timer will repeat until stopped */
ds@1952
   109
	#define TIMER_FLAG_NO_MAPCHANGE		(1<<1)		/**< Timer will not carry over mapchanges */
ds@1952
   110
ds@1952
   111
	class ITimerSystem : public SMInterface
ds@1952
   112
	{
ds@1952
   113
	public:
ds@1952
   114
		const char *GetInterfaceName()
ds@1952
   115
		{
ds@1952
   116
			return SMINTERFACE_TIMERSYS_NAME;
ds@1952
   117
		}
ds@1952
   118
		unsigned int GetInterfaceVersion()
ds@1952
   119
		{
ds@1952
   120
			return SMINTERFACE_TIMERSYS_VERSION;
ds@1952
   121
		}
ds@1952
   122
	public:
ds@1952
   123
		/**
ds@1952
   124
		 * @brief Creates a timed event.
ds@1952
   125
		 *
ds@1952
   126
		 * @param pCallbacks		Pointer to ITimedEvent callbacks.
ds@1952
   127
		 * @param fInterval			Interval, in seconds, of the timed event to occur.
ds@1952
   128
		 *							The smallest allowed interval is 0.1 seconds.
ds@1952
   129
		 * @param pData				Private data to pass on to the timer.
ds@1952
   130
		 * @param flags				Extra flags to pass on to the timer.
ds@1952
   131
		 * @return					An ITimer pointer on success, NULL on 
ds@1952
   132
		 *							failure.
ds@1952
   133
		 */
ds@1952
   134
		virtual ITimer *CreateTimer(ITimedEvent *pCallbacks, 
ds@1952
   135
										 float fInterval, 
ds@1952
   136
										 void *pData,
ds@1952
   137
										 int flags) =0;
ds@1952
   138
ds@1952
   139
		/**
ds@1952
   140
		 * @brief Kills a timer.
ds@1952
   141
		 *
ds@1952
   142
		 * @param pTimer			Pointer to the ITimer structure.
ds@1952
   143
		 * @return
ds@1952
   144
		 */
ds@1952
   145
		virtual void KillTimer(ITimer *pTimer) =0;
ds@1952
   146
ds@1952
   147
		/**
ds@1952
   148
		 * @brief Arbitrarily fires a timer.  If the timer is not a repeating 
ds@1952
   149
		 * timer, this will also kill the timer.
ds@1952
   150
		 *
ds@1952
   151
		 * @param pTimer			Pointer to the ITimer structure.
ds@1952
   152
		 * @param delayExec			If true, and the timer is repeating, the
ds@1952
   153
		 *							next execution will be delayed by its 
ds@1952
   154
		 *							interval.
ds@1952
   155
		 * @return
ds@1952
   156
		 */
ds@1952
   157
		virtual void FireTimerOnce(ITimer *pTimer, bool delayExec=false) =0;
ds@1952
   158
ds@1952
   159
		/**
ds@1952
   160
		 * @brief Sets the interface for dealing with map time limits.
ds@1952
   161
		 *
ds@1952
   162
		 * @param pMapTimer			Map timer interface pointer.
ds@1952
   163
		 * @return					Old pointer.
ds@1952
   164
		 */
ds@1952
   165
		virtual IMapTimer *SetMapTimer(IMapTimer *pTimer) =0;
ds@1952
   166
ds@1952
   167
		/**
ds@1952
   168
		 * @brief Notification that the map's time left has changed 
ds@1952
   169
		 * via a change in the time limit or a change in the game rules (
ds@1952
   170
		 * such as mp_restartgame).
ds@1952
   171
		 */
ds@1952
   172
		virtual void MapTimeLeftChanged() =0;
ds@1952
   173
ds@1952
   174
		/**
ds@1952
   175
		 * @brief Returns the current universal tick time.  This 
ds@1952
   176
		 * replacement for gpGlobals->curtime and engine->Time() correctly 
ds@1952
   177
		 * keeps track of ticks.
ds@1952
   178
		 *
ds@1952
   179
		 * During simulation, it is incremented by the difference between 
ds@1952
   180
		 * gpGlobals->curtime and the last simulated tick.  Otherwise, 
ds@1952
   181
		 * it is incremented by the interval per tick.
ds@1952
   182
		 *
ds@1952
   183
		 * It is not reset past map changes.
ds@1952
   184
		 *
ds@1952
   185
		 * @return					Universal ticked time.
ds@1952
   186
		 */
ds@1952
   187
		virtual float GetTickedTime() =0;
ds@1952
   188
ds@1952
   189
		/**
ds@1952
   190
		 * @brief Notification that the "starting point" in the game has has 
ds@1952
   191
		 * changed.  This does not invoke MapTimeLeftChanged() automatically.
ds@1952
   192
		 *
ds@1952
   193
		 * @param offset			Optional offset to add to the new time.
ds@1952
   194
		 */
ds@1952
   195
		virtual void NotifyOfGameStart(float offset = 0.0f) =0;
ds@1952
   196
ds@1952
   197
		/**
ds@1952
   198
		 * @brief Returns the time left in the map.
ds@1952
   199
		 *
ds@1952
   200
		 * @param pTime				Pointer to store time left, in seconds.
ds@1952
   201
		 * 							If there is no time limit, the number will 
ds@1952
   202
		 * 							be below 0.
ds@1952
   203
		 * @return					True on success, false if no support.
ds@1952
   204
		 */
ds@1952
   205
		virtual bool GetMapTimeLeft(float *pTime) =0;
ds@1952
   206
	};
ds@1952
   207
}
ds@1952
   208
ds@1952
   209
#endif //_INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_