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

天行健 君子當自強而不息

Getting Online with Multiplayer Gaming(13)

 

cApp::remove_player

Just as players join the game, so do players quit, and that’s the purpose of the
remove_player function. In the remove_player function, the server will scan the list of
connected players for a match of a DirectPlay identification number (from the disconnecting
player) and remove that player from the list. After the scan is complete
and the appropriate player is removed from the list, all clients are notified of the
disconnecting player, and the server rebuilds a list of existing players.

void cApp::remove_player(const sMsg* msg)
{
    
// search for player in list
    for(long i = 0; i < MAX_PLAYERS; i++)
    {
        
if(m_players[i].player_id == msg->header.player_id && m_players[i].connected)
        {
            m_players[i].connected = 
false;

            
// send remove player message to all players

            sDestroyPlayerMsg destroy_msg;

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

            send_network_msg(&destroy_msg, DPNSEND_NOLOOPBACK, ALL_CLIENT_PLAYERS);

            m_connected_player_num--;
            list_players();

            
break;
        }
    }
}
 

cApp::send_player_info

Unfortunately, in network gaming, game messages sometimes get lost along the
way. What if one of those lost messages intended to inform the client application
that a player had joined the game? Furthermore, what if the client started receiving
messages related to a player that the client didn’t know existed (because of a lost
message)?

In cases where the client has no knowledge of a player and is receiving messages
related to that player, the client will request the appropriate player’s data from the
server in order to continue. The server, in turn, will send the requested player’s
information to the client using the send_player_info function:

bool cApp::send_player_info(const sMsg* msg, DPNID to)
{
    sRequestPlayerInfoMsg* request_msg = (sRequestPlayerInfoMsg*) msg;

    
for(long i = 0; i < MAX_PLAYERS; i++)
    {
        
// only send if found in list
        if(m_players[i].player_id == request_msg->request_player_id && m_players[i].connected)
        {
            
// send player infomation to requesting player

            sCreatePlayerMsg create_msg;

            create_msg.header.type      = MSG_SEND_PLAYER_INFO;
            create_msg.header.size      = 
sizeof(sCreatePlayerMsg);
            create_msg.header.player_id = request_msg->request_player_id;
            create_msg.x_pos            = m_players[i].x_pos;
            create_msg.y_pos            = m_players[i].y_pos;
            create_msg.z_pos            = m_players[i].z_pos;
            create_msg.direction        = m_players[i].direction;

            send_network_msg(&create_msg, DPNSEND_NOLOOPBACK, to);

            
break;
        }
    }

    
return true;
}
 

cApp::player_state_change

The major message-processing function in the server must be player_state_change,
which takes incoming actions from the clients and updates the internal player data.

bool cApp::player_state_change(const sMsg* msg)
{
    
// get player index in list
    long player_index = -1;
    
    
for(long i = 0; i < MAX_PLAYERS; i++)
    {
        
if(m_players[i].player_id == msg->header.player_id && m_players[i].connected)
        {
            player_index = i;
            
break;
        }
    }

    
if(player_index == -1)
        
return false;

    sPlayer* player = &m_players[player_index];

    
bool allow_change = true;
    
    
// refuse to update player if swinging sword or hurt
    if(player->last_state == STATE_SWING || player->last_state == STATE_HURT)
        allow_change = 
false;    

    
// only change state if allowed
    if(! allow_change)
        
return false;

    sStateChangeMsg* change_msg = (sStateChangeMsg*) msg;

    
// update selected player
    player->last_update_time = timeGetTime();
    player->last_state       = change_msg->state;
    player->direction        = change_msg->direction;

    
// adjust action time based on latency
    player->last_update_time -= player->latency;

    sStateChangeMsg state_msg;

    
// send player data to all clients
    state_msg.header.type      = MSG_STATE_CHANGE;
    state_msg.header.size      = 
sizeof(sStateChangeMsg);
    state_msg.header.player_id = change_msg->header.player_id;
    state_msg.state            = player->last_state;
    state_msg.x_pos            = player->x_pos;
    state_msg.y_pos            = player->y_pos;
    state_msg.z_pos            = player->z_pos;
    state_msg.direction        = player->direction;
    state_msg.speed            = player->speed;

    send_network_msg(&state_msg, DPNSEND_NOLOOPBACK, ALL_CLIENT_PLAYERS);

    
if(change_msg->state != STATE_SWING)
        
return true;

    
// If swinging sword, determing who is hurt, check all players.
    for(long i = 0; i < MAX_PLAYERS; i++)
    {
        
// only check against other players that are connected
        if(i == player_index || !m_players[i].connected)
            
continue;

        
// get distance to player
        float x_diff = fabs(player->x_pos - m_players[i].x_pos);
        
float z_diff = fabs(player->z_pos - m_players[i].z_pos);
        
float dist   = x_diff * x_diff + z_diff * z_diff;

        
// continue if distance between players acceptable
        if(dist >= 10000.0f)
            
continue;

        
// get angle between players
        float angle = -atan2(m_players[i].z_pos - player->z_pos, m_players[i].x_pos - player->x_pos) + 1.570796f;

        angle -= player->direction;     
// adjust for attacker's direction
        angle += 0.785f;                // adjust for FOV

        // bounds angle value
        if(angle < 0.0f)        angle += 6.28f;
        
if(angle >= 6.28f)      angle -= 6.28f;

        
// player hit if in front of attacker (90 FOV)
        if(angle >= 0.0f && angle <= 1.570796f && m_players[i].last_state != STATE_HURT)
        {
            m_players[i].last_state = STATE_HURT;
            m_players[i].last_update_time = timeGetTime();

            
// send network message
            state_msg.header.type      = MSG_STATE_CHANGE;
            state_msg.header.size      = 
sizeof(sStateChangeMsg);
            state_msg.header.player_id = m_players[i].player_id;
            state_msg.state            = m_players[i].last_state;
            state_msg.x_pos            = m_players[i].x_pos;
            state_msg.y_pos            = m_players[i].y_pos;
            state_msg.z_pos            = m_players[i].z_pos;
            state_msg.direction        = m_players[i].direction;
            state_msg.speed            = m_players[i].speed;

            send_network_msg(&state_msg, DPNSEND_NOLOOPBACK, ALL_CLIENT_PLAYERS);
        }
    }

    
return true;
}

