With all of the things happening on the client side, be it rendering sprites or playing sounds or processing user input, it only makes sense to have all of the networking code localized inside a single class. This will allow us to communicate with the server quickly and easily. Let's begin designing that class, by first taking a look at some necessary definitions inside the
#define CONNECT_TIMEOUT 5000 // Milliseconds. class Client; using PacketHandler = std::function< void(const PacketID&, sf::Packet&, Client*)>;
The first definition is the amount of milliseconds that it takes for a client to realize that it's no longer connected to a server. This value can obviously be tweaked at any time. Following ...