Fixed the network lag/swamped bug
This commit is contained in:
parent
b785304adf
commit
57fe48887d
@ -85,7 +85,8 @@ void Client::update(double elapsed_time)
|
|||||||
|
|
||||||
m_net_client->Receive();
|
m_net_client->Receive();
|
||||||
client_packet.clear();
|
client_packet.clear();
|
||||||
if(m_net_client->getData(client_packet))
|
// Handle all received data (only really want the latest)
|
||||||
|
while(m_net_client->getData(client_packet))
|
||||||
{
|
{
|
||||||
// Update player position as calculated from the server.
|
// Update player position as calculated from the server.
|
||||||
client_packet >> m_player->direction;
|
client_packet >> m_player->direction;
|
||||||
@ -103,6 +104,12 @@ void Client::update(double elapsed_time)
|
|||||||
sf::Uint8 s_pressed = KEY_NOT_PRESSED;
|
sf::Uint8 s_pressed = KEY_NOT_PRESSED;
|
||||||
sf::Uint8 d_pressed = KEY_NOT_PRESSED;
|
sf::Uint8 d_pressed = KEY_NOT_PRESSED;
|
||||||
sf::Int32 rel_mouse_movement = 0;
|
sf::Int32 rel_mouse_movement = 0;
|
||||||
|
|
||||||
|
// This is a fix so that the mouse will not move outside the window and
|
||||||
|
// cause the user to click on another program.
|
||||||
|
// Note: Does not work well with fast movement.
|
||||||
|
if(client_has_focus)
|
||||||
|
{
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
|
||||||
{
|
{
|
||||||
a_pressed = KEY_PRESSED;
|
a_pressed = KEY_PRESSED;
|
||||||
@ -120,12 +127,6 @@ void Client::update(double elapsed_time)
|
|||||||
s_pressed = KEY_PRESSED;
|
s_pressed = KEY_PRESSED;
|
||||||
}
|
}
|
||||||
rel_mouse_movement = sf::Mouse::getPosition(*m_window).x - m_width / 2;
|
rel_mouse_movement = sf::Mouse::getPosition(*m_window).x - m_width / 2;
|
||||||
|
|
||||||
// This is a fix so that the mouse will not move outside the window and
|
|
||||||
// cause the user to click on another program.
|
|
||||||
// Note: Does not work well with fast movement.
|
|
||||||
if(client_has_focus)
|
|
||||||
{
|
|
||||||
sf::Mouse::setPosition(sf::Vector2i(m_width / 2, m_height / 2), *m_window);
|
sf::Mouse::setPosition(sf::Vector2i(m_width / 2, m_height / 2), *m_window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,8 @@ void Server::update( double elapsed_time )
|
|||||||
static sf::Int32 rel_mouse_movement = 0;
|
static sf::Int32 rel_mouse_movement = 0;
|
||||||
|
|
||||||
m_net_server->Receive();
|
m_net_server->Receive();
|
||||||
if(m_net_server->getData(server_packet))
|
// Handle all received data (only really want the latest)
|
||||||
|
while(m_net_server->getData(server_packet))
|
||||||
{
|
{
|
||||||
server_packet >> w_pressed;
|
server_packet >> w_pressed;
|
||||||
server_packet >> a_pressed;
|
server_packet >> a_pressed;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user