青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

天行健 君子當自強而不息

Getting Online with Multiplayer Gaming(10)

 

DirectPlay Messages to Game Messages

As I’ve mentioned before, the server needs to convert the DirectPlay network messages
into the game-related messages you’ve just read about. You accomplish this by
processing incoming player connection, disconnection, and receive data messages from
DirectPlay and converting those messages into game messages.

To accomplish this conversion of messages, you derive a class from cNetworkServer
and override the create_player, destroy_player, and receive functions:

class cServer : public cNetworkServer
{
protected:
    
virtual bool create_player(const DPNMSG_CREATE_PLAYER* msg);
    
virtual bool destroy_player(const DPNMSG_DESTROY_PLAYER* msg);
    
virtual bool receive(const DPNMSG_RECEIVE* msg);
};

Because I’m using the System Core to handle application processing, a problem
quickly arises when dealing with the network. The network component and application
component are two separate entities, which means that neither component is
allowed to modify the other's private data.

As Figure 19.11 illustrates, the network component needs a way to siphon incoming
messages into the application, which by chance is handled by creating three public
functions that match the network class’s functions.

To use the three message functions in the application component, you construct a
derived cFramework class that contains the three public functions as follows:

class cApp : public cFramework
{
private:
    HWND                m_controls[3];
    
    CRITICAL_SECTION    m_msg_cs;
    cMesh               m_level_mesh;

    GUID*               m_adapter_guid;
    cNetworkAdapter     m_adapter;
    cServer             m_server;

    
long                m_connected_player_num; 
    sPlayer*            m_players;

    sMsg*               m_msgs;
    
long                m_msg_head;
    
long                m_msg_tail;

    
///////////////////////////////////////////////////////////////////////////////

public:
    
void set_adapter_guid(GUID* adapter_guid)
    {
        m_adapter_guid = adapter_guid;
    }

public:
    cApp();
    
    
virtual bool init();
    
virtual bool frame();
    
virtual void shutdown();

    
void create_player(const DPNMSG_CREATE_PLAYER* msg);
    
void destroy_player(const DPNMSG_DESTROY_PLAYER* msg);
    
void receive(const DPNMSG_RECEIVE* msg);

private:
    
bool select_adapter();
    
void setup_app_window();
    
bool init_game();
    
bool host_game();    

    
void list_players();

    
void process_queue_msg();
    
void update_players();
    
void update_network();
    
void update_latency();

    
bool send_player_info(const sMsg* msg, DPNID to);
    
bool queue_msg(const void* msg);
    
bool add_player(const sMsg* msg);
    
void remove_player(const sMsg* msg);
    
bool player_state_change(const sMsg* msg);

    
bool send_network_msg(void* msg, long send_flags, int to);

    
bool check_intersect(cMesh* mesh,
                         
float x_start, float y_start, float z_start,
                         
float x_end,   float y_end,   float z_end);
};

To start sending DirectPlay messages to the application class, you code the overridden
cServer functions to call upon the matching application functions. In order for the
server to know which application class instance to send messages to, you need to
declare a global variable that points to the current application class instance in use:

cApp* g_app;
cNetworkAdapter* g_adapter;

Inside the derived application class’s constructor, you then point the global
g_app variable to the application class instance:

cApp::cApp()
{    
    m_adapter_guid = NULL;
    m_msgs         = NULL;
    m_msg_head     = 0;
    m_msg_tail     = 0;

    m_connected_player_num = 0;
    m_players = NULL;

    g_app     = 
this;
    g_adapter = &m_adapter;

    InitializeCriticalSection(&m_msg_cs);
}

Now, you can code the network server component to send incoming messages to
the application object defined by the global g_app pointer:


bool cServer::create_player(const DPNMSG_CREATE_PLAYER* msg)
{
    g_app->create_player(msg);

    
return true;
}

bool cServer::destroy_player(const DPNMSG_DESTROY_PLAYER* msg)
{
    g_app->destroy_player(msg);

    
return true;
}

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

    
return true;
}

The server component is now complete and is forwarding network messages to the
application class. To convert those network messages to game-related messages,
the application class must contain the following public functions:


