Bool HsGame::OnException(Int32 iCode) { static XIDVector vXID; //系统异常, 通知玩家进行存储 ObjMan* pUserMan = GetObjMan(HSO_PLAYER); if (pUserMan) { vXID.clear(); if (!pUserMan->CollectObjKey(vXID)) return false; PostException(vXID, iCode); } //系统异常, 通知各个管理器进行存储 ObjMan* pManagerMan = GetObjMan(HSO_MANAGER); if (pManagerMan) { vXID.clear(); if (!pManagerMan->CollectObjKey(vXID)) return false; PostException(vXID, iCode); } return true; }
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; }
Bool HsGame::TickManagers() { ObjMan* pManagerMan = GetObjMan(HSO_MANAGER); if (pManagerMan) { static XIDVector vXID; vXID.clear(); if (!pManagerMan->CollectObjKey(vXID)) return false; return PostTick(vXID); } return false; }
Bool HsGame::TickPlayers() { ObjMan* pUserMan = GetObjMan(HSO_PLAYER); if (pUserMan) { static XIDVector vXID; vXID.clear(); if (!pUserMan->CollectObjKey(vXID)) return false; return PostTick(vXID); } return false; }
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; }
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; }