📄 delaygroup.cpp
字号:
// DelayGroup.cpp: implementation of the CDelayGroup class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "DelayGroup.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMemoryPoolTempl<CDelayGroup::CDelay>* CDelayGroup::m_pDelayPool = NULL;
DWORD CDelayGroup::m_PoolRefCount = 0;
DWORD CDelayGroup::MakeKey(WORD Kind,WORD Idx)
{
return (Kind << 16) | Idx;
}
CDelayGroup::CDelayGroup()
{
if(m_pDelayPool == NULL)
m_pDelayPool = new CMemoryPoolTempl<CDelay>;
#ifdef _MAPSERVER_
m_pDelayPool->Init(1024,128,"CDelayGroup");
#else
m_pDelayPool->Init(16,16,"CDelayGroup");
#endif
++m_PoolRefCount;
m_DelayedTable.Initialize(16);
}
CDelayGroup::~CDelayGroup()
{
Release();
if(m_PoolRefCount == 0)
{
static BOOL bMsgBox = TRUE;
if(bMsgBox)
MessageBox(0,"DelayGroup 捞 捞惑窍促!!",0,0);
return;
}
--m_PoolRefCount;
if(m_PoolRefCount == 0)
{
m_pDelayPool->Release();
delete m_pDelayPool;
m_pDelayPool = NULL;
}
}
void CDelayGroup::Init()
{
Release();
}
void CDelayGroup::Release()
{
m_DelayedTable.SetPositionHead();
while(CDelay* pDelay = m_DelayedTable.GetData())
{
m_pDelayPool->Free(pDelay);
}
m_DelayedTable.RemoveAll();
}
float CDelayGroup::CheckDelay(WORD Kind,WORD Idx)
{
DWORD key = MakeKey(Kind,Idx);
CDelay* pDelay = m_DelayedTable.GetData(key);
if(pDelay == NULL)
return 0;
DWORD Elapsed = gCurTime - pDelay->StartTime;
float rate = 1 - (Elapsed/(float)pDelay->DelayTime);
// 掉饭捞啊 场车栏搁 掉饭捞甫 绝浚促.
if(rate <= 0)
{
m_pDelayPool->Free(pDelay);
m_DelayedTable.Remove(key);
return 0;
}
return rate;
}
void CDelayGroup::AddDelay(WORD Kind,WORD Idx,DWORD DelayTime)
{
DWORD key = MakeKey(Kind,Idx);
CDelay* pDelay = m_DelayedTable.GetData(key);
// 扁粮 掉饭捞啊 乐栏搁 盎脚茄饶 府畔茄促.
if(pDelay)
{
pDelay->StartTime = gCurTime;
pDelay->DelayTime = DelayTime;
return;
}
// 绝菌栏搁 货肺 眠啊茄促.
pDelay = m_pDelayPool->Alloc();
pDelay->Kind = Kind;
pDelay->Idx = Idx;
pDelay->StartTime = gCurTime;
pDelay->DelayTime = DelayTime;
m_DelayedTable.Add(pDelay,key);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -