Bool CApp::PostMsg(const XIDVector& vXID, CMsg* pMsg) { if (pMsg && vXID.size()) { Int32 iCount = GetThreadNum(); Assert(iCount > 0); map<Int32, XIDVector> mThreadXid; for(Size_t i=0;i<vXID.size();i++) { Int32 iIdx = vXID[i].Id % iCount; if (mThreadXid.find(iIdx) == mThreadXid.end()) mThreadXid[iIdx] = XIDVector(); mThreadXid[iIdx].push_back(vXID[i]); } map<Int32, XIDVector>::iterator it = mThreadXid.begin(); for (;it!=mThreadXid.end();it++) { CApp_MsgTask* pTask = new CApp_MsgTask(it->second, pMsg); CScope::ObjPtr scope(pTask); PostAppTask(pTask, it->first); } } g_MsgManager->FreeMsg(pMsg); return true; }
CApp_MsgTask(const XIDVector& vXid, CMsg* pMsg) : m_pMsg(pMsg) { for (Size_t i=0;i<vXid.size();i++) { m_vXid.push_back(vXid[i]); } };
CApp_TickTask(const XIDVector& vXid) { for (Size_t i=0;i<vXid.size();i++) { m_vXid.push_back(vXid[i]); } };
virtual void ResetXids(const XIDVector& vXid) { m_vXid.clear(); for (Size_t i=0;i<vXid.size();i++) { m_vXid.push_back(vXid[i]); } }
Bool CApp::PostTick(const XIDVector& vXID) { if (vXID.size()) { Int32 iCount = GetThreadNum(); Assert(iCount > 0); map<Int32, XIDVector> mThreadXid; for(Size_t i=0;i<vXID.size();i++) { Int32 iIdx = vXID[i].Id % iCount; if (mThreadXid.find(iIdx) == mThreadXid.end()) mThreadXid[iIdx] = XIDVector(); mThreadXid[iIdx].push_back(vXID[i]); } map<Int32, XIDVector>::iterator it = mThreadXid.begin(); for (;it!=mThreadXid.end();it++) { static map<Int32, CApp_TickTask> mTickTask; CApp_TickTask* pTask = 0; map<Int32, CApp_TickTask>::iterator tit = mTickTask.find(it->first); if (tit == mTickTask.end()) { mTickTask.insert(std::make_pair(it->first, CApp_TickTask(it->second))); pTask = &mTickTask.find(it->first)->second; } else { pTask = &tit->second; pTask->ResetXids(it->second); } if (pTask) { pTask->AddRef(); PostAppTask(pTask, it->first); } } } return true; }
Bool HawkAppFrame::BroadcastMsg(ObjMan* pObjMan, HawkMsg* pMsg) { if (pObjMan && pMsg) { XIDVector vXID; pObjMan->CollectObjKey(vXID); if (vXID.size()) PostMsg(vXID, pMsg); return true; } return false; }