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

天行健 君子當(dāng)自強(qiáng)而不息

Getting Online with Multiplayer Gaming(18)

 

Updating the Local Player

Between updates from the server, the clients need to update all players to keep the
game running smoothly. The client application limits updates to every 33ms (30 times
a second), which matches the server update rate. Between these player updates, the
client is allowed to collect input from the player who is used to change their actions.

The cApp::frame function is generally used to update the local player. The players
use the keyboard and mouse to control their characters, so I included a few Input
Core objects (m_keyboard and m_mouse):

bool cApp::frame()
{
    
// get local input every frame
    m_keyboard.acquire();
    m_mouse.acquire();
    m_keyboard.read();
    m_mouse.read();

    
// handle connection screen
    if(!g_connected || m_players[0].player_id == 0)
    {
        
// display connection message

        clear_display(0, 1.0f);

        
if(begin_display_scene())
        {
            draw_font(m_font, "Connecting to server ", 0, 0, 0, 0, COLOR_WHITE, DT_LEFT);
            end_display_scene();
        }

        present_display();
        
return true;
    }

    
// store movements every frame

    
static long move_action = 0, last_move = 0;

    
if(m_keyboard.get_key_state(KEY_UP) || m_keyboard.get_key_state(KEY_W))
        move_action |= ACTION_MOVE_UP;

    
if(m_keyboard.get_key_state(KEY_RIGHT)  || m_keyboard.get_key_state(KEY_D))
        move_action |= ACTION_MOVE_RIGHT;

    
if(m_keyboard.get_key_state(KEY_DOWN)  || m_keyboard.get_key_state(KEY_S))
        move_action |= ACTION_MOVE_DOWN;

    
if(m_keyboard.get_key_state(KEY_LEFT)  || m_keyboard.get_key_state(KEY_A))
        move_action |= ACTION_MOVE_LEFT;

    
// store attack action
    if(m_keyboard.get_key_state(KEY_SPACE) || m_mouse.get_button_state(MOUSE_LBUTTON))
        move_action |= ACTION_ATTACK;

    
// rotate camera

    
static bool cam_moved = false;

    
if(m_mouse.get_x_delta() > 0)
    {
        m_cam_angle -= 0.1f;
        cam_moved = 
true;
    }

    
if(m_mouse.get_x_delta() < 0)
    {
        m_cam_angle += 0.1f;
        cam_moved = 
true;
    }

    
static DWORD update_counter = timeGetTime();

    
// only update players every 33ms (30 times a second)
    if(timeGetTime() < update_counter + 33)
        
return true;

    
// set flag to allow player movement
    bool allow_move = true;

    
// do not allow movement if still swinging weapon or being hurt
    if(m_players[0].last_state == STATE_SWING || m_players[0].last_state == STATE_HURT)
        allow_move = 
false;

    
// handle movements if allowed
    if(allow_move)
    {
        
// process attack
        if(move_action & ACTION_ATTACK)
        {
            move_action = 0;    
// clear movement
            last_move   = 0;    // clear last movement

            // send attack message - let server signal swing

            sStateChangeMsg change_msg;

            change_msg.header.type      = MSG_STATE_CHANGE;
            change_msg.header.size      = 
sizeof(sStateChangeMsg);
            change_msg.header.player_id = m_players[0].player_id;
            change_msg.state            = STATE_SWING;
            change_msg.direction        = m_players[0].direction;

            send_network_msg(&change_msg, DPNSEND_NOLOOPBACK);
        }

        
// process local player movements
        if(move_action > 0 && move_action < 13)
        {
            
// set new player state
            
            EnterCriticalSection(&m_update_cs);

            m_players[0].last_state = STATE_MOVE;
            m_players[0].direction  = g_angles[move_action] - m_cam_angle + 4.71f;

            LeaveCriticalSection(&m_update_cs);

            
// reset last move if camera moved since last update
            if(cam_moved)
            {
                cam_moved = 
false;
                last_move = 0;
            }

            
// send actions to server if changed from last move
            if(move_action != last_move)
            {
                last_move = move_action;    
// store last action

                m_players[0].last_update_time = timeGetTime();

                sStateChangeMsg change_msg;

                
// construct message
                change_msg.header.type      = MSG_STATE_CHANGE;
                change_msg.header.size      = 
sizeof(sStateChangeMsg);
                change_msg.header.player_id = m_players[0].player_id;
                change_msg.state            = STATE_MOVE;
                change_msg.direction        = m_players[0].direction;

                send_network_msg(&change_msg, DPNSEND_NOLOOPBACK);
            }
        }
        
else
        {
            
// change to idle state
            EnterCriticalSection(&m_update_cs);
            m_players[0].last_state = STATE_IDLE;
            LeaveCriticalSection(&m_update_cs);

            
// send update only if player moved last update
            if(last_move)
            {
                last_move = 0;

                sStateChangeMsg change_msg;

                change_msg.header.type      = MSG_STATE_CHANGE;
                change_msg.header.size      = 
sizeof(sStateChangeMsg);
                change_msg.header.player_id = m_players[0].player_id;
                change_msg.state            = STATE_IDLE;
                change_msg.direction        = m_players[0].direction;

                send_network_msg(&change_msg, DPNSEND_NOLOOPBACK);
            }
        }
    }

    update_all_players();
    render_scene();

    move_action = 0;                    
// clear action data for next frame
    update_counter = timeGetTime();     // reset update counter

    
return true;
}

