GS contract to MS

Source: Internet
Author: User

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 (&AMP;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.