core/TimerSys.h
author David Anderson <dvander@alliedmods.net>
Mon Mar 19 01:44:09 2007 +0000 (2007-03-19)
changeset 647 1e29dcc9ca97
parent 641 ce1f369ba889
child 673 fc1d50579d06
permissions -rw-r--r--
fixed a potential bug with kicking players during authorization
     1 /**
     2 * vim: set ts=4 :
     3 * ===============================================================
     4 * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5 * ===============================================================
     6 *
     7 * This file is not open source and may not be copied without explicit
     8 * written permission of AlliedModders LLC.  This file may not be redistributed 
     9 * in whole or significant part.
    10 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    11 *
    12 * Version: $Id$
    13 */
    14 
    15 #ifndef _INCLUDE_SOURCEMOD_CTIMERSYS_H_
    16 #define _INCLUDE_SOURCEMOD_CTIMERSYS_H_
    17 
    18 #include "ShareSys.h"
    19 #include <ITimerSystem.h>
    20 #include <sh_stack.h>
    21 #include <sh_list.h>
    22 #include "sourcemm_api.h"
    23 
    24 using namespace SourceHook;
    25 using namespace SourceMod;
    26 
    27 typedef List<ITimer *> TimerList;
    28 typedef List<ITimer *>::iterator TimerIter;
    29 
    30 class SourceMod::ITimer
    31 {
    32 public:
    33 	void Initialize(ITimedEvent *pCallbacks, float fInterval, float fToExec, void *pData, int flags);
    34 	ITimedEvent *m_Listener;
    35 	void *m_pData;
    36 	float m_Interval;
    37 	float m_ToExec;
    38 	int m_Flags;
    39 	bool m_InExec;
    40 	bool m_KillMe;
    41 };
    42 
    43 class TimerSystem : 
    44 	public ITimerSystem,
    45 	public SMGlobalClass
    46 {
    47 public:
    48 	~TimerSystem();
    49 public: //SMGlobalClass
    50 	void OnSourceModAllInitialized();
    51 public: //ITimerSystem
    52 	ITimer *CreateTimer(ITimedEvent *pCallbacks, float fInterval, void *pData, int flags);
    53 	void KillTimer(ITimer *pTimer);
    54 	void FireTimerOnce(ITimer *pTimer, bool delayExec=false);
    55 public:
    56 	void RunFrame();
    57 	void MapChange();
    58 private:
    59 	List<ITimer *> m_SingleTimers;
    60 	List<ITimer *> m_LoopTimers;
    61 	CStack<ITimer *> m_FreeTimers;
    62 	float m_LastExecTime;
    63 };
    64 
    65 extern TimerSystem g_Timers;
    66 
    67 #endif //_INCLUDE_SOURCEMOD_CTIMERSYS_H_