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

天行健 君子當自強而不息

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 閱讀(253) 評論(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>
            一区二区三区国产精品| 亚洲一区二区黄| 亚洲激情av| 美女主播视频一区| 99热在线精品观看| 亚洲一区二区成人| 国产精品国产精品国产专区不蜜| 国产精品家庭影院| 欧美va日韩va| 久久不见久久见免费视频1| 噜噜噜躁狠狠躁狠狠精品视频 | 亚洲一区二区在线免费观看视频| 久久不射2019中文字幕| 久久久www成人免费精品| 国产综合欧美| 嫩草国产精品入口| 99国产欧美久久久精品| 久热精品视频在线观看| 亚洲一区二区三区中文字幕| 亚洲欧美日韩综合| 国产欧美综合一区二区三区| 在线视频精品一区| 亚洲精品久久久一区二区三区| 亚洲电影第1页| 欧美日韩成人在线观看| 久久久国产亚洲精品| 一区二区三区日韩| 久久久最新网址| 亚洲欧美国产精品桃花| 亚洲国产成人久久综合| 国产日韩一区二区三区在线播放 | 亚洲一区在线直播| 亚洲国产精品黑人久久久| 欧美一区=区| 亚洲一区二区免费看| 亚洲伦理在线观看| 亚洲视频成人| 西瓜成人精品人成网站| 久久免费的精品国产v∧| 久久精品国产99精品国产亚洲性色 | 性色av一区二区三区| 日韩一级大片| 99国产一区| 一本在线高清不卡dvd| 亚洲国产mv| 国产资源精品在线观看| 狠狠色狠色综合曰曰| 国产精品久久久久国产精品日日| 久久av一区二区三区漫画| 亚洲一区在线免费| 美女黄毛**国产精品啪啪| 欧美久久久久久久久| 欧美经典一区二区三区| 在线精品视频一区二区三四| 亚洲第一福利社区| 小辣椒精品导航| 亚洲第一精品在线| 欧美搞黄网站| 91久久国产综合久久| 亚洲伦理久久| 麻豆精品精华液| 国产一区二区三区日韩| 久久婷婷久久| 午夜日韩在线观看| 欧美亚洲在线播放| 欧美激情第9页| 亚洲午夜一区| 亚洲欧美另类国产| 亚洲欧美日韩国产另类专区| 午夜精品福利在线| 中文一区字幕| 久久伊人一区二区| 亚洲福利免费| 日韩视频免费| 亚洲乱码一区二区| 麻豆成人综合网| 久久久久久综合| 麻豆av一区二区三区| 亚洲精品综合在线| 亚洲欧美日韩第一区| 国产精品在线看| 麻豆精品在线观看| 亚洲专区在线| 亚洲精品一二三| 欧美国产精品一区| 蜜臀av性久久久久蜜臀aⅴ四虎| 国产欧美日韩三区| 国产精品天天看| 亚洲午夜免费视频| 中文在线资源观看网站视频免费不卡 | 国产精品xxxxx| 午夜视频在线观看一区| 欧美亚洲一区三区| 在线看片欧美| 99riav国产精品| 国产精品永久免费| 91久久精品一区二区三区| 99国产精品国产精品毛片| 亚洲精品国产精品久久清纯直播| 欧美国产精品久久| 久久综合一区二区三区| 嫩草影视亚洲| 麻豆九一精品爱看视频在线观看免费| 欧美激情综合色综合啪啪| 亚洲电影视频在线| 欧美亚洲一区| 一区二区三区四区蜜桃| 亚洲免费观看在线视频| 国产一区二区三区久久 | 美女999久久久精品视频| 夜色激情一区二区| 久久亚洲国产精品一区二区| 亚洲天堂久久| 理论片一区二区在线| 欧美成人按摩| 黄色精品免费| 欧美精品一区在线播放| 夜夜嗨av一区二区三区免费区| 久久先锋资源| 亚洲国产精品久久久久| 欧美日韩伊人| 亚洲一区二区免费| 久久精品国产清高在天天线| 国产在线不卡精品| 欧美一区二区视频观看视频| 你懂的视频一区二区| 亚洲欧美经典视频| 久久日韩精品| 亚洲电影观看| 久久国产黑丝| 欧美一级午夜免费电影| 有码中文亚洲精品| 久久国产精品久久久久久电车| 亚洲精品日产精品乱码不卡| 鲁大师影院一区二区三区| 亚洲一区二区视频在线| 激情五月婷婷综合| 国产亚洲成av人在线观看导航 | 亚洲一区亚洲| 久久久精品久久久久| 麻豆成人小视频| 麻豆成人av| 久久国产成人| 亚洲欧美日韩视频二区| 亚洲成色999久久网站| 国产日本亚洲高清| 在线不卡a资源高清| 亚洲国产老妈| 亚洲天堂网在线观看| 亚洲视频中文| 性高湖久久久久久久久| 亚洲欧美日韩在线高清直播| 午夜在线电影亚洲一区| 国产在线麻豆精品观看| 欧美日本一区二区视频在线观看| 久久久久久久久综合| 亚洲国产精品成人久久综合一区| 免费日韩av| 一道本一区二区| 亚洲日本va午夜在线电影| 亚洲精品一区二区三区在线观看| 亚洲深夜福利| 美女精品在线| 亚洲电影免费在线| 亚洲在线一区二区| 欧美高清成人| 激情欧美日韩| 在线一区观看| 亚洲精品午夜| 欧美日韩精品不卡| 99国产精品久久久久老师| 欧美gay视频| 久久男人资源视频| 亚洲国产精选| 亚洲另类视频| 欧美日韩午夜剧场| 亚洲国产高清自拍| 久久综合色婷婷| 亚洲在线播放电影| 国产精品久久毛片a| av成人免费观看| 欧美一区二区三区视频免费| 亚洲久久成人| 国产亚洲欧洲一区高清在线观看| 性欧美精品高清| aa国产精品| 欧美精品在线一区二区三区| aa日韩免费精品视频一| 亚洲精品免费一区二区三区| 一区二区三区精品视频在线观看| 国产精品久久久久久久久| 久久久国产一区二区三区| 久久―日本道色综合久久| 亚洲理论在线| 国内精品久久久久久久97牛牛| 亚洲电影第1页| 久久精品99国产精品| 老鸭窝毛片一区二区三区| 亚洲一区高清| 欧美日韩免费在线视频|