CUGL 3.0
Cornell University Game Library
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
cugl::physics2::distrib::GameStateEvent Class Reference

#include <CUGameStateEvent.h>

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

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< NetEventnewEvent () 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
 
- Public Member Functions inherited from cugl::physics2::distrib::NetEvent
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
 

Static Public Member Functions

static std::shared_ptr< GameStateEventalloc ()
 
static std::shared_ptr< NetEventallocGameStart ()
 
static std::shared_ptr< NetEventallocReady ()
 
static std::shared_ptr< NetEventallocUIDAssign (Uint32 sid)
 

Protected Attributes

EventType _type
 
Uint32 _shortUID
 

Detailed Description

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.

Member Enumeration Documentation

◆ EventType

Enum for the type of the event.

Enumerator
UID_ASSIGN 

Assigning a short id to a simulation

CLIENT_RDY 

Notifying that the client is read

GAME_START 

Starting the game

GAME_RESET 

Reseting the game

GAME_PAUSE 

Pausing the game

GAME_RESUME 

Resuming the game

Constructor & Destructor Documentation

◆ GameStateEvent() [1/2]

cugl::physics2::distrib::GameStateEvent::GameStateEvent ( )
inline

Constructs an event with default values.

◆ GameStateEvent() [2/2]

cugl::physics2::distrib::GameStateEvent::GameStateEvent ( EventType  t)
inline

Constructs an event with the given type.

Parameters
tThe type of the event

Member Function Documentation

◆ alloc()

static std::shared_ptr< GameStateEvent > cugl::physics2::distrib::GameStateEvent::alloc ( )
inlinestatic

Returns a newly allocated event of this type.

This is a static version of newEvent.

Returns
a newly allocated event of this type.

◆ allocGameStart()

static std::shared_ptr< NetEvent > cugl::physics2::distrib::GameStateEvent::allocGameStart ( )
inlinestatic

Returns a newly allocated event for broadcasting the game start

Returns
a newly allocated event for broadcasting the game start

◆ allocReady()

static std::shared_ptr< NetEvent > cugl::physics2::distrib::GameStateEvent::allocReady ( )
inlinestatic

Returns a newly allocated event for marking the client as ready

Returns
a newly allocated event for marking the client as ready

◆ allocUIDAssign()

static std::shared_ptr< NetEvent > cugl::physics2::distrib::GameStateEvent::allocUIDAssign ( Uint32  sid)
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.

Parameters
sidThe short id to assign

◆ deserialize()

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

◆ getShortUID()

Uint8 cugl::physics2::distrib::GameStateEvent::getShortUID ( ) const
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.

Returns
the shortUID of the event

◆ getType()

EventType cugl::physics2::distrib::GameStateEvent::getType ( ) const
inline

Returns the event type

Returns
the event type

◆ newEvent()

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

Returns
a newly allocated event of this type.

Reimplemented from cugl::physics2::distrib::NetEvent.

◆ serialize()

std::vector< std::byte > cugl::physics2::distrib::GameStateEvent::serialize ( )
overridevirtual

Returns a byte vector serializing this event

Returns
a byte vector serializing this event

Reimplemented from cugl::physics2::distrib::NetEvent.

◆ setType()

void cugl::physics2::distrib::GameStateEvent::setType ( EventType  t)
inline

Sets the event type

Parameters
tThe type of the event

Member Data Documentation

◆ _shortUID

Uint32 cugl::physics2::distrib::GameStateEvent::_shortUID
protected

The shortUID of the associated physics world

◆ _type

EventType cugl::physics2::distrib::GameStateEvent::_type
protected

An internal type of the game state message


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