At every frame, the input devices are restored (in case a device’s focus has been
lost), and input is read in. If the user presses Esc, the game-play quits by returning
a value of false from the frame function.

From here, game-play may only continue if the client is connected to the server.
If no such connection exists, a message displays to that effect. Also, if a player is
still waiting for a DirectPlay identification number from the server, a message displays,
and a request is periodically sent to the server for the correct identification
number.

From here on, player input is parsed. A single variable tracks player actions (move_action),
and each bit in the variable represents a specific action (as shown in Figure 19.17). The
user’s actions are move up, move down, move left, move right, and attack. Also, camera
angle changes are recorded (and flagged for later updating).

Normally, players are allowed to move around the world, but if a player is currently
swinging his weapon or being hurt, that player is not allowed to move. You use the
allow_move flag to signify when a player’s actions can be processed, as shown here:

If a player chooses to attack, you need to construct a state-change message and
send that message to the server. After you send the state-change message, clear the
player’s movement actions. Notice that the client does not change its own state at
this point; the server determines when to change the player’s state.

If the player did not attack, his actions are checked to see whether the player is
moving.

After the player’s state and movement direction is set, the Frame function continues
by resetting the camera’s movements (by setting the cam_move flag to false). The
player’s controls are relative to the camera-viewing angle (if the player is pressing
the up arrow key, he is walking away from the camera). If you change the camera’s
angle while the player is walking, you force the player’s direction to change as well.
The client takes this change of the player’s direction into consideration when the
camera is rotated.

Once a player has moved, the client sends a state-change message to the server.
Notice that the state-change message is sent only if the player’s movement is different
from the last move he performed (as recorded in the last_move variable).

If the player hasn’t moved, his state is changed to standing still (STATE_IDLE), and a
state-change message is sent to the server.

At this point, the local player’s actions have been recorded and sent to the server.
Next, all players are updated, the scene is rendered, and the movement actions are
reset for the next frame.

posted on 2007-12-19 17:22 lovedday 閱讀(233) 評(píng)論(0)  編輯 收藏 引用


只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導(dǎo)航

統(tǒng)計(jì)

常用鏈接

隨筆分類(178)

3D游戲編程相關(guān)鏈接

搜索

