CUGL 3.0
Cornell University Game Library
Loading...
Searching...
No Matches
Public Member Functions | Friends | List of all members
cugl::physics2::distrib::NetEvent Class Reference

#include <CUNetEvent.h>

Inheritance diagram for cugl::physics2::distrib::NetEvent:
cugl::physics2::distrib::GameStateEvent cugl::physics2::distrib::PhysObstEvent cugl::physics2::distrib::PhysSyncEvent

Public Member Functions

virtual std::shared_ptr< NetEventnewEvent ()
 
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
 

Detailed Description

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.

Member Function Documentation

◆ deserialize()

virtual void cugl::physics2::distrib::NetEvent::deserialize ( const std::vector< std::byte > &  data)
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.

Parameters
dataa serialized byte vector

Reimplemented in cugl::physics2::distrib::GameStateEvent, cugl::physics2::distrib::PhysObstEvent, and cugl::physics2::distrib::PhysSyncEvent.

◆ getEventTimeStamp()

Uint64 cugl::physics2::distrib::NetEvent::getEventTimeStamp ( ) const
inline

Returns the timestamp of the event set by the sender.

This attribute is valid only if the event was received by this client.

Returns
the timestamp of the event set by the sender.

◆ getReceiveTimeStamp()

Uint64 cugl::physics2::distrib::NetEvent::getReceiveTimeStamp ( ) const
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.

Returns
the timestamp when the event was received by this client.

◆ getSourceId()

const std::string cugl::physics2::distrib::NetEvent::getSourceId ( ) const
inline

Returns the ID of the sender.

This attribute is valid only if the event was received by this client.

Returns
the ID of the sender.

◆ newEvent()

virtual std::shared_ptr< NetEvent > cugl::physics2::distrib::NetEvent::newEvent ( )
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.

Returns
a newly allocated event of this type.

Reimplemented in cugl::physics2::distrib::GameStateEvent, cugl::physics2::distrib::PhysObstEvent, and cugl::physics2::distrib::PhysSyncEvent.

◆ serialize()

virtual std::vector< std::byte > cugl::physics2::distrib::NetEvent::serialize ( )
inlinevirtual

Returns a byte vector serializing this event.

Returns
a byte vector serializing this event.

Reimplemented in cugl::physics2::distrib::GameStateEvent, cugl::physics2::distrib::PhysObstEvent, and cugl::physics2::distrib::PhysSyncEvent.


The documentation for this class was generated from the following file: