• <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)鏈接

            搜索

            最新評論

            久久久久无码精品国产| 99久久精品国产麻豆| 久久亚洲AV无码精品色午夜| 东方aⅴ免费观看久久av| 人人狠狠综合久久亚洲88| 国产成人综合久久精品红| 精品久久久久久中文字幕| 久久久久久伊人高潮影院| 国产精品激情综合久久| 青草国产精品久久久久久| 日韩十八禁一区二区久久| 久久国产一区二区| 国色天香久久久久久久小说 | 婷婷久久五月天| 久久久九九有精品国产| 亚洲va久久久噜噜噜久久狠狠| 91精品国产91热久久久久福利| 亚洲AV无码1区2区久久| 少妇熟女久久综合网色欲| 久久99精品久久久久久秒播| 精品国产福利久久久| 久久久久人妻一区二区三区vr| 久久香综合精品久久伊人| 久久久久亚洲AV无码专区桃色| 久久香蕉综合色一综合色88| 久久人妻少妇嫩草AV无码专区 | 日韩人妻无码一区二区三区久久 | 久久精品?ⅴ无码中文字幕| 狠狠色噜噜狠狠狠狠狠色综合久久| 中文字幕久久精品无码| 亚洲欧洲久久av| 久久人人爽人人人人片av| 久久这里只有精品首页| 国产香蕉久久精品综合网| 久久人妻无码中文字幕| 久久精品国产99国产精品导航| 国产成人久久精品一区二区三区| 久久伊人五月丁香狠狠色| 久久精品无码专区免费东京热| 精品国产福利久久久| 久久99久久成人免费播放|