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

天行健 君子當自強而不息

Getting Online with Multiplayer Gaming(17)

 

Message Handling

The client application uses the same message structures as the server, but the client
has no need for queuing messages. As Figure 19.16 demonstrates, incoming messages
are immediately parsed by the client.

Now that you’ve seen the receive function that handles incoming message, it’s time
to examine each message handling function.

 

cApp::create_player

As clients join the game, the server informs other connected clients of those new
arrivals. The purpose of the following create_player function is to find room in the
sPlayer structure and store the player data:

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

    
// do not add local player to list
    if(create_msg->header.player_id == m_players[0].player_id)
        
return;

    
long player_index = -1;

    
for(long i = 1; i < MAX_PLAYERS; i++)
    {
        
if(m_players[i].connected)
        {
            
// makre sure player not already in list
            if(m_players[i].player_id == create_msg->header.player_id)
                
return;
        }
        
else
            player_index = i;
    }

    
if(player_index == -1)  // no open slots
        return;

    EnterCriticalSection(&m_update_cs);

    
// add player data
    m_players[player_index].connected  = true;
    m_players[player_index].player_id  = create_msg->header.player_id;
    m_players[player_index].x_pos      = create_msg->x_pos;
    m_players[player_index].y_pos      = create_msg->y_pos;
    m_players[player_index].z_pos      = create_msg->z_pos;
    m_players[player_index].direction  = create_msg->direction;
    m_players[player_index].speed      = 0.0f;
    m_players[player_index].last_state = STATE_IDLE;

    m_num_players++;

    LeaveCriticalSection(&m_update_cs);
}

 

cApp::destroy_player

The server notifies clients when a player is leaving a session. The clients, in turn,
signal the player as being disconnected and skips updating the player during the
update cycle. The following code determines which client is disconnected and
takes the appropriate steps:

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

    
// do not remove local player from list
    if(destroy_msg->header.player_id == m_players[0].player_id)
        
return;

    
long player_index = get_player_index(destroy_msg->header.player_id);
    
if(player_index == -1)
        
return;

    EnterCriticalSection(&m_update_cs);

    m_players[player_index].connected = 
false;
    m_num_players--;

    LeaveCriticalSection(&m_update_cs);
}
 

cApp::change_player_state

The client processes changes of state in players by pulling out the message data and
putting it in the player’s structure. If a player isn’t found in the list of players, the
client requests that player’s information via a MSG_GET_PLAYER_INFO message and exits the
change_player_state function without further ado.

This is the only situation in which a player’s coordinates can be directly modified
by a state change—clients are not allowed to make direct changes to their coordinates
(to avoid cheating), so it’s up to the server to tell players just where they are
in the world during the updates:

void cApp::change_player_state(const sMsg* msg)
{
    sStateChangeMsg* change_msg = (sStateChangeMsg*) msg;

    
long player_index = get_player_index(change_msg->header.player_id);

    
if(player_index == -1)  // unknown player - request information
    {
        sRequestPlayerInfoMsg request_msg;

        request_msg.header.type       = MSG_GET_PLAYER_INFO;
        request_msg.header.size       = 
sizeof(sRequestPlayerInfoMsg);
        request_msg.header.player_id  = m_players[0].player_id;
        request_msg.request_player_id = change_msg->header.player_id;

        send_network_msg(&request_msg, DPNSEND_NOLOOPBACK);
        
return;
    }

    EnterCriticalSection(&m_update_cs);

    
// store new player state information
    m_players[player_index].last_state = change_msg->state;
    m_players[player_index].x_pos      = change_msg->x_pos;
    m_players[player_index].y_pos      = change_msg->y_pos;
    m_players[player_index].z_pos      = change_msg->z_pos;
    m_players[player_index].direction  = change_msg->direction;
    m_players[player_index].speed      = change_msg->speed;
    m_players[player_index].latency    = change_msg->latency;

    
// bounds latency to 1 second
    if(m_players[player_index].latency > 1000)
        m_players[player_index].latency = 1000;

    
// adjust time based on latency
    m_players[player_index].last_update_time = timeGetTime() - m_players[player_index].latency;

    LeaveCriticalSection(&m_update_cs);
}

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

bool cApp::send_network_msg(void* msg, long send_flags)
{
    sMsgHeader* header = (sMsgHeader*) msg;

    
if(header->size == 0)
        
return false;

    
return m_client.send_data(msg, header->size, send_flags);
}

Just like the server, the client has a send_network_msg to send the game-related
network messages to the server.

NOTE
The client also depends on the latency time to modify
the timing calculations.The server sends this latency
time to the client, but to make things safe, the client
application is allowed to cut the latency down to one
second if the server states that it is higher.


