• <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>

            天行健 君子當自強而不息

            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)  編輯 收藏 引用

            公告

            導航

            統計

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關鏈接

            搜索

            最新評論

            日日狠狠久久偷偷色综合0| 狠狠久久综合伊人不卡| 精品久久久久久无码不卡| 久久精品国产亚洲av麻豆图片| 精品伊人久久大线蕉色首页| 日韩人妻无码精品久久久不卡| 亚洲综合精品香蕉久久网97| 亚洲精品综合久久| 久久精品国产99久久久| 久久天天躁狠狠躁夜夜av浪潮 | 秋霞久久国产精品电影院| 久久影视国产亚洲| 色偷偷久久一区二区三区| 久久嫩草影院免费看夜色| 国产精品美女久久久| 欧美亚洲国产精品久久| 99久久www免费人成精品| 久久精品中文字幕无码绿巨人| 久久伊人影视| 精品久久久无码中文字幕天天| 欧美黑人又粗又大久久久| 怡红院日本一道日本久久 | 久久精品国产亚洲AV大全| 久久国产视屏| 一本大道加勒比久久综合| av国内精品久久久久影院| 一本一本久久aa综合精品 | 久久精品国产亚洲沈樵| 波多野结衣AV无码久久一区| 亚洲国产精品成人久久蜜臀| 久久er国产精品免费观看2| 久久ww精品w免费人成| 精品熟女少妇av免费久久| 久久丫精品国产亚洲av不卡 | 久久精品国产69国产精品亚洲| 一本色道久久99一综合| 亚洲精品无码久久久久去q| 2021国内精品久久久久久影院| 久久无码AV中文出轨人妻| 久久影视综合亚洲| 精品综合久久久久久98|