• <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 閱讀(124) 評論(0)  編輯 收藏 引用


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


            公告

            導(dǎo)航

            統(tǒng)計

            常用鏈接

            隨筆分類(178)

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

            搜索

            最新評論

            免费国产99久久久香蕉| 99久久中文字幕| 伊人久久五月天| 久久久无码精品亚洲日韩按摩| 91精品国产91久久综合| 久久综合视频网站| 天天爽天天狠久久久综合麻豆| 免费国产99久久久香蕉| 中文字幕乱码久久午夜| 99久久精品这里只有精品| 亚洲国产精品无码久久久蜜芽| 日韩一区二区久久久久久| 婷婷五月深深久久精品| 亚洲国产精品狼友中文久久久| 99久久精品国产麻豆| 亚洲中文字幕无码久久2020| 国产福利电影一区二区三区,免费久久久久久久精 | 久久精品国产亚洲5555| 少妇内射兰兰久久| 中文国产成人精品久久亚洲精品AⅤ无码精品 | 久久精品中文字幕久久| 性色欲网站人妻丰满中文久久不卡| 国产精品丝袜久久久久久不卡| 久久精品无码一区二区无码| 一级女性全黄久久生活片免费 | 久久亚洲国产成人精品性色| 久久久久国产亚洲AV麻豆| 99精品久久精品| 精品国产乱码久久久久久郑州公司 | 久久久久亚洲精品日久生情 | 国产成人精品久久二区二区| 亚洲国产精品久久久天堂| 久久狠狠爱亚洲综合影院| 99久久香蕉国产线看观香| 午夜精品久久久内射近拍高清| 精品久久久久久久久久中文字幕| 国内精品久久久久影院免费| 久久免费高清视频| 青青青国产成人久久111网站| 亚洲国产成人久久综合碰碰动漫3d | 欧美成a人片免费看久久|