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

天行健 君子當自強而不息

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>
            久久久亚洲影院你懂的| 免费av成人在线| 国产精品乱子乱xxxx| 在线一区二区三区四区| 一区二区欧美在线观看| 国产欧美精品一区| 久久精品视频在线| 久久久一区二区| 亚洲精品视频二区| 在线亚洲精品| 国产一区二区三区在线观看免费| 久久精品五月| 蜜桃久久精品一区二区| 99国产成+人+综合+亚洲欧美| 99精品99| 激情伊人五月天久久综合| 亚洲高清在线视频| 欧美日韩在线不卡| 欧美一级大片在线观看| 久久久久成人精品| 一区二区冒白浆视频| 亚洲专区一区二区三区| 一区二区三区在线看| 亚洲国产经典视频| 国产精品亚洲片夜色在线| 久久综合亚洲社区| 国产精品mm| 嫩草影视亚洲| 国产精品美女在线观看| 欧美xx视频| 国产精品久久久久久久久婷婷| 久久久久国产精品www| 欧美激情一区二区三区蜜桃视频| 欧美一级午夜免费电影| 蜜臀av性久久久久蜜臀aⅴ四虎| 亚洲小说春色综合另类电影| 久久精品亚洲国产奇米99| 中日韩高清电影网| 老鸭窝毛片一区二区三区| 午夜精品在线| 欧美黄在线观看| 欧美一区=区| 欧美色123| 欧美激情一区二区三区在线视频观看 | 欧美一区综合| 亚洲精品中文字幕在线| 久久国产精品久久久| 香港成人在线视频| 欧美日韩精品综合| 亚洲国产精品一区二区三区| 国户精品久久久久久久久久久不卡| 欧美 日韩 国产在线 | 久久精品卡一| 午夜精品影院在线观看| 欧美午夜不卡| 亚洲精品国产视频| 日韩亚洲国产欧美| 欧美精品激情在线| 亚洲黄色大片| 亚洲乱码国产乱码精品精98午夜| 欧美一区国产在线| 香蕉久久久久久久av网站| 欧美午夜剧场| 一区二区三区欧美成人| 亚洲一区二区三区免费观看 | 欧美激情久久久久| 亚洲黑丝在线| 一区二区三区精品国产| 欧美精品v国产精品v日韩精品 | 久久精品一区| 国产亚洲欧美色| 久久国产一区二区| 久久在线免费观看| 亚洲国产成人porn| 免费欧美在线| 亚洲精品免费在线| 亚洲欧美偷拍卡通变态| 国产精品日日摸夜夜添夜夜av| 中文国产一区| 久久精品国亚洲| 在线观看不卡av| 免费在线国产精品| 亚洲每日在线| 欧美专区在线观看| 精品福利av| 欧美精品在线视频| 亚洲一区综合| 欧美承认网站| 在线亚洲精品| 国产一区激情| 欧美激情视频在线免费观看 欧美视频免费一| 亚洲国产精品第一区二区三区| 9l国产精品久久久久麻豆| 国产精品激情电影| 久久久久在线| 99国产麻豆精品| 久热精品视频在线观看| 日韩视频精品在线观看| 国产欧美日韩精品专区| 老色批av在线精品| 亚洲图片欧美日产| 欧美福利电影在线观看| 亚洲欧美一区二区精品久久久| 激情文学综合丁香| 欧美性一区二区| 久久视频精品在线| 亚洲性感激情| 欧美福利一区二区| 欧美一级二区| 一区二区高清| 在线观看视频亚洲| 国产精品免费看久久久香蕉| 巨乳诱惑日韩免费av| 亚洲欧美日本国产有色| 亚洲人午夜精品免费| 久久久久se| 欧美一级淫片aaaaaaa视频| 亚洲精品网站在线播放gif| 国产伦理一区| 国产精品福利在线观看| 欧美电影在线观看完整版| 小黄鸭精品密入口导航| 99v久久综合狠狠综合久久| 欧美不卡激情三级在线观看| 性久久久久久| 亚洲天堂成人| 99在线精品视频| 亚洲精选久久| 亚洲国产精品一区二区www| 国产日韩欧美一区二区| 国产精品每日更新| 欧美日韩日日夜夜| 欧美激情在线播放| 欧美91福利在线观看| 久久久综合网| 久久久久久久综合| 欧美一区二区成人| 午夜精品成人在线视频| 亚洲一级片在线观看| 日韩亚洲在线观看| 亚洲精品欧美一区二区三区| 欧美激情一区二区| 亚洲国产裸拍裸体视频在线观看乱了中文| 久久蜜桃香蕉精品一区二区三区| 午夜在线电影亚洲一区| 午夜精品久久久久久| 午夜精品美女自拍福到在线| 亚洲网站在线播放| 亚洲女人小视频在线观看| 亚洲一区二区三区激情| 香蕉久久精品日日躁夜夜躁| 欧美在线关看| 久久免费99精品久久久久久| 久久亚洲二区| 欧美高清在线| 亚洲日本中文字幕| 在线综合亚洲欧美在线视频| 亚洲欧美激情一区二区| 欧美一区二区精品| 久久久一区二区三区| 免费成人美女女| 欧美精品色网| 国产精品乱人伦中文| 国内揄拍国内精品少妇国语| 在线看欧美视频| 一本色道久久99精品综合 | 亚洲欧美日韩第一区| 欧美综合国产| 欧美mv日韩mv亚洲| 99精品国产高清一区二区| 亚洲综合视频1区| 久久免费国产精品| 欧美精品日韩精品| 国产伦精品一区二区三区照片91 | 欧美日韩黄色一区二区| 国产精品一区亚洲| 悠悠资源网亚洲青| 99爱精品视频| 久久精品男女| 亚洲精品在线电影| 久久国产精品久久久| 欧美经典一区二区三区| 国产精品网红福利| 亚洲国产欧美一区二区三区同亚洲 | 久久夜色精品国产噜噜av| 免费av成人在线| 欧美日韩在线电影| 黄色精品一二区| 亚洲性图久久| 你懂的国产精品永久在线| 一区二区三区欧美日韩| 久久麻豆一区二区| 国产精品欧美日韩一区| 亚洲激情综合| 久久久久成人精品| 亚洲伊人一本大道中文字幕| 欧美激情偷拍| 亚洲国产99| 久久只精品国产| 亚洲欧洲av一区二区三区久久|