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

            公告

            導航

            統計

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關鏈接

            搜索

            最新評論

            蜜臀av性久久久久蜜臀aⅴ| 狠狠久久亚洲欧美专区| 伊人久久大香线蕉AV色婷婷色| 人妻无码αv中文字幕久久琪琪布| 激情伊人五月天久久综合| 久久香蕉一级毛片| 精品久久久中文字幕人妻| 中文字幕亚洲综合久久| 久久一区二区免费播放| 伊人久久精品无码av一区| 久久99精品国产麻豆不卡| 国内精品综合久久久40p| 精品久久久久久无码中文字幕 | 久久精品国产2020| 久久久久女教师免费一区| 久久亚洲精品无码AV红樱桃| 一本久道久久综合狠狠躁AV| 久久99热狠狠色精品一区| 国内高清久久久久久| 亚洲精品乱码久久久久久不卡| 久久综合久久综合久久| 久久久精品人妻一区二区三区四 | 国内精品欧美久久精品| 国产精品福利一区二区久久| 亚洲AV无码久久精品色欲| 一极黄色视频久久网站| 久久人妻少妇嫩草AV蜜桃| 国产无套内射久久久国产| 久久久久综合网久久| 2020最新久久久视精品爱| 久久亚洲高清观看| 色噜噜狠狠先锋影音久久| 久久九九有精品国产23百花影院| 国产精品久久久亚洲| 久久综合九色综合精品| 热久久国产精品| 国内精品久久久久国产盗摄| 久久精品国产亚洲精品| 青青草原综合久久大伊人| 精品综合久久久久久97| 国产69精品久久久久久人妻精品|