plugins/include/timers.inc
author David Anderson <dvander@alliedmods.net>
Tue Aug 14 01:00:42 2007 +0000 (2007-08-14)
changeset 1324 9d1983bf06c7
parent 1108 fafe809b16ca
child 1330 ab94316bb52b
permissions -rw-r--r--
added SQL_CheckConfig() so sql admin plugins can default back
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
dvander@1108
    23
#define TIMER_REPEAT			(1<<0)		/**< Timer will repeat until it returns Plugin_Stop */
dvander@1108
    24
#define TIMER_FLAG_NO_MAPCHANGE	(1<<1)		/**< Timer will not carry over mapchanges */
dvander@1108
    25
#define TIMER_HNDL_CLOSE		(1<<9)		/**< Timer will automatically call CloseHandle() on its value when finished */
faluco@612
    26
faluco@612
    27
/**
faluco@612
    28
 * Any of the following prototypes will work for a timed function.
faluco@612
    29
 */
faluco@612
    30
funcenum Timer
faluco@612
    31
{
faluco@612
    32
	/**
faluco@612
    33
 	 * Called when the timer interval has elapsed.
faluco@612
    34
 	 * 
faluco@612
    35
 	 * @param timer			Handle to the timer object.
faluco@612
    36
 	 * @param hndl			Handle passed when the timer was created.
faluco@612
    37
 	 * @return				Plugin_Stop to stop a repeating timer, any other value for
faluco@612
    38
 	 *						default behavior.
faluco@612
    39
 	 */
faluco@612
    40
	Action:public(Handle:timer, Handle:hndl),
faluco@612
    41
	
faluco@612
    42
	/**
faluco@612
    43
 	 * Called when the timer interval has elapsed.
faluco@612
    44
 	 * 
faluco@612
    45
 	 * @param timer			Handle to the timer object.
faluco@612
    46
 	 * @param value			Value passed when the timer was created.
faluco@612
    47
 	 * @return				Plugin_Stop to stop a repeating timer, any other value for
faluco@612
    48
 	 *						default behavior.
faluco@612
    49
 	 */
dvander@716
    50
	Action:public(Handle:timer, any:value),
faluco@612
    51
	
faluco@612
    52
	/**
faluco@612
    53
 	 * Called when the timer interval has elapsed.
faluco@612
    54
 	 * 
faluco@612
    55
 	 * @param timer			Handle to the timer object.
faluco@612
    56
 	 * @return				Plugin_Stop to stop a repeating timer, any other value for
faluco@612
    57
 	 *						default behavior.
faluco@612
    58
 	 */
faluco@612
    59
	Action:public(Handle:timer),
faluco@612
    60
};
faluco@612
    61
faluco@612
    62
/**
faluco@612
    63
 * Creates a basic timer.  Calling CloseHandle() on a timer will end the timer.
faluco@612
    64
 *
faluco@612
    65
 * @param interval			Interval from the current game time to execute the given function.
faluco@612
    66
 * @param func				Function to execute once the given interval has elapsed.
faluco@612
    67
 * @param value				Handle or value to give to the timer function.
faluco@612
    68
 * @param flags				Flags to set (such as repeatability or auto-Handle closing).
faluco@612
    69
 * @return					Handle to the timer object.  You do not need to call CloseHandle().
faluco@612
    70
 */
dvander@716
    71
native Handle:CreateTimer(Float:interval, Timer:func, any:value=INVALID_HANDLE, flags=0);
faluco@612
    72
faluco@612
    73
/**
faluco@612
    74
 * Kills a timer.  Use this instead of CloseHandle() if you need more options.
faluco@612
    75
 *
faluco@612
    76
 * @param autoClose			If autoClose is true, the timer's value will be 
faluco@612
    77
 *							closed as a handle if TIMER_HNDL_CLOSE was not specified.
faluco@612
    78
 * @noreturn
faluco@612
    79
 */
faluco@612
    80
native KillTimer(Handle:timer, bool:autoClose=false);
faluco@612
    81
faluco@612
    82
/**
faluco@612
    83
 * Manually triggers a timer so its function will be called.
faluco@612
    84
 *
faluco@612
    85
 * @param timer				Timer Handle to trigger.
faluco@612
    86
 * @param reset				If reset is true, the elapsed time counter is reset
faluco@612
    87
 *							so the full interval must pass again.
faluco@612
    88
 * @noreturn
faluco@612
    89
 */
faluco@612
    90
native TriggerTimer(Handle:timer, bool:reset=false);
faluco@612
    91
faluco@612
    92
/**
dvander@822
    93
 * Returns the simulated game time.
dvander@822
    94
 *
dvander@822
    95
 * @param simulated			Retrieves whether or not the tick count
dvander@822
    96
 *							is being manually simulated by SourceMod.
dvander@822
    97
 *							This is the case if no players have joined
dvander@822
    98
 *							the map yet.
dvander@822
    99
 * @return					Time based on the game tick count.
dvander@822
   100
 */
dvander@822
   101
native Float:GetTickedTime(&bool:simulated);
dvander@822
   102
dvander@822
   103
/**
faluco@612
   104
 * Creates a timer associated with a new data pack, and returns the datapack.
faluco@612
   105
 * @note The datapack is automatically freed when the timer ends.
faluco@612
   106
 * @note The position of the datapack is not reset or changed for the timer function.
faluco@612
   107
 *
faluco@612
   108
 * @param interval			Interval from the current game time to execute the given function.
faluco@612
   109
 * @param func				Function to execute once the given interval has elapsed.
faluco@612
   110
 * @param data				The newly created datapack is passed though this by-reference parameter.
faluco@612
   111
 * @param flags				Timer flags.
faluco@612
   112
 * @return					Handle to the timer object.  You do not need to call CloseHandle().
faluco@612
   113
 */
dvander@716
   114
stock Handle:CreateDataTimer(Float:interval, Timer:func, &Handle:data, flags=0)
faluco@612
   115
{
faluco@612
   116
	data = CreateDataPack();
faluco@612
   117
	flags |= TIMER_HNDL_CLOSE;
faluco@612
   118
	return CreateTimer(interval, func, data, flags);
faluco@612
   119
}