• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天行健 君子當(dāng)自強而不息

            Getting Online with Multiplayer Gaming(16)

             

            The Network Component

            To use a client component, you have to derive a class from it and, in that derived
            class, override the necessary functions. Those functions are few and are needed
            only to convey when a connection to the server is achieved or to receive incoming
            game messages.

            To use the client network component, begin by deriving your own class from
            cNetworkClient:

            class cClient : public cNetworkClient
            {
            private:
                
            virtual bool connect_complete(const DPNMSG_CONNECT_COMPLETE* msg);
                
            virtual bool receive(const DPNMSG_RECEIVE* msg);
            };

            To pass messages to the application, the derived application object needs only one
            public function to siphon in received messages. Why only one? The client needs to
            know when a connection is established to the server, which is the purpose of the
            connect_complete function.

            By using a global variable (g_connected) that represents the connection status, the
            client network component can update the state of the connection as follows:

            #define CLIENT_WIDTH        640
            #define CLIENT_HEIGHT       480

            #define ACTION_MOVE_UP      1
            #define ACTION_MOVE_RIGHT   2
            #define ACTION_MOVE_DOWN    4
            #define ACTION_MOVE_LEFT    8
            #define ACTION_ATTACK       16

            cApp*               g_app;
            cNetworkAdapter*    g_adapter;

            bool                g_connected;

            const float g_angles[13] = { 0.0f, 
                                         0.0f, 1.57f, 0.785f, 3.14f,     
                                         0.0f, 2.355f, 0.0f, 4.71f, 
                                         5.495f, 0.0f, 0.0f, 3.925f };

            /****************************************************************************************************/

            bool cClient::connect_complete(const DPNMSG_CONNECT_COMPLETE* msg)
            {
                g_connected = (msg->hResultCode == S_OK);
                g_app->set_local_player(msg->dpnidLocal);

                
            return true;
            }

            bool cClient::receive(const DPNMSG_RECEIVE* msg)
            {
                g_app->receive(msg);

                
            return true;
            }


            /****************************************************************************************************/


            void cApp::set_local_player(DPNID player_id)
            {
            EnterCriticalSection(&m_update_cs);

            m_players[0].player_id = player_id;

            LeaveCriticalSection(&m_update_cs);
            }


            Use the matching cApp::receive function for the cClient::receive function:

            bool cApp::receive(const DPNMSG_RECEIVE* msg)
            {
                sMsg* msg_ptr = (sMsg*) msg->pReceiveData;

                
            switch(msg_ptr->header.type)
                {
                
            case MSG_GET_PLAYER_INFO:   // add  a player to list
                case MSG_CREATE_PLAYER:
                    create_player(msg_ptr);
                    
            break;

                
            case MSG_DESTROY_PLAYER:    // remove a player from list
                    destroy_player(msg_ptr);
                    
            break;

                
            case MSG_STATE_CHANGE:      // change state of player
                    change_player_state(msg_ptr);
                    
            break;
                }

                
            return true;
            }

            Notice that the receive function immediately processes incoming messages appropriately
            by calling separate functions for each type of game message.

            posted on 2007-12-19 16:21 lovedday 閱讀(127) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            公告

            導(dǎo)航

            統(tǒng)計

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關(guān)鏈接

            搜索

            最新評論

            久久婷婷五月综合97色直播| 久久综合给久久狠狠97色| 精品久久久久久无码中文野结衣| 久久99热这里只有精品66| 国产成人综合久久综合| 久久毛片一区二区| 久久精品国产99国产精品| 久久精品天天中文字幕人妻| 亚洲国产精品无码久久青草| 国产毛片久久久久久国产毛片 | 伊人久久大香线蕉综合热线| 亚洲国产精品18久久久久久| 久久久久久久91精品免费观看| 精品久久久久久久久中文字幕| 久久棈精品久久久久久噜噜| 久久久久久青草大香综合精品| 国内精品久久久久影院一蜜桃| 欧美一区二区三区久久综合| 久久精品三级视频| 免费观看成人久久网免费观看| 久久电影网一区| 久久久无码精品亚洲日韩按摩 | 蜜桃麻豆www久久| 久久天堂AV综合合色蜜桃网| 日本WV一本一道久久香蕉| 久久久久亚洲爆乳少妇无| 香蕉aa三级久久毛片| 久久久亚洲AV波多野结衣 | 久久伊人五月天论坛| 美女写真久久影院| 久久精品一区二区| 久久精品www人人爽人人| 人妻无码中文久久久久专区| 欧美亚洲国产精品久久久久| 亚洲一级Av无码毛片久久精品| 色悠久久久久久久综合网| 久久久久久久亚洲精品| 合区精品久久久中文字幕一区| 欧美日韩精品久久久久| 思思久久99热只有频精品66| 亚洲国产成人乱码精品女人久久久不卡 |