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

天行健 君子當自強而不息

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 閱讀(226) 評論(0)  編輯 收藏 引用

公告

導航

統計

常用鏈接

隨筆分類(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国产精品私拍| 国产主播一区| 亚洲最黄网站| 激情欧美日韩一区| 99精品国产在热久久| 国产亚洲精品激情久久| 亚洲国产精品t66y| 国产精品普通话对白| 欧美福利视频在线| 国产美女诱惑一区二区| 欧美风情在线观看| 国产美女在线精品免费观看| 亚洲精品九九| 一区在线免费| 午夜精品成人在线视频| 一区二区冒白浆视频| 久久久国产成人精品| 亚洲一区二区三区四区五区黄 | 欧美成人午夜视频| 国产视频欧美| 亚洲一区美女视频在线观看免费| 亚洲福利在线视频| 香蕉久久国产| 性久久久久久久久| 欧美日韩免费观看一区| 欧美国产另类| 永久免费视频成人| 欧美中文在线观看| 香蕉av777xxx色综合一区| 欧美精品乱码久久久久久按摩| 久久久999精品视频| 国产精品福利网站| 91久久精品www人人做人人爽| 黑人一区二区| 久久99伊人| 亚洲永久精品大片| 欧美国产亚洲视频| 欧美电影免费观看大全| 狠狠综合久久av一区二区小说| 亚洲一区二区三区中文字幕在线| 亚洲伦理在线观看| 欧美精品97| 日韩视频一区二区在线观看 | 美国成人直播| 免费一级欧美片在线观看| 国内偷自视频区视频综合| 欧美亚洲免费电影| 久久国产欧美精品| 很黄很黄激情成人| 久久噜噜亚洲综合| 欧美黑人一区二区三区| 亚洲国产精品久久91精品| 久久综合狠狠综合久久综合88| 美女网站在线免费欧美精品| 在线电影院国产精品| 美女脱光内衣内裤视频久久网站| 欧美成人免费全部观看天天性色| 一区三区视频| 欧美精品一区二区三区久久久竹菊 | 国产精品区一区| 午夜在线观看免费一区| 久久午夜精品| 亚洲精品网站在线播放gif| 欧美噜噜久久久xxx| 中文欧美字幕免费| 久久夜色精品国产| 亚洲伦理久久| 国产日产欧美一区| 久久在线视频| 制服丝袜激情欧洲亚洲| 久久精选视频| 日韩午夜电影av| 国产精品一香蕉国产线看观看| 久久激情中文| 日韩一二三区视频| 久久亚洲精品网站| 一区二区三区**美女毛片| 国产精品一区二区男女羞羞无遮挡| 欧美一区国产一区| 亚洲精品欧美精品| 欧美一区影院| 日韩午夜在线| 国产亚洲成人一区| 欧美日韩精品二区第二页| 欧美一区2区三区4区公司二百| 欧美电影免费观看大全| 性做久久久久久免费观看欧美 | 欧美亚男人的天堂| 久久综合久久88| 亚洲一区二区久久| 亚洲精美视频| 久久视频一区| 亚洲专区在线视频| 亚洲欧洲一级| 精品动漫一区二区| 国产精品日韩在线| 欧美女同在线视频| 蜜臀99久久精品久久久久久软件| 亚洲在线观看免费视频| 亚洲国产视频一区二区| 久久亚洲美女| 久久成人资源| 亚洲自拍高清| 亚洲视频免费看| 亚洲精品黄色| 在线成人欧美| 欲色影视综合吧| 国内精品嫩模av私拍在线观看 | 久久精品国产精品亚洲综合| 亚洲欧美日韩国产一区| 日韩视频一区二区三区| 亚洲国内自拍| 欧美激情免费观看| 暖暖成人免费视频| 久久久伊人欧美| 久久xxxx精品视频| 久久久久久久久久久久久久一区| 午夜精品短视频| 亚洲欧美第一页| 亚洲欧美怡红院| 亚洲欧美激情四射在线日| 亚洲自拍偷拍一区| 亚洲——在线| 亚洲欧美日韩中文在线制服| 亚洲资源在线观看| 性欧美激情精品| 久久久国产精品亚洲一区| 久久亚洲春色中文字幕| 久久久一本精品99久久精品66| 久久久久综合| 欧美α欧美αv大片| 欧美黄色精品| 91久久精品国产91久久性色tv| 亚洲国产日本| 日韩亚洲国产精品| 亚洲图片在线| 欧美在线播放| 久久亚洲精品欧美| 欧美精品一区在线播放| 国产精品草莓在线免费观看| 国产精品日产欧美久久久久| 国产一区在线看| 亚洲精品国产精品久久清纯直播| 日韩视频一区二区三区在线播放| 99精品99| 欧美在线欧美在线| 欧美aⅴ99久久黑人专区| 亚洲国产网站| 亚洲一二三区在线观看| 欧美在线观看视频| 欧美精品二区| 国产欧美一级| 亚洲人成7777| 午夜一区二区三视频在线观看| 久久精品99国产精品日本| 欧美第一黄网免费网站| 国产精品99久久久久久久女警| 欧美在线你懂的| 欧美激情一区二区三区蜜桃视频| 国产精品伦一区| 亚洲第一精品在线| 亚洲影视九九影院在线观看| 久久亚洲综合| 国产精品99久久不卡二区| 久久精品国产99| 国产精品久久久久aaaa九色| 1024成人网色www| 亚洲免费一在线| 欧美国产乱视频| 欧美在线一区二区| 欧美日精品一区视频| 黑人巨大精品欧美一区二区| 亚洲校园激情| 欧美激情中文字幕在线| 午夜国产一区| 欧美午夜在线观看| 亚洲理论电影网| 久久资源av| 亚洲欧美国产视频| 欧美日本一区| 亚洲人成网在线播放| 久久亚洲春色中文字幕|