void cApp::create_player(const DPNMSG_CREATE_PLAYER* msg)
{
    sCreatePlayerMsg create_msg;

    create_msg.header.type      = MSG_CREATE_PLAYER;
    create_msg.header.size      = 
sizeof(sCreatePlayerMsg);
    create_msg.header.player_id = msg->dpnidPlayer;

    queue_msg(&create_msg);
}

///////////////////////////////////////////////////////////////////////////////////////

void cApp::destroy_player(const DPNMSG_DESTROY_PLAYER* msg)
{
    sDestroyPlayerMsg destroy_msg;

    destroy_msg.header.type      = MSG_DESTROY_PLAYER;
    destroy_msg.header.size      = 
sizeof(sDestroyPlayerMsg);
    destroy_msg.header.player_id = msg->dpnidPlayer;

    queue_msg(&destroy_msg);
}

///////////////////////////////////////////////////////////////////////////////////////

void cApp::receive(const DPNMSG_RECEIVE* msg)
{
    sMsgHeader* header = (sMsgHeader*) msg->pReceiveData;

    
// make sure it is a valid message type and queue it
    switch(header->type)
    {
    
case MSG_SEND_PLAYER_INFO:
    
case MSG_STATE_CHANGE:
        queue_msg(msg->pReceiveData);
        
break;
    }
}

You can see that in each of the three functions, I’m constructing a game-related
message using the data from the DirectPlay messages provided. When a player tries
to connect to the server, a create-player message is created that stores the connecting
player’s DirectPlayer identification number (along with the message type and size).
That create-player message is then queued.

As for players disconnecting from the game, a disconnect-player message is constructed
and queued. Last, whenever data (other than a system message) is
received from a client, the cApp::receive function checks it to see whether it’s a valid
message type, and if so, the message is queued.

I keep mentioning the message queue and how the previously shown function adds
messages to the queue. Next, you find out what the queue is and how it works.

posted on 2007-12-18 20:35 lovedday 閱讀(258) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導航

統計

常用鏈接

隨筆分類(178)

