Initial implementation of server-side reconciliation for player movement. Clients respect the server as the authoritative source for game state. In 'process_game_state', the client compares its locally predicted pos with the state received from the server and snaps to the server's position if they diverge. Had to add a defensive check to the server-side Player constructor to fix a bug where the first connecting client was incorrectly assigned an ID of 0. This prevented it from sending or recieving any game data.
21 lines
444 B
C++
21 lines
444 B
C++
#include <string.h>
|
|
|
|
#include "player.h"
|
|
#include "network/tcpsocket.h"
|
|
|
|
unsigned int Player::_next_player_id = 0;
|
|
|
|
Player::Player(BettolaLib::Network::TCPSocket* socket) :
|
|
_socket(socket),
|
|
_has_udp_addr(false) {
|
|
|
|
/* Try and set a player id to 0 now you audacious pr.ck! */
|
|
if(_next_player_id == 0) {
|
|
_next_player_id = 1;
|
|
}
|
|
_id = _next_player_id++;
|
|
_x = 0.0f; _y = 0.0f;
|
|
memset(&_udp_addr, 0, sizeof(_udp_addr));
|
|
}
|
|
|