![]() |
CUGL 3.0
Cornell University Game Library
|
#include <CUGameStateEvent.h>
Public Types | |
enum class | EventType : int { UID_ASSIGN = 100 , CLIENT_RDY = 101 , GAME_START = 102 , GAME_RESET = 103 , GAME_PAUSE = 104 , GAME_RESUME = 105 } |
Public Member Functions | |
GameStateEvent () | |
GameStateEvent (EventType t) | |
std::shared_ptr< NetEvent > | newEvent () override |
EventType | getType () const |
void | setType (EventType t) |
Uint8 | getShortUID () const |
std::vector< std::byte > | serialize () override |
void | deserialize (const std::vector< std::byte > &data) override |
![]() | |
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 |
Static Public Member Functions | |
static std::shared_ptr< GameStateEvent > | alloc () |
static std::shared_ptr< NetEvent > | allocGameStart () |
static std::shared_ptr< NetEvent > | allocReady () |
static std::shared_ptr< NetEvent > | allocUIDAssign (Uint32 sid) |
Protected Attributes | |
EventType | _type |
Uint32 | _shortUID |
This class represents a game state change during a session.
This class allows the user to extend the networked physics library to notify changes in game state, such as starting the game, reseting it, or pausing it.
|
strong |
|
inline |
Constructs an event with default values.
|
inline |
Constructs an event with the given type.
t | The type of the event |
|
inlinestatic |
Returns a newly allocated event of this type.
This is a static version of newEvent
.
|
inlinestatic |
Returns a newly allocated event for broadcasting the game start
|
inlinestatic |
Returns a newly allocated event for marking the client as ready
|
inlinestatic |
Returns a newly allocated event for assigning ids for clients
This event is sent from the host to one client only. It is not meant to be broadcasted.
sid | The short id to assign |
|
overridevirtual |
Deserializes this event from a byte vector.
This method will set the type of the event and all relevant fields.
Reimplemented from cugl::physics2::distrib::NetEvent.
|
inline |
Returns the shortUID of the event
If the event is not EventType#UID_ASSIGN
, this method returns 0. Valid shortUIDs are guaranteed to be greater than 0.
|
inline |
Returns the event type
|
inlineoverridevirtual |
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 from cugl::physics2::distrib::NetEvent.
|
overridevirtual |
Returns a byte vector serializing this event
Reimplemented from cugl::physics2::distrib::NetEvent.
|
inline |
Sets the event type
t | The type of the event |
|
protected |
The shortUID of the associated physics world
|
protected |
An internal type of the game state message