⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timerengine.h

📁 游戏框架
💻 H
字号:
// ***************************************************************
//  TimerEngine   version:  1.0
//  -------------------------------------------------------------
//	File Name:	TimerEngine.h
//	Created:	2007/07/18
//	Modified:	2007/07/18   16:37
//	Author:		William.Liang
//  Msn:		lwq49@msn.com
//  Email:		lwq49@21cn.com, lwq49@msn.com
//	Description:
//
//	Purpose:	
//  -------------------------------------------------------------
//  license:
//
//  The contents of this file are subject to the Mozilla Public
//  License Version 1.1 (the "License"); you may not use this file
//  except in compliance with the License. You may obtain a copy
//  of the License at http://www.mozilla.org/MPL/ Software dis-
//  tributed under the License is distributed on an "AS IS" 
//  basis, WITHOUT WARRANTY OF ANY KIND, either express or im-
//  plied. See the License for the specific language governing
//  rights and limitations under the License.
//
//  The Initial Developer of the Original Code is William.Liang .
//  Copyright (C) 2007 - All Rights Reserved.
// ***************************************************************
#ifndef TIMERENGINE_HEAD_FILE
#define TIMERENGINE_HEAD_FILE

#pragma once

//系统头文件
#include "ServiceEnginer.h"
#include "..\ComService\ServiceThread.h"
#include "QueueServiceEvent.h"

//类说明
class CTimerEngine;

//////////////////////////////////////////////////////////////////////////

//定时器线程
class SERVICE_ENGINER_CLASS CTimerThread : public CServiceThread
{
	//变量定义
protected:
	DWORD								m_dwTimerSpace;					//时间间隔
	CTimerEngine						* m_pTimerEngine;				//定时器引擎

	//函数定义
public:
	//构造函数
	CTimerThread(void);
	//析构函数
	virtual ~CTimerThread(void);

	//功能函数
public:
	//配置函数
	bool InitThread(CTimerEngine * pTimerEngine, DWORD dwTimerSpace);

	//重载函数
private:
	//运行函数
	virtual bool RepetitionRun();
};

//////////////////////////////////////////////////////////////////////////

//定时器子项
struct tagTimerItem
{
	WORD								wTimerID;						//定时器 ID
	DWORD								dwElapse;						//定时时间
	DWORD								dwTimeLeave;					//倒计时间
	DWORD								dwRepeatTimes;					//重复次数
	WPARAM								wBindParam;						//绑定参数
};

//定时器子项数组定义
typedef CListTemplate<tagTimerItem*, WORD> CTimerItemPtr;

//////////////////////////////////////////////////////////////////////////

//定时器引擎
class SERVICE_ENGINER_CLASS CTimerEngine : public ITimerEngine, public ITimerEngineManager
{
	friend class CTimerThread;

	//配置定义
protected:
	DWORD								m_dwTimerSpace;					//时间间隔

	//状态变量
protected:
	bool								m_bService;						//运行标志
	DWORD								m_dwTimePass;					//经过时间
	DWORD								m_dwTimeLeave;					//倒计时间
	CTimerItemPtr						m_TimerItems;					//计时器数组

	//组件变量
protected:
	CThreadLock							m_ThreadLock;					//线程锁
	CTimerThread						m_TimerThread;					//定时器线程
	CQueueServiceEvent					m_AttemperEvent;				//通知组件

	//函数定义
public:
	//构造函数
	CTimerEngine(void);
	//析构函数
	virtual ~CTimerEngine(void);

	//基础接口
public:
	//释放对象
	virtual bool __cdecl Release() { if (IsValid()) delete this; return true; }
	//是否有效
	virtual bool __cdecl IsValid() { return AfxIsValidAddress(this,sizeof(CTimerEngine))?true:false; }
	//接口查询
	virtual void * __cdecl QueryInterface(const IID & Guid, DWORD dwQueryVer);

	//接口函数
public:
	//设置定时器
	virtual bool __cdecl SetTimer(WORD wTimerID, DWORD dwElapse, DWORD dwRepeat, WPARAM wParam, BOOL bCheckExist=true);
	//删除定时器
	virtual bool __cdecl KillTimer(WORD wTimerID);
	//删除定时器
	virtual bool __cdecl KillAllTimer();

	//管理接口
public:
	//开始服务
	virtual bool __cdecl StartService();
	//停止服务
	virtual bool __cdecl StopService();
	//设置接口
	virtual bool __cdecl SetTimerEngineSink(IUnknownEx * pIUnknownEx);

	//内部函数
private:
	//定时器通知
	void OnTimerThreadSink();
};

//////////////////////////////////////////////////////////////////////////

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -