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 ...

Get SFML Game Development By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.