public/ITimerSystem.h

Go to the documentation of this file.
00001 /**
00002  * vim: set ts=4 :
00003  * =============================================================================
00004  * SourceMod
00005  * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
00006  * =============================================================================
00007  *
00008  * This program is free software; you can redistribute it and/or modify it under
00009  * the terms of the GNU General Public License, version 3.0, as published by the
00010  * Free Software Foundation.
00011  * 
00012  * This program is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00015  * details.
00016  *
00017  * You should have received a copy of the GNU General Public License along with
00018  * this program.  If not, see <http://www.gnu.org/licenses/>.
00019  *
00020  * As a special exception, AlliedModders LLC gives you permission to link the
00021  * code of this program (as well as its derivative works) to "Half-Life 2," the
00022  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
00023  * by the Valve Corporation.  You must obey the GNU General Public License in
00024  * all respects for all other code used.  Additionally, AlliedModders LLC grants
00025  * this exception to all derivative works.  AlliedModders LLC defines further
00026  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
00027  * or <http://www.sourcemod.net/license.php>.
00028  *
00029  * Version: $Id: ITimerSystem.h 1964 2008-03-27 04:54:56Z damagedsoul $
00030  */
00031 
00032 #ifndef _INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_
00033 #define _INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_
00034 
00035 /**
00036  * @file ITimerSystem.h
00037  * @brief Contains functions for creating and managing timers.
00038  */
00039 
00040 
00041 #include <IShareSys.h>
00042 #include <IForwardSys.h>
00043 
00044 #define SMINTERFACE_TIMERSYS_NAME                 "ITimerSys"
00045 #define SMINTERFACE_TIMERSYS_VERSION    3
00046 
00047 namespace SourceMod
00048 {
00049           class ITimer;
00050 
00051           /**
00052            * @brief Interface for map timers.
00053            */
00054           class IMapTimer
00055           {
00056           public:
00057                     /**
00058                      * Returns the current map time limit in seconds.
00059                      *
00060                      * @return                                        Time limit, in seconds, or 
00061                      *                                                          0 if there is no limit.
00062                      */
00063                     virtual int GetMapTimeLimit() =0;
00064                     
00065                     /**
00066                      * Extends the map limit (either positively or negatively) in seconds.
00067                      *
00068                      * @param extra_time          Time to extend map by.  If 0, the map will 
00069                      *                                                          be set to have no time limit.
00070                      */
00071                     virtual void ExtendMapTimeLimit(int extra_time) =0;
00072 
00073                     /**
00074                      * Tells the map timer whether it is being used or not.
00075                      *
00076                      * Map timers are automatically enabled when they are set, and 
00077                      * automatically disabled if being un-set.
00078                      *
00079                      * @param enabled             True if enabling, false if disabling.
00080                      */
00081                     virtual void SetMapTimerStatus(bool enabled) =0;
00082           };
00083 
00084           /**
00085            * @brief Event callbacks for when a timer is executed.
00086            */
00087           class ITimedEvent
00088           {
00089           public:
00090                     /**
00091                      * @brief Called when a timer is executed.
00092                      *
00093                      * @param pTimer              Pointer to the timer instance.
00094                      * @param pData                         Private pointer passed from host.
00095                      * @return                                        Pl_Stop to stop timer, Pl_Continue to continue.
00096                      */
00097                     virtual ResultType OnTimer(ITimer *pTimer, void *pData) =0;
00098 
00099                     /**
00100                      * @brief Called when the timer has been killed.
00101                      *
00102                      * @param pTimer              Pointer to the timer instance.
00103                      * @param pData                         Private data pointer passed from host.
00104                      */
00105                     virtual void OnTimerEnd(ITimer *pTimer, void *pData) =0;
00106           };
00107 
00108           #define TIMER_FLAG_REPEAT                         (1<<0)              /**< Timer will repeat until stopped */
00109           #define TIMER_FLAG_NO_MAPCHANGE                   (1<<1)              /**< Timer will not carry over mapchanges */
00110 
00111           class ITimerSystem : public SMInterface
00112           {
00113           public:
00114                     const char *GetInterfaceName()
00115                     {
00116                               return SMINTERFACE_TIMERSYS_NAME;
00117                     }
00118                     unsigned int GetInterfaceVersion()
00119                     {
00120                               return SMINTERFACE_TIMERSYS_VERSION;
00121                     }
00122           public:
00123                     /**
00124                      * @brief Creates a timed event.
00125                      *
00126                      * @param pCallbacks                    Pointer to ITimedEvent callbacks.
00127                      * @param fInterval                     Interval, in seconds, of the timed event to occur.
00128                      *                                                                    The smallest allowed interval is 0.1 seconds.
00129                      * @param pData                                   Private data to pass on to the timer.
00130                      * @param flags                                   Extra flags to pass on to the timer.
00131                      * @return                                                  An ITimer pointer on success, NULL on 
00132                      *                                                                    failure.
00133                      */
00134                     virtual ITimer *CreateTimer(ITimedEvent *pCallbacks, 
00135                                                                                                      float fInterval, 
00136                                                                                                      void *pData,
00137                                                                                                      int flags) =0;
00138 
00139                     /**
00140                      * @brief Kills a timer.
00141                      *
00142                      * @param pTimer                        Pointer to the ITimer structure.
00143                      * @return
00144                      */
00145                     virtual void KillTimer(ITimer *pTimer) =0;
00146 
00147                     /**
00148                      * @brief Arbitrarily fires a timer.  If the timer is not a repeating 
00149                      * timer, this will also kill the timer.
00150                      *
00151                      * @param pTimer                        Pointer to the ITimer structure.
00152                      * @param delayExec                     If true, and the timer is repeating, the
00153                      *                                                                    next execution will be delayed by its 
00154                      *                                                                    interval.
00155                      * @return
00156                      */
00157                     virtual void FireTimerOnce(ITimer *pTimer, bool delayExec=false) =0;
00158 
00159                     /**
00160                      * @brief Sets the interface for dealing with map time limits.
00161                      *
00162                      * @param pMapTimer                     Map timer interface pointer.
00163                      * @return                                                  Old pointer.
00164                      */
00165                     virtual IMapTimer *SetMapTimer(IMapTimer *pTimer) =0;
00166 
00167                     /**
00168                      * @brief Notification that the map's time left has changed 
00169                      * via a change in the time limit or a change in the game rules (
00170                      * such as mp_restartgame).
00171                      */
00172                     virtual void MapTimeLeftChanged() =0;
00173 
00174                     /**
00175                      * @brief Returns the current universal tick time.  This 
00176                      * replacement for gpGlobals->curtime and engine->Time() correctly 
00177                      * keeps track of ticks.
00178                      *
00179                      * During simulation, it is incremented by the difference between 
00180                      * gpGlobals->curtime and the last simulated tick.  Otherwise, 
00181                      * it is incremented by the interval per tick.
00182                      *
00183                      * It is not reset past map changes.
00184                      *
00185                      * @return                                                  Universal ticked time.
00186                      */
00187                     virtual float GetTickedTime() =0;
00188 
00189                     /**
00190                      * @brief Notification that the "starting point" in the game has has 
00191                      * changed.  This does not invoke MapTimeLeftChanged() automatically.
00192                      *
00193                      * @param offset                        Optional offset to add to the new time.
00194                      */
00195                     virtual void NotifyOfGameStart(float offset = 0.0f) =0;
00196 
00197                     /**
00198                      * @brief Returns the time left in the map.
00199                      *
00200                      * @param pTime                                   Pointer to store time left, in seconds.
00201                      *                                                                    If there is no time limit, the number will 
00202                      *                                                                    be below 0.
00203                      * @return                                                  True on success, false if no support.
00204                      */
00205                     virtual bool GetMapTimeLeft(float *pTime) =0;
00206           };
00207 }
00208 
00209 #endif //_INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_

Generated on Fri Nov 21 01:10:02 2008 for SourceMod SDK by  doxygen 1.5.1