最新評(píng)論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            欧美成年人视频| 国产精品wwwwww| 国产色综合久久| 性欧美1819sex性高清| 日韩视频专区| 欧美色图天堂网| 欧美亚洲网站| 欧美资源在线观看| 亚洲大胆在线| 亚洲精品国精品久久99热一| 欧美精品在线看| 亚洲综合色噜噜狠狠| 欧美亚洲系列| 最新中文字幕一区二区三区| 亚洲另类一区二区| 国产伦精品免费视频| 免费短视频成人日韩| 亚洲国产精品一区制服丝袜| 欧美日韩国产综合新一区| 亚洲欧美日韩区| 久久久久久久综合| 亚洲一级片在线观看| 亚洲欧美日韩国产成人精品影院| 国产视频综合在线| 亚洲精品日韩久久| 国产伦精品一区| 亚洲第一区在线观看| 国产精品私人影院| 欧美a一区二区| 国产精品一区二区久久久| 久久综合给合久久狠狠狠97色69| 欧美精品在线观看一区二区| 午夜久久久久| 欧美国产日韩在线观看| 久久久国产午夜精品| 欧美日韩一区二区在线视频| 老司机精品视频一区二区三区| 欧美日一区二区在线观看| 麻豆精品视频在线观看视频| 国产精品九九久久久久久久| 欧美福利视频在线| 免费看成人av| 久久精品国产一区二区三区免费看| 欧美成人免费全部| 久久嫩草精品久久久精品一| 欧美三级电影精品| 亚洲成人在线免费| 亚洲高清视频中文字幕| 国产精品99久久久久久www| 亚洲国产精品欧美一二99| 午夜在线观看免费一区| 亚洲天堂成人在线视频| 欧美激情第六页| 欧美大片在线观看一区二区| 国产主播一区二区三区| 亚洲免费一在线| 亚洲影视中文字幕| 欧美日韩一区二区欧美激情| 亚洲国产精品久久久| 亚洲国产91| 久久久综合网站| 免费久久精品视频| 在线免费观看日本一区| 久久久久免费视频| 免费久久99精品国产自| 一区二区三区在线视频观看| 久久国产一区二区| 玖玖玖国产精品| 在线看片日韩| 免费久久久一本精品久久区| 欧美电影专区| 亚洲美女在线观看| 欧美在线不卡视频| 久久蜜桃香蕉精品一区二区三区| 国产综合视频| 久久精品综合一区| 欧美顶级大胆免费视频| 亚洲精品影视| 欧美日韩中文精品| 亚洲一区二区三区四区五区黄| 亚洲欧美制服另类日韩| 国产精品自拍小视频| 欧美资源在线| 亚洲国产欧美日韩精品| av成人手机在线| 国产精品久久久久三级| 欧美一区二区三区男人的天堂| 久久久午夜电影| 亚洲三级电影全部在线观看高清| 亚洲欧美另类在线| 久久久综合网| 亚洲欧洲一区二区天堂久久| 欧美日韩免费精品| 午夜亚洲一区| 亚洲第一精品夜夜躁人人爽| 中文日韩在线| 国产亚洲高清视频| 男人的天堂成人在线| 99国产精品久久久久久久| 久久精品亚洲一区| 99视频精品全部免费在线| 国产精品入口| 欧美黄色aa电影| 亚洲欧美网站| 亚洲欧洲一区二区三区| 久久精品国产69国产精品亚洲| 亚洲第一页中文字幕| 国产精品久久久久久久久果冻传媒 | 在线观看亚洲a| 欧美视频官网| 免费欧美日韩国产三级电影| 中文网丁香综合网| 亚洲福利视频一区| 久久九九国产精品| 亚洲午夜精品久久久久久app| 国内精品国产成人| 欧美性天天影院| 欧美大片在线观看一区| 欧美一级视频免费在线观看| 一本色道久久综合一区| 欧美激情第9页| 久久狠狠亚洲综合| 午夜激情久久久| 亚洲视频每日更新| 亚洲人成高清| 亚洲国产另类 国产精品国产免费| 国产精品视频免费一区| 欧美日韩在线精品| 欧美xxx在线观看| 久久视频在线视频| 久久精品国产96久久久香蕉| 亚洲欧美第一页| 在线视频中文亚洲| 亚洲精品一区久久久久久| 欧美国产精品劲爆| 蜜桃久久av| 久久视频在线看| 久久尤物电影视频在线观看| 欧美一区在线直播| 欧美一区二区三区男人的天堂| 亚洲图片欧美日产| 亚洲视频在线观看视频| 在线视频免费在线观看一区二区| 亚洲欧洲一区二区三区在线观看 | 99视频精品在线| 亚洲日本久久| 99精品国产福利在线观看免费| 亚洲国产日韩欧美在线99 | 欧美精品成人在线| 欧美顶级大胆免费视频| 欧美精品国产一区| 欧美日韩一区免费| 欧美日韩直播| 国产欧美日韩在线观看| 国产亚洲高清视频| 亚洲第一成人在线| 91久久夜色精品国产网站| 亚洲理论在线| 亚洲午夜影视影院在线观看| 亚洲欧美综合另类中字| 久久久久国产精品一区三寸| 可以免费看不卡的av网站| 欧美成人精品高清在线播放| 亚洲国产毛片完整版| 一区二区三区鲁丝不卡| 亚洲欧美中文另类| 噜噜噜噜噜久久久久久91| 欧美国产日韩xxxxx| 欧美私人啪啪vps| 国产日韩亚洲| 亚洲精品日本| 亚洲免费小视频| 久久综合久久久久88| 亚洲激情视频网| 亚洲视频免费看| 久久精品一区| 欧美日韩亚洲一区| 国模私拍一区二区三区| 亚洲精品久久久久久久久久久久久 | 久久免费黄色| 欧美视频日韩视频| 国语精品一区| 亚洲无限乱码一二三四麻| 久久久女女女女999久久| 亚洲黄色精品| 欧美在线一二三区| 欧美日韩精品在线观看| 狠狠爱综合网| 亚洲欧美欧美一区二区三区| 嫩模写真一区二区三区三州| 亚洲视频免费| 欧美精品不卡| 在线观看一区二区精品视频| 亚洲主播在线| 亚洲高清影视| 久久久噜噜噜久久| 国产欧美一区二区精品性色| 在线性视频日韩欧美| 欧美成人四级电影| 久久精品国产一区二区电影 |