sourcemod/public/ITimerSystem.h

190 lines
5.7 KiB
C
Raw Normal View History

/**
* vim: set ts=4 :
* =============================================================================
* SourceMod
* Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id$
*/
#ifndef _INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_
#define _INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_
/**
* @file ITimerSystem.h
* @brief Contains functions for creating and managing timers.
*/
#include <IShareSys.h>
#include <IForwardSys.h>
#define SMINTERFACE_TIMERSYS_NAME "ITimerSys"
#define SMINTERFACE_TIMERSYS_VERSION 1
namespace SourceMod
{
class ITimer;
/**
* @brief Interface for map timers.
*/
class IMapTimer
{
public:
/**
* Returns the current map time limit in seconds.
*
* @return Time limit, in seconds, or
* 0 if there is no limit.
*/
virtual int GetMapTimeLimit() =0;
/**
* Returns how much time is left in the map.
*
* @param time_left Pointer to store time, in seconds.
* @return True if there is a time limit, false
* if the time limit is 0.
*/
virtual bool GetMapTimeLeft(int *time_left) =0;
/**
* Extends the map limit (either positively or negatively) in seconds.
*
* @param extra_time Time to extend map by. If 0, the map will
* be set to have no time limit.
*/
virtual void ExtendMapTimeLimit(int extra_time) =0;
/**
* Tells the map timer whether it is being used or not.
*
* Map timers are automatically enabled when they are set, and
* automatically disabled if being un-set.
*
* @param enabled True if enabling, false if disabling.
*/
virtual void SetMapTimerStatus(bool enabled) =0;
};
/**
* @brief Event callbacks for when a timer is executed.
*/
class ITimedEvent
{
public:
/**
* @brief Called when a timer is executed.
*
* @param pTimer Pointer to the timer instance.
* @param pData Private pointer passed from host.
* @return Pl_Stop to stop timer, Pl_Continue to continue.
*/
virtual ResultType OnTimer(ITimer *pTimer, void *pData) =0;
/**
* @brief Called when the timer has been killed.
*
* @param pTimer Pointer to the timer instance.
* @param pData Private data pointer passed from host.
*/
virtual void OnTimerEnd(ITimer *pTimer, void *pData) =0;
};
#define TIMER_FLAG_REPEAT (1<<0) /**< Timer will repeat until stopped */
#define TIMER_FLAG_NO_MAPCHANGE (1<<1) /**< Timer will not carry over mapchanges */
class ITimerSystem : public SMInterface
{
public:
const char *GetInterfaceName()
{
return SMINTERFACE_TIMERSYS_NAME;
}
unsigned int GetInterfaceVersion()
{
return SMINTERFACE_TIMERSYS_VERSION;
}
public:
/**
* @brief Creates a timed event.
*
* @param pCallbacks Pointer to ITimedEvent callbacks.
* @param fInterval Interval, in seconds, of the timed event to occur.
* The smallest allowed interval is 0.1 seconds.
* @param pData Private data to pass on to the timer.
* @param flags Extra flags to pass on to the timer.
* @return An ITimer pointer on success, NULL on
* failure.
*/
virtual ITimer *CreateTimer(ITimedEvent *pCallbacks,
float fInterval,
void *pData,
int flags) =0;
/**
* @brief Kills a timer.
*
* @param pTimer Pointer to the ITimer structure.
* @return
*/
virtual void KillTimer(ITimer *pTimer) =0;
/**
* @brief Arbitrarily fires a timer. If the timer is not a repeating
* timer, this will also kill the timer.
*
* @param pTimer Pointer to the ITimer structure.
* @param delayExec If true, and the timer is repeating, the
* next execution will be delayed by its
* interval.
* @return
*/
virtual void FireTimerOnce(ITimer *pTimer, bool delayExec=false) =0;
/**
* @brief Sets the interface for dealing with map time limits.
*
* @param pMapTimer Map timer interface pointer.
* @return Old pointer.
*/
virtual IMapTimer *SetMapTimer(IMapTimer *pTimer) =0;
/**
* @brief Notifies the timer that the map timelimit has been extended.
*
* A time limit of 0 implies that there is no limit.
*
* @param old_limit Old limit, in seconds.
* @param new_limit New limit, in seconds.
*/
virtual void MapTimeLimitExtended(int old_limit, int new_limit) =0;
};
}
#endif //_INCLUDE_SOURCEMOD_TIMER_SYSTEM_H_