posted on 2007-12-19 16:44 lovedday 閱讀(248) 評論(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>
            91久久精品国产91久久| 国产一区二区三区黄视频| 亚洲黄一区二区| 欧美成人免费播放| 欧美激情网友自拍| 免费在线一区二区| 亚洲成人在线网| 亚洲精品乱码久久久久久久久| 亚洲精品色图| 一区二区久久久久久| 亚洲欧美日韩精品久久| 久久久精品999| 欧美日韩国产美女| 国产精品三级久久久久久电影| 国产欧美日韩精品丝袜高跟鞋| 尤物精品国产第一福利三区| 亚洲毛片一区| 欧美一区二区三区在线| 亚洲国产精品999| 午夜精品久久久久久久99水蜜桃 | 久久国产乱子精品免费女| 久久久国产精品一区二区三区| 欧美1区3d| 国产精品午夜在线| 亚洲国产精品精华液网站| 亚洲无吗在线| 蜜臀av国产精品久久久久| 亚洲精品三级| 久久久精品日韩| 国产精品欧美久久| 亚洲精品国产无天堂网2021| 午夜激情久久久| 亚洲黄色免费| 久久激情五月丁香伊人| 欧美色网一区二区| 亚洲欧洲日本一区二区三区| 欧美在线高清视频| 亚洲美洲欧洲综合国产一区| 久热精品在线| 影音先锋日韩有码| 久久精品日韩一区二区三区| 欧美激情在线| 久久精品亚洲一区二区| 欧美体内she精视频| 91久久亚洲| 久久精品综合| 亚洲日韩中文字幕在线播放| 国产精品国产精品| 亚洲三级电影全部在线观看高清 | 亚洲一区二区在线视频| 欧美18av| 久久亚洲捆绑美女| 激情婷婷亚洲| 久久国产日韩欧美| 亚洲免费一在线| 国产精品99免费看 | 久久久久五月天| 国产一区在线观看视频| 久久av二区| 欧美在线网站| 黄色国产精品| 久久综合色88| 裸体丰满少妇做受久久99精品 | 亚洲精品一区中文| 欧美国产一区二区三区激情无套| 久久精品夜色噜噜亚洲a∨| 黄色一区二区在线观看| 女主播福利一区| 蜜桃av噜噜一区| 亚洲精品日韩在线观看| 91久久精品美女| 欧美日韩亚洲高清一区二区| 亚洲午夜羞羞片| 亚洲综合精品四区| 国内自拍视频一区二区三区| 久久久久久噜噜噜久久久精品 | 欧美丝袜一区二区三区| 亚洲免费视频网站| 午夜精品久久久久久久男人的天堂 | 国产午夜一区二区三区| 久久久久久久一区| 久久精品1区| 99热在线精品观看| 一本到12不卡视频在线dvd | 亚洲精品国产日韩| 在线综合亚洲| 国语精品一区| 亚洲日本va午夜在线电影 | 国产在线欧美日韩| 欧美一区二区三区在线免费观看| 亚洲电影视频在线| 亚洲精品在线看| 国产乱人伦精品一区二区| 欧美成人免费播放| 欧美吻胸吃奶大尺度电影| 久久国产黑丝| 蜜月aⅴ免费一区二区三区 | 欧美精品免费在线| 久久av一区二区三区漫画| 久久久久久久网站| 亚洲午夜伦理| 久久一二三四| 午夜精品久久99蜜桃的功能介绍| 久久欧美中文字幕| 亚洲欧美一区二区激情| 欧美91大片| 久久久之久亚州精品露出| 欧美日韩在线观看视频| 欧美成人一二三| 国产一区二区欧美日韩| 亚洲国产日韩欧美| 韩国福利一区| 亚洲欧美国产精品va在线观看| 亚洲夫妻自拍| 欧美一区=区| 亚洲欧美另类综合偷拍| 欧美国产另类| 久久在线视频在线| 国产精品天天看| 一个人看的www久久| 在线电影一区| 久久久精品动漫| 久久综合国产精品| 国产字幕视频一区二区| 亚洲自拍偷拍一区| 亚洲一区二区在线免费观看| 欧美电影在线| 亚洲国产午夜| 亚洲黄色天堂| 另类天堂av| 欧美xart系列高清| 亚洲承认在线| 欧美www视频在线观看| 亚洲成色777777女色窝| 怡红院精品视频在线观看极品| 午夜宅男久久久| 久久久久久久网站| 国产有码在线一区二区视频| 午夜精品福利一区二区三区av| 亚洲一区二区在线看| 国产精品国产亚洲精品看不卡15| 一本色道久久综合亚洲精品按摩 | 亚洲精品日韩在线观看| 欧美激情精品久久久| 亚洲精品视频免费在线观看| 亚洲精品一区二区三区不| 欧美国产一区在线| 亚洲精品亚洲人成人网| 亚洲欧美日韩精品综合在线观看| 亚洲精品自在久久| 日韩一级精品| 午夜精品久久久久久久蜜桃app | 久久久九九九九| 欧美黄色大片网站| 亚洲激情精品| 欧美日韩中文字幕| 亚洲欧美日本视频在线观看| 欧美专区第一页| 伊人久久大香线蕉综合热线| 玖玖在线精品| 一本大道av伊人久久综合| 午夜久久黄色| 在线播放日韩专区| 欧美日韩www| 亚洲午夜精品视频| 久久综合色8888| 亚洲深夜影院| 国产午夜精品视频| 欧美精品免费在线| 欧美一区二区三区日韩| 亚洲激情视频网站| 亚洲欧美日韩人成在线播放| 好吊色欧美一区二区三区四区 | 欧美日本国产精品| 午夜精品在线观看| 亚洲人成网站999久久久综合| 亚洲欧美另类久久久精品2019| 韩国成人福利片在线播放| 欧美日本高清一区| 久久亚洲国产精品一区二区| 亚洲美女免费视频| 欧美阿v一级看视频| 亚洲欧美色婷婷| 亚洲毛片在线免费观看| 国产综合av| 国产精品欧美一区喷水| 欧美二区不卡| 久久xxxx精品视频| 欧美性开放视频| 美女视频黄 久久| 性感少妇一区| 亚洲无限乱码一二三四麻| 欧美韩日一区二区三区| 久久精精品视频| 亚洲欧美在线免费| 亚洲私人影吧| 亚洲精品久久久久久久久久久| 国产一区二区三区不卡在线观看| 欧美欧美全黄| 欧美激情久久久久久|