Up to this point, the server has looked for the player that uses the state-change
message. If a message is coming from a player who is not connected, the message
is ignored. From now on, the game’s logic takes over.

Players are allowed to walk, stand still, or swing their weapons. Players whose states
are already set as swinging their weapons or being hurt are not allowed to update
their states (until those states are cleared).

Now the player’s state is updated (if allowed) and sent out to all other connected
players. Next, if the player has swung his weapon, all players are scanned to see
whether the attacker hit them. If so, the states of those hurt are changed to HURT.

Also, notice that I offset the state’s time variable (sPlayer::last_update_time) by the player’s
latency value (sPlayer::latency). This adjusts for network transmission delays and
improves synchronization. If you remove the latency offset, you’ll see a jumping
effect when players are moving around the level.

Note that players who are swinging their swords have a chance to hit the players in
front of them. To check whether another player was hit during an attack, you first
perform a distance calculation, and if any characters are considered close enough,
the angles between the players are checked. If the players being attacked are within
a 90-degree field of view in front of the attackers (as illustrated in Figure 19.14),
they are considered hit, at which point, those victims’ states are changed to HURT.

And that’s it for dealing with the game messages and state changes in players.
Although the player_state_change function is responsible for parsing the queued game
messages, it’s really up to another function to move players and clear their swinging
or hurt states, as you see in the following section.

