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