GS Package to MS (GS,MS packet interaction process) Example: people on-line first look at how to determine which map of the database first only save a mapid at the time of initialization of the share has initialized all the map, and saved the map pointer information, the key is MapID if(Ractorex.getmapid () <=0) Ractorex.setmapid (1009);intMapID =ractorex.getmapid (); Ractorex.m_nbodyid= M_pshare->tgetnbodyid (Ractorex.getprof (), Ractorex.getsex ());//now that Bodyid used it.M_pmap= M_pshare->getmapbymapid (MapID);//map pointer information can be obtained by MapIDif(!M_pmap) {M_actorid=0; return;} M_pmap->gs2msdata (Gs2ms_add_player, M_nchannelid, (void*) &ractorex,sizeof(Ractorex));//incoming Ms,m_pmap is the player location map pointervoidMap::gs2msdata (intCmdintCHANNEL_ID,void* Data,intLen) {MAPPKT pkt; Pkt.channelid=channel_id; Pkt.data= M_MEMPOOL.POPPKT (len);//allocate a piece of memory from the memory pool, the new one used previously, and then this new is easy to fail.memcpy (pkt.data, data, Len); Pkt.len=Len; Pkt.cmd=cmd; PUSHPKT (PKT);}//The next step is the role of the thread .voidthrtransdata::P ushpkt (mappkt Pkt) {#ifdef Boost_lockfree for (;;) { if(M_gs2mspkts2.push (PKT))//put this package in a lock-free queue Break; Cxx11::this_thread::interruptible_wait (1); }#else{Cxx11::lock_guardLock(m_mtxgs2ms); M_quegs2mspkts.push (PKT); }#endif};voidThrtransdata::threadloop () {//setthreadpriority (GetCurrentThread (), thread_priority_highest);mappkt Pkt; Try { intNcount =0; while(true) { if(Getdatafromqueue (&PKT))//fetching packets from the lock-free queue{processpkt (Pkt); M_MEMPOOL.PUSHPKT (Pkt.data, Pkt.len); Ncount++; if(Ncount > -) {ncount=0; M_sptimerfactory-Drivetimer (); } Continue; } {m_sptimerfactory-Drivetimer (); if(m_bstopwork) Break; Cxx11::this_thread::interruptible_wait (1); } } } Catch(...) { Charszmsg[ the] = {0}; sprintf (szmsg,"'%s ' thread%dmap:P kt.cmd =%d", __function__,:: GetCurrentThreadID (), pkt.cmd); Safe::error_msg (szmsg); }}voidMap::P rocesspkt (mappkt pkt) {//... //Gs2ms_add_player belongs to GS and MS Communication internal Protocol, the internal Protocol adopts the form of tree, parallel relationship is too much management inconvenient Else if(Gs2ms_add_player = = pkt.cmd)//The player enters the map message, just a small example{Playerchannel* PPC =NewPlayerchannel ( This);//This playerchannel is a lot of a module, player information, look back again//added to the map, but the player is not activated intNchannelid = ppc->Onplayerenter (Pkt.data, Pkt.len); M_vecplayerchannel[nchannelid]=PPC; Addplayer (Nchannelid); } //...}
GS contract to MS