core/TimerSys.h
author David Anderson <dvander@alliedmods.net>
Fri Jun 08 01:09:17 2007 +0000 (2007-06-08)
changeset 922 980941c525fa
parent 727 fade10824d88
child 1142 13547d08e3a8
permissions -rw-r--r--
sm_kick now uses targeting properly
     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 struct TickInfo
    31 {
    32 	bool ticking;				/* true=game is ticking, false=we're ticking */
    33 	unsigned int tickcount;		/* number of simulated ticks we've done */
    34 	float ticktime;				/* tick time we're maintaining */
    35 };
    36 
    37 class SourceMod::ITimer
    38 {
    39 public:
    40 	void Initialize(ITimedEvent *pCallbacks, float fInterval, float fToExec, void *pData, int flags);
    41 	ITimedEvent *m_Listener;
    42 	void *m_pData;
    43 	float m_Interval;
    44 	float m_ToExec;
    45 	int m_Flags;
    46 	bool m_InExec;
    47 	bool m_KillMe;
    48 };
    49 
    50 class TimerSystem : 
    51 	public ITimerSystem,
    52 	public SMGlobalClass
    53 {
    54 public:
    55 	~TimerSystem();
    56 public: //SMGlobalClass
    57 	void OnSourceModAllInitialized();
    58 	void OnSourceModLevelChange(const char *mapName);
    59 public: //ITimerSystem
    60 	ITimer *CreateTimer(ITimedEvent *pCallbacks, float fInterval, void *pData, int flags);
    61 	void KillTimer(ITimer *pTimer);
    62 	void FireTimerOnce(ITimer *pTimer, bool delayExec=false);
    63 public:
    64 	void RunFrame();
    65 	void MapChange();
    66 private:
    67 	List<ITimer *> m_SingleTimers;
    68 	List<ITimer *> m_LoopTimers;
    69 	CStack<ITimer *> m_FreeTimers;
    70 	float m_LastExecTime;
    71 };
    72 
    73 extern TimerSystem g_Timers;
    74 extern TickInfo g_SimTicks;
    75 
    76 #endif //_INCLUDE_SOURCEMOD_CTIMERSYS_H_