posted on 2007-12-18 22:39 lovedday 閱讀(246) 評論(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>
            欧美激情精品久久久久久大尺度| 欧美日韩午夜| 在线国产精品播放| 裸体一区二区三区| 免费在线一区二区| 日韩一级免费| 亚洲一区二区3| 国产精品一二三视频| 久久久噜噜噜久久久| 久久夜色精品国产欧美乱| 亚洲精品一级| 中文精品在线| 好吊妞**欧美| 亚洲精品国产拍免费91在线| 欧美日韩成人综合天天影院| 欧美有码在线视频| 裸体歌舞表演一区二区 | 欧美一级日韩一级| 影音先锋一区| 99re66热这里只有精品3直播| 国产精品日产欧美久久久久| 久久久伊人欧美| 欧美黄色大片网站| 午夜欧美视频| 欧美韩日一区| 久久久久久一区| 欧美日韩国产123区| 久久精品国产91精品亚洲| 老司机凹凸av亚洲导航| 午夜精品一区二区三区在线播放| 久久久久在线观看| 西瓜成人精品人成网站| 毛片基地黄久久久久久天堂| 午夜久久资源| 欧美日韩a区| 免费影视亚洲| 国产亚洲福利| av成人激情| 日韩视频免费在线观看| 欧美在线看片a免费观看| 在线亚洲免费| 欧美顶级大胆免费视频| 久久国产99| 欧美午夜精彩| 日韩视频一区二区三区在线播放免费观看| 国产一区二区三区高清在线观看| 日韩亚洲欧美一区| 亚洲人在线视频| 久久婷婷国产综合精品青草| 欧美综合国产精品久久丁香| 欧美日韩在线影院| 亚洲人妖在线| 99精品视频免费全部在线| 美女爽到呻吟久久久久| 久久久久久久国产| 国产一区二区三区久久 | 欧美+亚洲+精品+三区| 国产一二精品视频| 欧美一级在线播放| 欧美一区在线看| 国产欧美日韩高清| 亚洲小说欧美另类婷婷| 亚洲午夜日本在线观看| 欧美日韩在线影院| 日韩午夜激情av| 亚洲一二区在线| 国产精品黄色| 亚洲一区区二区| 久久国产手机看片| 国产一区二区三区免费在线观看| 午夜精品免费视频| 久久精品水蜜桃av综合天堂| 国产欧美日韩一区二区三区在线| 香蕉乱码成人久久天堂爱免费| 香蕉乱码成人久久天堂爱免费 | 久久久另类综合| 欧美国产欧美综合| 亚洲免费观看视频| 欧美午夜精品理论片a级按摩| 这里只有精品视频| 久久精品国内一区二区三区| 黄色成人在线网站| 猛干欧美女孩| 日韩一区二区精品视频| 亚洲欧美在线视频观看| 国产一区二区三区无遮挡| 久久久综合免费视频| 亚洲激情一区| 欧美在线影院| 亚洲日本电影在线| 国产精品va在线播放| 欧美一级夜夜爽| 亚洲成色999久久网站| 亚洲一区二区三区色| 国产中文一区| 欧美激情a∨在线视频播放| 一区二区欧美激情| 久久综合九色综合网站| 亚洲麻豆av| 国产一区高清视频| 欧美激情在线观看| 午夜精品一区二区三区在线| 欧美福利小视频| 亚洲在线视频观看| 在线国产精品播放| 国产精品久久久久77777| 久久综合久久久久88| 亚洲一区二区三区在线播放| 欧美岛国在线观看| 久久国产精品第一页| 99精品国产福利在线观看免费| 国产一区导航| 欧美色图首页| 欧美国产日本| 久久亚洲私人国产精品va| 亚洲少妇中出一区| 亚洲黄色免费| 久久综合久色欧美综合狠狠| 亚洲一区二区免费看| 亚洲人成啪啪网站| 一色屋精品视频免费看| 国产精品系列在线播放| 欧美日韩一区三区四区| 欧美电影在线观看| 久久综合九色综合久99| 欧美一区2区三区4区公司二百| 99在线精品视频| 亚洲品质自拍| 亚洲黄色在线视频| 欧美成人精品在线播放| 久久综合中文| 久久深夜福利免费观看| 久久爱www| 久久精品一二三| 久久国产精品99国产| 欧美在线观看视频一区二区| 亚洲欧美一区二区三区在线| 一区二区三区免费看| 亚洲美女av网站| 亚洲美女在线看| 一本色道久久88精品综合| 亚洲卡通欧美制服中文| 亚洲精品国产精品国自产观看| 亚洲国产成人91精品| 91久久线看在观草草青青| 136国产福利精品导航网址| 1769国产精品| 亚洲美女免费精品视频在线观看| 最新中文字幕亚洲| 亚洲乱亚洲高清| 亚洲午夜久久久| 欧美一区二区观看视频| 久久精品国产99国产精品| 久久一二三四| 欧美sm视频| 亚洲精品专区| 亚洲免费影视第一页| 久久精品99国产精品| 久久亚洲综合色一区二区三区| 欧美成人在线免费观看| 欧美日韩一区二区三区视频| 国产精品网红福利| 黄色亚洲网站| 日韩午夜电影| 欧美一区二区三区男人的天堂| 久久久久久成人| 亚洲第一精品影视| 亚洲午夜精品网| 久久婷婷综合激情| 欧美日韩另类国产亚洲欧美一级| 国产精品一级二级三级| 亚洲第一天堂av| 亚洲视频1区| 久久综合精品一区| 亚洲九九爱视频| 欧美制服丝袜| 欧美日韩不卡一区| 国产一区91精品张津瑜| 99re6这里只有精品| 欧美中文日韩| 亚洲美女精品久久| 久久精品国产亚洲高清剧情介绍 | 亚洲一区二区动漫| 麻豆成人精品| 国产欧美一区二区三区另类精品| 亚洲国产精品一区二区第一页 | 亚洲国产综合视频在线观看| 亚洲免费伊人电影在线观看av| 蜜桃av一区二区在线观看| 国产农村妇女毛片精品久久莱园子 | 欧美中文字幕第一页| 欧美精品www| 狠狠色丁香婷婷综合影院| 亚洲在线观看视频| 亚洲二区免费| 久久免费偷拍视频| 国产欧美一区二区白浆黑人| 亚洲午夜伦理| 亚洲精品一区二区三区蜜桃久| 久久夜色精品一区|