![]() |
CUGL 3.0
Cornell University Game Library
|
#include <CUNetEvent.h>
Public Member Functions | |
virtual std::shared_ptr< NetEvent > | newEvent () |
virtual std::vector< std::byte > | serialize () |
virtual void | deserialize (const std::vector< std::byte > &data) |
Uint64 | getEventTimeStamp () const |
Uint64 | getReceiveTimeStamp () const |
const std::string | getSourceId () const |
Friends | |
class | NetEventController |
A template class for all communication messages between machines.
Any information that needs to be sent through the network during gameplay should be wrapped in a NetEvent object. Custom events types can be made by subclassing this class and adding parameters as necessary.
It is your responsibility to serialize and deserialize your custom classes. However, you should only serialize/deserialize the new attributes that you provide, and not the ones inherited from this class.
|
inlinevirtual |
Deserializes a vector of bytes and set the corresponding parameters.
This function should be the "reverse" of the serialize
function. It should be able to recreate a serialized event entirely, setting all the useful parameters of this class.
data | a serialized byte vector |
Reimplemented in cugl::physics2::distrib::GameStateEvent, cugl::physics2::distrib::PhysObstEvent, and cugl::physics2::distrib::PhysSyncEvent.
|
inline |
Returns the timestamp of the event set by the sender.
This attribute is valid only if the event was received by this client.
|
inline |
Returns the timestamp when the event was received by this client.
This attribute is valid only if the event was received by this client.
|
inline |
Returns the ID of the sender.
This attribute is valid only if the event was received by this client.
|
inlinevirtual |
Returns a newly allocated event of this type.
This method is used by the NetEventController to create a new event with this type as a reference.
Note that this method is not static, unlike the alloc method present in most of CUGL. That is because we need this factory method to be polymorphic. All custom subclasses must implement this method.
Reimplemented in cugl::physics2::distrib::GameStateEvent, cugl::physics2::distrib::PhysObstEvent, and cugl::physics2::distrib::PhysSyncEvent.
|
inlinevirtual |
Returns a byte vector serializing this event.
Reimplemented in cugl::physics2::distrib::GameStateEvent, cugl::physics2::distrib::PhysObstEvent, and cugl::physics2::distrib::PhysSyncEvent.