Moving from a TCP only model to a hybrid TCP/UDP system. This is required to achieve a responsive, real-time multiplayer experience.
32 lines
825 B
C++
32 lines
825 B
C++
#pragma once
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include "bettola/network/tcpsocket.h"
|
|
|
|
class Player {
|
|
public:
|
|
Player(BettolaLib::Network::TCPSocket* socket);
|
|
|
|
void set_position(float x, float y) { _x = x; _y = y; }
|
|
void set_udp_addr(const sockaddr_in& addr) { _udp_addr = addr; _has_udp_addr = true; }
|
|
|
|
unsigned int get_id(void) const { return _id; }
|
|
float get_x(void) const { return _x; }
|
|
float get_y(void) const { return _y; }
|
|
|
|
BettolaLib::Network::TCPSocket& get_socket(void) const { return *_socket; }
|
|
const sockaddr_in& get_udp_addr(void) const { return _udp_addr; }
|
|
bool has_udp_addr(void) const { return _has_udp_addr; }
|
|
|
|
private:
|
|
static unsigned int _next_player_id;
|
|
|
|
unsigned int _id;
|
|
float _x;
|
|
float _y;
|
|
BettolaLib::Network::TCPSocket* _socket;
|
|
sockaddr_in _udp_addr;
|
|
bool _has_udp_addr;
|
|
};
|