3D游戲編程相關鏈接

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            午夜免费日韩视频| 欧美诱惑福利视频| 欧美精品v日韩精品v国产精品 | 免费在线观看成人av| 性欧美1819sex性高清| 国产欧美一区二区精品性| 亚洲综合色自拍一区| 亚洲欧美成人一区二区三区| 国产精品毛片a∨一区二区三区| 亚洲欧美中文日韩v在线观看| 亚洲免费视频一区二区| 国产一区视频在线看| 麻豆精品在线视频| 欧美+亚洲+精品+三区| 一本色道久久综合亚洲精品按摩| 亚洲毛片在线| 国产亚洲成年网址在线观看| 欧美 亚欧 日韩视频在线| 欧美电影免费观看网站| 亚洲尤物在线| 久久岛国电影| 日韩视频永久免费观看| 亚洲一区激情| 在线观看欧美日韩| 99成人在线| 韩国久久久久| 日韩视频在线永久播放| 国产欧美一区二区三区在线老狼| 久久综合精品一区| 欧美调教vk| 久久资源av| 国产精品护士白丝一区av| 久久深夜福利免费观看| 欧美日韩美女在线| 久久免费精品日本久久中文字幕| 欧美黄色免费网站| 久久久91精品| 欧美三级电影精品| 欧美91精品| 国产女同一区二区| 亚洲人成网站999久久久综合| 欧美视频你懂的| 欧美成人亚洲| 国产婷婷色一区二区三区四区| 欧美国产日本韩| 国产裸体写真av一区二区| 欧美激情成人在线| 国内久久婷婷综合| 亚洲一区二区在线观看视频| 亚洲国产欧美一区| 久久精品免费电影| 久久aⅴ国产欧美74aaa| 欧美日韩成人综合| 欧美黄色免费网站| 在线成人中文字幕| 欧美一区二区三区日韩| 午夜精品久久久久久久白皮肤| 欧美劲爆第一页| 亚洲福利视频一区二区| 黄色资源网久久资源365| 亚洲一区二区三区视频| 亚洲午夜一区二区三区| 欧美日本三区| 亚洲国内欧美| 亚洲精品国产拍免费91在线| 久久久久久伊人| 美日韩在线观看| 国模吧视频一区| 久久久久久国产精品mv| 久久婷婷国产综合尤物精品| 国产亚洲欧洲997久久综合| 亚洲欧美日韩在线观看a三区| 午夜伦理片一区| 国产免费一区二区三区香蕉精| 亚洲专区一二三| 久久国产精品毛片| 国内久久精品| 久久久夜夜夜| 亚洲国产精品一区| 日韩视频三区| 国产精品初高中精品久久| 99精品久久| 午夜精品一区二区三区在线| 国产日韩av一区二区| 久久riav二区三区| 欧美1级日本1级| 日韩一区二区精品葵司在线| 欧美日韩国产探花| 亚洲一区视频| 久久婷婷国产综合尤物精品| 亚洲国产精品激情在线观看| 欧美风情在线观看| 亚洲深夜福利网站| 久久人人爽人人爽| 亚洲另类自拍| 国产精品人成在线观看免费 | 日韩视频一区二区在线观看 | 亚洲一品av免费观看| 欧美日韩在线亚洲一区蜜芽| 亚洲香蕉伊综合在人在线视看| 久久九九免费视频| 亚洲精品久久久久久久久久久久久| 欧美日韩一区国产| 久久成人国产| 亚洲美女黄色| 久久午夜影视| 亚洲一区二区在| 激情综合色综合久久综合| 欧美日韩1080p| 久久成人精品| 99pao成人国产永久免费视频| 久久aⅴ国产紧身牛仔裤| 亚洲激情精品| 国产午夜精品视频| 欧美日韩成人网| 欧美在线观看网址综合| 亚洲三级免费| 久久亚洲精品中文字幕冲田杏梨| 一区二区av在线| 亚洲国产成人精品久久| 国产精品久久久久久久久久久久久 | 一区二区高清视频| 免费一级欧美片在线播放| 亚洲欧美制服另类日韩| 亚洲免费观看高清在线观看 | 欧美丝袜一区二区三区| 久久天天躁夜夜躁狠狠躁2022 | 亚洲淫性视频| 日韩午夜在线播放| 亚洲第一综合天堂另类专| 久久裸体艺术| 欧美中文字幕| 亚洲欧美国产77777| 夜夜嗨av一区二区三区网站四季av | 欧美日韩黄视频| 免费观看成人www动漫视频| 亚洲欧美日韩人成在线播放| 亚洲国产成人不卡| 欧美国产高潮xxxx1819| 六月天综合网| 久久综合久久88| 久久亚洲影院| 久久久久久久久蜜桃| 久久精品欧美日韩| 久久精品日韩| 欧美在线视频免费观看| 亚洲欧美精品伊人久久| 一区二区三区产品免费精品久久75| 91久久精品一区二区别| 亚洲成人在线| 在线成人欧美| 亚洲高清在线视频| 最新国产精品拍自在线播放| 在线电影国产精品| 激情视频亚洲| 最近中文字幕mv在线一区二区三区四区 | 欧美日韩国产黄| 欧美午夜a级限制福利片| 国产精品jizz在线观看美国 | 欧美韩国一区| 欧美色123| 国产伦精品一区二区三区照片91| 国产精品制服诱惑| 一区二区三区在线观看视频| 亚洲成在人线av| 日韩亚洲欧美成人一区| 亚洲一区二区三区高清不卡| 欧美在线视频观看| 裸体一区二区三区| 亚洲国产裸拍裸体视频在线观看乱了 | 久久精品国产视频| 欧美成人资源| 一区二区毛片| 久久精品国产在热久久| 欧美大尺度在线观看| 国产精品福利在线观看| 国外成人网址| 一区二区三区日韩| 久久精品国产久精国产思思 | 一区二区欧美精品| 久久精品国产亚洲一区二区三区| 久久夜色精品国产欧美乱极品| 亚洲国产日韩欧美| 亚洲欧美日韩精品一区二区| 久久天堂精品| 国产精品欧美一区二区三区奶水| 精品成人免费| 亚洲综合电影一区二区三区| 乱码第一页成人| 亚洲视频在线观看| 欧美成人精品不卡视频在线观看| 国产精品久久久亚洲一区| 亚洲成人在线网| 亚洲欧美清纯在线制服| 欧美成人午夜影院| 篠田优中文在线播放第一区| 欧美精品日韩www.p站| 精品1区2区3区4区| 欧美一级二级三级蜜桃| 亚洲精品在线看|