-
Notifications
You must be signed in to change notification settings - Fork 1
Networking
Networking is accomplished using the Events architecture.
When a NetworkEvent is injected into the event system, the NetworkManager receives it, serializes and sends it, and then cancels the event execution. Thus, as the NetworkManager has the highest priority (EventListener::Priority::INTERNAL_HIGHEST
), network events will not be injected into other EventListeners.
NetworkEvents are serialized using the IOPacket
helper class. All members have to be serialized in the same order into and out of the packet, for which the operator&
has been implemented. Enums are serialized using the EnumHelper
class.
The NetworkManager sends the packet using SFML and a sf::UdpSocket
. The receiving NetworkManager will read the EventType ID from the packet, create a clone of a Prototype Event with that ID (FactoryPattern) and let this Event deserialize itself from the packet. To make sure the IDs are the same in both server and client, the event types have to be inserted into the StringManager in the exact same order everywhere. This is done by registering them as prototypes in the same order in both applications.