plugins/include/timers.inc
author Borja Ferrer <faluco@alliedmods.net>
Tue Jul 31 02:08:25 2007 +0000 (2007-07-31)
changeset 1219 6f440a361fa7
parent 1108 fafe809b16ca
child 1330 ab94316bb52b
permissions -rw-r--r--
added amb595, eye position and angle natives
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ===============================================================
     6  *
     7  *  This file is part of the SourceMod/SourcePawn SDK.  This file may only be used 
     8  * or modified under the Terms and Conditions of its License Agreement, which is found 
     9  * in LICENSE.txt.  The Terms and Conditions for making SourceMod extensions/plugins 
    10  * may change at any time.  To view the latest information, see:
    11  *   http://www.sourcemod.net/license.php
    12  *
    13  * Version: $Id$
    14  */
    15 
    16 #if defined _timers_included
    17  #endinput
    18 #endif
    19 #define _timers_included
    20 
    21 #include <datapack>
    22 
    23 #define TIMER_REPEAT			(1<<0)		/**< Timer will repeat until it returns Plugin_Stop */
    24 #define TIMER_FLAG_NO_MAPCHANGE	(1<<1)		/**< Timer will not carry over mapchanges */
    25 #define TIMER_HNDL_CLOSE		(1<<9)		/**< Timer will automatically call CloseHandle() on its value when finished */
    26 
    27 /**
    28  * Any of the following prototypes will work for a timed function.
    29  */
    30 funcenum Timer
    31 {
    32 	/**
    33  	 * Called when the timer interval has elapsed.
    34  	 * 
    35  	 * @param timer			Handle to the timer object.
    36  	 * @param hndl			Handle passed when the timer was created.
    37  	 * @return				Plugin_Stop to stop a repeating timer, any other value for
    38  	 *						default behavior.
    39  	 */
    40 	Action:public(Handle:timer, Handle:hndl),
    41 	
    42 	/**
    43  	 * Called when the timer interval has elapsed.
    44  	 * 
    45  	 * @param timer			Handle to the timer object.
    46  	 * @param value			Value passed when the timer was created.
    47  	 * @return				Plugin_Stop to stop a repeating timer, any other value for
    48  	 *						default behavior.
    49  	 */
    50 	Action:public(Handle:timer, any:value),
    51 	
    52 	/**
    53  	 * Called when the timer interval has elapsed.
    54  	 * 
    55  	 * @param timer			Handle to the timer object.
    56  	 * @return				Plugin_Stop to stop a repeating timer, any other value for
    57  	 *						default behavior.
    58  	 */
    59 	Action:public(Handle:timer),
    60 };
    61 
    62 /**
    63  * Creates a basic timer.  Calling CloseHandle() on a timer will end the timer.
    64  *
    65  * @param interval			Interval from the current game time to execute the given function.
    66  * @param func				Function to execute once the given interval has elapsed.
    67  * @param value				Handle or value to give to the timer function.
    68  * @param flags				Flags to set (such as repeatability or auto-Handle closing).
    69  * @return					Handle to the timer object.  You do not need to call CloseHandle().
    70  */
    71 native Handle:CreateTimer(Float:interval, Timer:func, any:value=INVALID_HANDLE, flags=0);
    72 
    73 /**
    74  * Kills a timer.  Use this instead of CloseHandle() if you need more options.
    75  *
    76  * @param autoClose			If autoClose is true, the timer's value will be 
    77  *							closed as a handle if TIMER_HNDL_CLOSE was not specified.
    78  * @noreturn
    79  */
    80 native KillTimer(Handle:timer, bool:autoClose=false);
    81 
    82 /**
    83  * Manually triggers a timer so its function will be called.
    84  *
    85  * @param timer				Timer Handle to trigger.
    86  * @param reset				If reset is true, the elapsed time counter is reset
    87  *							so the full interval must pass again.
    88  * @noreturn
    89  */
    90 native TriggerTimer(Handle:timer, bool:reset=false);
    91 
    92 /**
    93  * Returns the simulated game time.
    94  *
    95  * @param simulated			Retrieves whether or not the tick count
    96  *							is being manually simulated by SourceMod.
    97  *							This is the case if no players have joined
    98  *							the map yet.
    99  * @return					Time based on the game tick count.
   100  */
   101 native Float:GetTickedTime(&bool:simulated);
   102 
   103 /**
   104  * Creates a timer associated with a new data pack, and returns the datapack.
   105  * @note The datapack is automatically freed when the timer ends.
   106  * @note The position of the datapack is not reset or changed for the timer function.
   107  *
   108  * @param interval			Interval from the current game time to execute the given function.
   109  * @param func				Function to execute once the given interval has elapsed.
   110  * @param data				The newly created datapack is passed though this by-reference parameter.
   111  * @param flags				Timer flags.
   112  * @return					Handle to the timer object.  You do not need to call CloseHandle().
   113  */
   114 stock Handle:CreateDataTimer(Float:interval, Timer:func, &Handle:data, flags=0)
   115 {
   116 	data = CreateDataPack();
   117 	flags |= TIMER_HNDL_CLOSE;
   118 	return CreateTimer(interval, func, data, flags);
   119 }