core/TimerSys.h
author Scott Ehlert <ds@alliedmods.net>
Sat Apr 21 17:03:28 2007 +0000 (2007-04-21)
changeset 702 ff520b71249c
parent 673 fc1d50579d06
child 727 fade10824d88
permissions -rw-r--r--
Wow, how did I forget this - exported IMemoryUtils interface
     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 	void OnSourceModLevelChange(const char *mapName);
    52 public: //ITimerSystem
    53 	ITimer *CreateTimer(ITimedEvent *pCallbacks, float fInterval, void *pData, int flags);
    54 	void KillTimer(ITimer *pTimer);
    55 	void FireTimerOnce(ITimer *pTimer, bool delayExec=false);
    56 public:
    57 	void RunFrame();
    58 	void MapChange();
    59 private:
    60 	List<ITimer *> m_SingleTimers;
    61 	List<ITimer *> m_LoopTimers;
    62 	CStack<ITimer *> m_FreeTimers;
    63 	float m_LastExecTime;
    64 };
    65 
    66 extern TimerSystem g_Timers;
    67 
    68 #endif //_INCLUDE_SOURCEMOD_CTIMERSYS_H_