您的位置:首页 > 其它

根据时间和类型生成一个唯一的id

2016-07-20 10:18 441 查看
NLMISC::CEntityId CNewIdBuilder::getNewEntityId()

{
uint32 now = NLMISC::CTime::getSecondsSince1970();
if (now > mCreateIdLastTime)
{
mCreateIdLastTime = now;
mShortId = 0;
}

if (mShortId >= MAX_ID_PER_SEC)
{
++mCreateIdLastTime;
mShortId = 0;

nlwarning("getNewEntityId typeId = [%d] diff = [%d]", mTypeId, (mCreateIdLastTime - now));
}

uint32 fullId = (uint32)(mCreateIdLastTime<<5) + mShortId;
++mShortId;
return NLMISC::CEntityId(mTypeId, fullId);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: