Shared code
Since there are many instances where code we write is going to exist on both the client and the server side, let's discuss that first, starting with the way data exchange between both sides is made.
The most important part of our information exchange is updating entities on any and all connected clients. We do this by sending specialized structures back and forth, which contains relevant entity information. From now on, these structures are going to be referred to as snapshots. Let's see how they can be implemented, by taking a look at the EntitySnapshot.h
file:
struct EntitySnapshot{ std::string m_type; sf::Vector2f m_position; sf::Int32 m_elevation; sf::Vector2f m_velocity; sf::Vector2f m_acceleration; sf::Uint8 m_direction; sf::Uint8 m_state; sf::Uint8 m_health; std::string m_name; };
The information we're going to be updating constantly for any given entity consists of its position and elevation, velocity, acceleration, the...