core/TimerSys.h
changeset 592 c2a2c38f1331
child 616 d5b1dcf38c07
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/core/TimerSys.h	Sat Mar 10 21:26:04 2007 +0000
     1.3 @@ -0,0 +1,65 @@
     1.4 +/**
     1.5 +* vim: set ts=4 :
     1.6 +* ===============================================================
     1.7 +* SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     1.8 +* ===============================================================
     1.9 +*
    1.10 +* This file is not open source and may not be copied without explicit
    1.11 +* written permission of AlliedModders LLC.  This file may not be redistributed 
    1.12 +* in whole or significant part.
    1.13 +* For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    1.14 +*
    1.15 +* Version: $Id$
    1.16 +*/
    1.17 +
    1.18 +#ifndef _INCLUDE_SOURCEMOD_CTIMERSYS_H_
    1.19 +#define _INCLUDE_SOURCEMOD_CTIMERSYS_H_
    1.20 +
    1.21 +#include "ShareSys.h"
    1.22 +#include <ITimerSystem.h>
    1.23 +#include <sh_stack.h>
    1.24 +#include <sh_list.h>
    1.25 +#include "sourcemm_api.h"
    1.26 +
    1.27 +using namespace SourceHook;
    1.28 +using namespace SourceMod;
    1.29 +
    1.30 +typedef List<ITimer *> TimerList;
    1.31 +typedef List<ITimer *>::iterator TimerIter;
    1.32 +
    1.33 +class SourceMod::ITimer
    1.34 +{
    1.35 +public:
    1.36 +	void Initialize(ITimedEvent *pCallbacks, float fInterval, float fToExec, void *pData, int flags);
    1.37 +	ITimedEvent *m_Listener;
    1.38 +	void *m_pData;
    1.39 +	float m_Interval;
    1.40 +	float m_ToExec;
    1.41 +	int m_Flags;
    1.42 +	bool m_InExec;
    1.43 +	bool m_KillMe;
    1.44 +};
    1.45 +
    1.46 +class CTimerSystem : 
    1.47 +	public ITimerSystem,
    1.48 +	public SMGlobalClass
    1.49 +{
    1.50 +public: //SMGlobalClass
    1.51 +	void OnSourceModAllInitialized();
    1.52 +public: //ITimerSystem
    1.53 +	ITimer *CreateTimer(ITimedEvent *pCallbacks, float fInterval, void *pData, int flags);
    1.54 +	void KillTimer(ITimer *pTimer);
    1.55 +	void FireTimerOnce(ITimer *pTimer, bool delayExec=false);
    1.56 +public:
    1.57 +	void RunFrame();
    1.58 +	void MapChange();
    1.59 +private:
    1.60 +	List<ITimer *> m_SingleTimers;
    1.61 +	List<ITimer *> m_LoopTimers;
    1.62 +	CStack<ITimer *> m_FreeTimers;
    1.63 +	float m_LastExecTime;
    1.64 +};
    1.65 +
    1.66 +extern CTimerSystem g_Timers;
    1.67 +
    1.68 +#endif //_INCLUDE_SOURCEMOD_CTIMERSYS_H_