Added check to make sure player are alive to perform sm_slap, sm_burn, sm_slay.
3 * ================================================================
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * ================================================================
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License,
10 * version 3.0, as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to
21 * link the code of this program (as well as its derivative works) to
22 * "Half-Life 2," the "Source Engine," the "SourcePawn JIT," and any
23 * Game MODs that run on software by the Valve Corporation. You must
24 * obey the GNU General Public License in all respects for all other
25 * code used. Additionally, AlliedModders LLC grants this exception
26 * to all derivative works. AlliedModders LLC defines further
27 * exceptions, found in LICENSE.txt (as of this writing, version
28 * JULY-31-2007), or <http://www.sourcemod.net/license.php>.
33 #ifndef _INCLUDE_SOURCEMOD_THREADER_H
34 #define _INCLUDE_SOURCEMOD_THREADER_H
38 * @brief Contains platform independent routines for threading.
41 #include <IShareSys.h>
43 #define SMINTERFACE_THREADER_NAME "IThreader"
44 #define SMINTERFACE_THREADER_VERSION 2
49 * @brief Thread creation flags
55 * @brief Auto-release handle on finish
57 * You are not guaranteed the handle for this is valid after
58 * calling MakeThread(), so never use it until OnTerminate is called.
60 Thread_AutoRelease = 1,
62 * @brief Thread is created "suspended", meaning it is inactive until unpaused.
64 Thread_CreateSuspended = 2,
68 * @brief Specifies thread priority levels.
72 ThreadPrio_Minimum = -8,
74 ThreadPrio_Normal = 0,
76 ThreadPrio_Maximum = 8,
80 * @brief The current state of a thread.
90 * @brief Thread-specific parameters.
96 flags(Thread_Default),
97 prio(ThreadPrio_Normal)
100 ThreadFlags flags; /**< Flags to set on the thread */
101 ThreadPriority prio; /**< Priority to set on the thread */
104 class IThreadCreator;
107 * @brief Describes a handle to a thread.
112 /** Virtual destructor */
113 virtual ~IThreadHandle() { };
116 * @brief Pauses parent thread until this thread completes.
118 * @return True if successful, false otherwise.
120 virtual bool WaitForThread() =0;
123 * @brief Destroys the thread handle. This will not necessarily cancel the thread.
125 virtual void DestroyThis() =0;
128 * @brief Returns the parent threader.
130 * @return IThreadCreator that created this thread.
132 virtual IThreadCreator *Parent() =0;
135 * @brief Returns the thread states.
137 * @param ptparams Pointer to a ThreadParams buffer.
139 virtual void GetParams(ThreadParams *ptparams) =0;
142 * @brief Returns the thread priority.
144 * @return Thread priority.
146 virtual ThreadPriority GetPriority() =0;
149 * @brief Sets thread priority.
150 * NOTE: On Linux, this always returns false.
152 * @param prio Thread priority to set.
153 * @return True if successful, false otherwise.
155 virtual bool SetPriority(ThreadPriority prio) =0;
158 * @brief Returns the thread state.
160 * @return Current thread state.
162 virtual ThreadState GetState() =0;
165 * @brief Attempts to unpause a paused thread.
167 * @return True on success, false otherwise.
169 virtual bool Unpause() =0;
173 * @brief Handles a single thread's execution.
178 /** Virtual destructor */
179 virtual ~IThread() { };
182 * @brief Called when the thread runs (in its own thread).
184 * @param pHandle Pointer to the thread's handle.
186 virtual void RunThread(IThreadHandle *pHandle) =0;
189 * @brief Called when the thread terminates. This occurs inside the thread as well.
191 * @param pHandle Pointer to the thread's handle.
192 * @param cancel True if the thread did not finish, false otherwise.
194 virtual void OnTerminate(IThreadHandle *pHandle, bool cancel) =0;
199 * @brief Describes a thread creator
204 /** Virtual Destructor */
205 virtual ~IThreadCreator() { };
208 * @brief Creates a basic thread.
210 * @param pThread IThread pointer for callbacks.
212 virtual void MakeThread(IThread *pThread) =0;
215 * @brief Creates a thread with specific options.
217 * @param pThread IThread pointer for callbacks.
218 * @param flags Flags for the thread.
219 * @return IThreadHandle pointer (must be released).
221 virtual IThreadHandle *MakeThread(IThread *pThread, ThreadFlags flags) =0;
224 * @brief Creates a thread with specific options.
226 * @param pThread IThread pointer for callbacks.
227 * @param params Extended options for the thread.
228 * @return IThreadHandle pointer (must be released).
230 virtual IThreadHandle *MakeThread(IThread *pThread, const ThreadParams *params) =0;
233 * @brief Returns the priority bounds.
234 * Note: On Linux, the min and max are both Thread_Normal.
236 * @param max Stores the maximum priority level.
237 * @param min Stores the minimum priority level.
239 virtual void GetPriorityBounds(ThreadPriority &max, ThreadPriority &min) =0;
243 * @brief Describes a simple locking mutex.
248 /** Virtual Destructor */
249 virtual ~IMutex() { };
252 * @brief Attempts to lock, but returns instantly.
254 * @return True if lock was obtained, false otherwise.
256 virtual bool TryLock() =0;
259 * @brief Attempts to lock by waiting for release.
261 virtual void Lock() =0;
264 * @brief Unlocks the mutex.
266 virtual void Unlock() =0;
269 * @brief Destroys the mutex handle.
271 virtual void DestroyThis() =0;
275 * @brief Describes a simple "condition variable"/signal lock.
280 /** Virtual Destructor */
281 virtual ~IEventSignal() { };
284 * @brief Waits for a signal.
286 virtual void Wait() =0;
289 * @brief Triggers the signal and resets the signal after triggering.
291 virtual void Signal() =0;
294 * @brief Frees the signal handle.
296 virtual void DestroyThis() =0;
300 * @brief Describes possible worker states
311 * @brief This is a "worker pool." A single thread places tasks in a queue.
312 * Each IThread is then a task, rather than its own separate thread.
314 class IThreadWorker : public IThreadCreator
317 /** Virtual Destructor */
318 virtual ~IThreadWorker()
323 * @brief Runs one "frame" of the worker.
325 * @return Number of tasks processed.
327 virtual unsigned int RunFrame() =0;
330 * @brief Pauses the worker.
332 * @return True on success, false otherwise.
334 virtual bool Pause() =0;
337 * @brief Unpauses the worker.
339 * @return True on success, false otherwise.
341 virtual bool Unpause() =0;
344 * @brief Starts the worker thread.
346 * @return True on success, false otherwise.
348 virtual bool Start() =0;
351 * @brief Stops the worker thread.
353 * @param flush If true, all remaining tasks will be cancelled.
354 * Otherwise, the threader will wait until the queue is empty.
355 * @return True on success, false otherwise.
357 virtual bool Stop(bool flush) =0;
360 * @brief Returns the status of the worker.
362 * @param numThreads Pointer to store number of threads in the queue.
363 * @return State of the worker.
365 virtual WorkerState GetStatus(unsigned int *numThreads) =0;
369 * @brief Describes thread worker callbacks.
371 class IThreadWorkerCallbacks
375 * @brief Called when the worker thread is initialized.
377 * @param pWorker Pointer to the worker.
379 virtual void OnWorkerStart(IThreadWorker *pWorker)
384 * @brief Called when the worker thread is cleaning up.
386 * @param pWorker Pointer to the worker.
388 virtual void OnWorkerStop(IThreadWorker *pWorker)
394 * @brief Describes a threading system
396 class IThreader : public SMInterface, public IThreadCreator
399 virtual const char *GetInterfaceName()
401 return SMINTERFACE_THREADER_NAME;
403 virtual unsigned int GetInterfaceVersion()
405 return SMINTERFACE_THREADER_VERSION;
407 virtual bool IsVersionCompatible(unsigned int version)
413 return SMInterface::IsVersionCompatible(version);
417 * @brief Creates a mutex (mutual exclusion lock).
419 * @return A new IMutex pointer (must be destroyed).
421 virtual IMutex *MakeMutex() =0;
424 * @brief Sleeps the calling thread for a number of milliseconds.
426 * @param ms Millisecond count to sleep.
428 virtual void ThreadSleep(unsigned int ms) =0;
431 * @brief Creates a non-signalled event.
433 * @return A new IEventSignal pointer (must be destroyed).
435 virtual IEventSignal *MakeEventSignal() =0;
438 * @brief Creates a thread worker.
440 * @param hooks Optional pointer to callback interface.
441 * @param threaded If true, the worker will be threaded.
442 * If false, the worker will require manual frame execution.
443 * @return A new IThreadWorker pointer (must be destroyed).
445 virtual IThreadWorker *MakeWorker(IThreadWorkerCallbacks *hooks, bool threaded) =0;
448 * @brief Destroys an IThreadWorker pointer.
450 * @param pWorker IThreadWorker pointer to destroy.
452 virtual void DestroyWorker(IThreadWorker *pWorker) =0;
456 #endif //_INCLUDE_SOURCEMOD_THREADER_H