ds@1952: /** ds@1952: * vim: set ts=4 : ds@1952: * ============================================================================= ds@1952: * SourceMod ds@1952: * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. ds@1952: * ============================================================================= ds@1952: * ds@1952: * This program is free software; you can redistribute it and/or modify it under ds@1952: * the terms of the GNU General Public License, version 3.0, as published by the ds@1952: * Free Software Foundation. ds@1952: * ds@1952: * This program is distributed in the hope that it will be useful, but WITHOUT ds@1952: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ds@1952: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ds@1952: * details. ds@1952: * ds@1952: * You should have received a copy of the GNU General Public License along with ds@1952: * this program. If not, see . ds@1952: * ds@1952: * As a special exception, AlliedModders LLC gives you permission to link the ds@1952: * code of this program (as well as its derivative works) to "Half-Life 2," the ds@1952: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software ds@1952: * by the Valve Corporation. You must obey the GNU General Public License in ds@1952: * all respects for all other code used. Additionally, AlliedModders LLC grants ds@1952: * this exception to all derivative works. AlliedModders LLC defines further ds@1952: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), ds@1952: * or . ds@1952: * ds@1952: * Version: $Id$ ds@1952: */ ds@1952: ds@1952: #ifndef _INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_ ds@1952: #define _INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_ ds@1952: ds@1952: /** ds@1952: * @file ITimerSystem.h ds@1952: * @brief Contains functions for creating and managing timers. ds@1952: */ ds@1952: ds@1952: ds@1952: #include ds@1952: #include ds@1952: ds@1952: #define SMINTERFACE_TIMERSYS_NAME "ITimerSys" ds@1952: #define SMINTERFACE_TIMERSYS_VERSION 3 ds@1952: ds@1952: namespace SourceMod ds@1952: { ds@1952: class ITimer; ds@1952: ds@1952: /** ds@1952: * @brief Interface for map timers. ds@1952: */ ds@1952: class IMapTimer ds@1952: { ds@1952: public: ds@1952: /** ds@1952: * Returns the current map time limit in seconds. ds@1952: * ds@1952: * @return Time limit, in seconds, or ds@1952: * 0 if there is no limit. ds@1952: */ ds@1952: virtual int GetMapTimeLimit() =0; ds@1952: ds@1952: /** ds@1952: * Extends the map limit (either positively or negatively) in seconds. ds@1952: * ds@1952: * @param extra_time Time to extend map by. If 0, the map will ds@1952: * be set to have no time limit. ds@1952: */ ds@1952: virtual void ExtendMapTimeLimit(int extra_time) =0; ds@1952: ds@1952: /** ds@1952: * Tells the map timer whether it is being used or not. ds@1952: * ds@1952: * Map timers are automatically enabled when they are set, and ds@1952: * automatically disabled if being un-set. ds@1952: * ds@1952: * @param enabled True if enabling, false if disabling. ds@1952: */ ds@1952: virtual void SetMapTimerStatus(bool enabled) =0; ds@1952: }; ds@1952: ds@1952: /** ds@1952: * @brief Event callbacks for when a timer is executed. ds@1952: */ ds@1952: class ITimedEvent ds@1952: { ds@1952: public: ds@1952: /** ds@1952: * @brief Called when a timer is executed. ds@1952: * ds@1952: * @param pTimer Pointer to the timer instance. ds@1952: * @param pData Private pointer passed from host. ds@1952: * @return Pl_Stop to stop timer, Pl_Continue to continue. ds@1952: */ ds@1952: virtual ResultType OnTimer(ITimer *pTimer, void *pData) =0; ds@1952: ds@1952: /** ds@1952: * @brief Called when the timer has been killed. ds@1952: * ds@1952: * @param pTimer Pointer to the timer instance. ds@1952: * @param pData Private data pointer passed from host. ds@1952: */ ds@1952: virtual void OnTimerEnd(ITimer *pTimer, void *pData) =0; ds@1952: }; ds@1952: ds@1952: #define TIMER_FLAG_REPEAT (1<<0) /**< Timer will repeat until stopped */ ds@1952: #define TIMER_FLAG_NO_MAPCHANGE (1<<1) /**< Timer will not carry over mapchanges */ ds@1952: ds@1952: class ITimerSystem : public SMInterface ds@1952: { ds@1952: public: ds@1952: const char *GetInterfaceName() ds@1952: { ds@1952: return SMINTERFACE_TIMERSYS_NAME; ds@1952: } ds@1952: unsigned int GetInterfaceVersion() ds@1952: { ds@1952: return SMINTERFACE_TIMERSYS_VERSION; ds@1952: } ds@1952: public: ds@1952: /** ds@1952: * @brief Creates a timed event. ds@1952: * ds@1952: * @param pCallbacks Pointer to ITimedEvent callbacks. ds@1952: * @param fInterval Interval, in seconds, of the timed event to occur. ds@1952: * The smallest allowed interval is 0.1 seconds. ds@1952: * @param pData Private data to pass on to the timer. ds@1952: * @param flags Extra flags to pass on to the timer. ds@1952: * @return An ITimer pointer on success, NULL on ds@1952: * failure. ds@1952: */ ds@1952: virtual ITimer *CreateTimer(ITimedEvent *pCallbacks, ds@1952: float fInterval, ds@1952: void *pData, ds@1952: int flags) =0; ds@1952: ds@1952: /** ds@1952: * @brief Kills a timer. ds@1952: * ds@1952: * @param pTimer Pointer to the ITimer structure. ds@1952: * @return ds@1952: */ ds@1952: virtual void KillTimer(ITimer *pTimer) =0; ds@1952: ds@1952: /** ds@1952: * @brief Arbitrarily fires a timer. If the timer is not a repeating ds@1952: * timer, this will also kill the timer. ds@1952: * ds@1952: * @param pTimer Pointer to the ITimer structure. ds@1952: * @param delayExec If true, and the timer is repeating, the ds@1952: * next execution will be delayed by its ds@1952: * interval. ds@1952: * @return ds@1952: */ ds@1952: virtual void FireTimerOnce(ITimer *pTimer, bool delayExec=false) =0; ds@1952: ds@1952: /** ds@1952: * @brief Sets the interface for dealing with map time limits. ds@1952: * ds@1952: * @param pMapTimer Map timer interface pointer. ds@1952: * @return Old pointer. ds@1952: */ ds@1952: virtual IMapTimer *SetMapTimer(IMapTimer *pTimer) =0; ds@1952: ds@1952: /** ds@1952: * @brief Notification that the map's time left has changed ds@1952: * via a change in the time limit or a change in the game rules ( ds@1952: * such as mp_restartgame). ds@1952: */ ds@1952: virtual void MapTimeLeftChanged() =0; ds@1952: ds@1952: /** ds@1952: * @brief Returns the current universal tick time. This ds@1952: * replacement for gpGlobals->curtime and engine->Time() correctly ds@1952: * keeps track of ticks. ds@1952: * ds@1952: * During simulation, it is incremented by the difference between ds@1952: * gpGlobals->curtime and the last simulated tick. Otherwise, ds@1952: * it is incremented by the interval per tick. ds@1952: * ds@1952: * It is not reset past map changes. ds@1952: * ds@1952: * @return Universal ticked time. ds@1952: */ ds@1952: virtual float GetTickedTime() =0; ds@1952: ds@1952: /** ds@1952: * @brief Notification that the "starting point" in the game has has ds@1952: * changed. This does not invoke MapTimeLeftChanged() automatically. ds@1952: * ds@1952: * @param offset Optional offset to add to the new time. ds@1952: */ ds@1952: virtual void NotifyOfGameStart(float offset = 0.0f) =0; ds@1952: ds@1952: /** ds@1952: * @brief Returns the time left in the map. ds@1952: * ds@1952: * @param pTime Pointer to store time left, in seconds. ds@1952: * If there is no time limit, the number will ds@1952: * be below 0. ds@1952: * @return True on success, false if no support. ds@1952: */ ds@1952: virtual bool GetMapTimeLeft(float *pTime) =0; ds@1952: }; ds@1952: } ds@1952: ds@1952: #endif //_INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_