定时器系统
来源:互联网 发布:压缩感知算法 编辑:程序博客网 时间:2024/05/18 20:06
Rzyom定时器系统由三个类组成:
class CTimer;class CTimerEvent;class CTimerManager;
CTimerEvent 用于用户派生自己的事件处理类,重新实现定时回调接口timerCallback(),处理相应事件。
CTimer 通用定时器类,设置定时时长,多久之后回调timerCallback()。
如果这个对象被销毁其回调将被自动取消。
一个计时器只能设置一个触发时间,第二次设置将覆盖以前的时间。
CTimerManager 这是一个单例,在tickUpdate()中触发时间到了的CTimerEvent.timerCallback() 。
注:该系统的唯一要求是,CTimerManager:: tickUpdate()需要在每个游戏循环中调用。
使用方法&例程:
class CMyClass;class CMyTimerEvent;class CMyTimerEvent: public CTimerEvent{public:CMyTimerEvent(CMyClass* parent);void timerCallback(CTimer* owner);private:CMyClass* _Parent;}class CMyClass{public:void startTimer(){// set the timer to trigger in 5000 millisecond_Timer.setRemaining(5000,new CMyTimerEvent(this));}void doSomething(CTimerEvent* event){nlinfo("hello world");// set the timer to trigger in 2000 millisecond with the same event handler_Timer.setRemaining(2000,event);}private:CMyTimer _Timer;};void CMyTimerEvent::CMyTimerEvent(CMyClass* parent){_Parent=parent;}void CMyTimerEvent::timerCallback(CTimer* owner){_Parent->doSomething(this);}
这个定时器系统的精度与服务器每帧的执行时间有关,默认为100毫秒。
CTimerEvent将定时时间换算成游戏循环圈数,hash后存于一个vector中,之后每次游戏循环检查 _EventVectors[uint8(fps&0xff)]。
// the type of the event vector for a given time hashtypedef std::vector<NLMISC::CSmartPtr<CTimerEvent> > TEventVector;TEventVector _EventVectors[256];
0 0
- 定时器系统
- 系统定时器
- ZigBee系统定时器
- linux系统中的定时器
- STM32系统定时器SysTick
- stm32 SysTick系统定时器
- sysTick系统定时器
- STM32系统定时器SysTick
- linux系统 定时器
- uboot---系统时钟和定时器
- Linux 系统设计之 定时器
- LPC1768之系统滴答定时器
- 系统时钟和SysTick定时器
- C#系统服务程序定时器
- 定时器;如何获取系统时间
- STM32之SysTick(系统定时器)
- MFC--定时器及系统时间
- stm32系统滴答定时器使用
- HDU-1271 整数对
- 2014 -- ASP.NET 面试题
- MySQL联结表
- Linux下设置定期执行脚本
- hibernate.hbm2ddl.auto参数及其含义
- 定时器系统
- HDU 1874 畅通工程续-- Dijkstra算法详解 单源点最短路问题
- Unity3d 2D动画之Blend Trees 学习
- 2014 -- android 面试题
- 链表
- 二十世纪最伟大的10大算法
- 博弈论中的尼姆博弈
- [cocos2dx]学习 屏幕适配与其解决方案
- MyEclipse has detected that less than 5% of the 64MB of Perm Gen (Non-heap memor