Open 3D Engine GridMate API Reference  2205.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends | List of all members
GridMate::GridSession Class Referenceabstract

#include <Session.h>

Inherits Handler, and Handler.

Classes

struct  EventCommand
 
struct  NotFullyConnectedMember
 

Public Types

enum  CarrierChannels { CC_REPLICA_DATA, CC_VOICE_DATA, CC_USER_DATA }
 
enum  Result { GS_OK = 0, GS_ERROR }
 

Public Member Functions

virtual void Update ()
 
virtual bool SendInviteDlg ()
 Displays send invite dialog and binds current session data to it.
 
const SessionID & GetId () const
 
unsigned int GetNumberOfMembers () const
 
GridMemberGetMemberByIndex (unsigned int index) const
 
GridMemberGetMemberById (const MemberID &id) const
 
GridMemberGetMemberById (const MemberIDCompact &id) const
 
GridMemberGetHost () const
 
GridMemberGetMyMember () const
 
Result KickMember (GridMember *member, AZ::u8 reason=0)
 
Result BanMember (GridMember *member, AZ::u8 reason=0)
 
virtual Result LockSession ()
 
virtual Result UnlockSession ()
 
void Leave (bool isMigrateHost)
 
bool IsHost () const
 
bool IsReady () const
 
bool IsMigratingHost () const
 Return true if we are in host migration state, false otherwise.
 
unsigned int GetTime () const
 returns time in milliseconds since the session started.
 
SessionTopology GetTopology () const
 
unsigned char GetNumUsedPublicSlots () const
 
unsigned char GetNumUsedPrivateSlots () const
 
unsigned char GetNumFreePublicSlots () const
 
unsigned char GetNumFreePrivateSlots () const
 
unsigned char GetFlags () const
 
unsigned int GetPeerToPeerTimeout () const
 Returns timeout in milliseconds for the host to tolerate 2 peers with different number of connections. The peer with less connections will be kicked out after that timeout expires.
 
unsigned int GetHostMigrationTimeout () const
 Return host migration max time in milliseconds. If timeout expires the used will leave the current session.
 
unsigned int GetHostMigrationVotingTime () const
 Return host migration min voting time. Value between 0 and GetHostMigrationTimeout() / 2 for voting time, before we go to elect the winner.
 
unsigned int GetNumParams () const
 
const GridSessionParamGetParam (unsigned int index) const
 
bool SetParam (const GridSessionParam &param)
 
bool RemoveParam (const AZStd::string &paramId)
 
bool RemoveParam (unsigned int index)
 
ReplicaManagerGetReplicaMgr ()
 Returns the instance of the replica manager. Replica manager may not be initialized if the session is NOT in ready (created) state.
 
CarrierGetCarrier ()
 Returns the pointer to the transport layer. The pointer can be NULL if the session is NOT in ready (created) state.
 
const CarrierDescGetCarrierDesc () const
 Returns pointer to the descriptor which was used to create the transport layer (carrier)
 
IGridMateGetGridMate ()
 Return owner gridmate.
 
void DebugEnableDisconnectDetection (bool isEnable)
 Debug: Change the disconnect detection state of all members in the session.
 
bool DebugIsEnableDisconnectDetection () const
 

Protected Types

enum  BaseStates {
  SS_TOP, SS_NO_SESSION, SS_START_UP, SS_CREATE,
  SS_IN_SESSION, SS_JOIN, SS_IDLE, SS_START_GAME,
  SS_IN_GAME, SS_END_GAME, SS_DELETE, SS_HOST_MIGRATE_ELECTION,
  SS_HOST_MIGRATE_SESSION, SS_LAST
}
 
enum  BaseStateEvents {
  SE_UPDATE, SE_HOST, SE_JOIN, SE_JOIN_INVITE,
  SE_JOINED, SE_CREATED, SE_START_GAME, SE_LEAVE_GAME,
  SE_END_GAME, SE_DELETE, SE_DELETED, SE_CONNECTION_LOST,
  SE_HM_SESSION_MIGRATED, SE_HM_MIGRATE_CLIENT, SE_HM_CLIENT_SESSION_MIGRATED, SE_HM_REPLICAS_MIGRATED,
  SE_LAST
}
 
typedef unordered_set< ConnectionIDConnectionIDSet
 
typedef vector< GridMember * > MemberArrayType
 
typedef vector< NotFullyConnectedMemberNotConnectedArrayType
 

Protected Member Functions

 GridSession (SessionService *service)
 
bool Initialize (const CarrierDesc &carrierDesc)
 Base initialization, must be called before all other operations on session.
 
virtual void Shutdown ()
 Called by the system to shutdown all session resources, before it's get deleted.
 
void SetHandshakeUserData (const void *data, size_t size)
 
void OnIncomingConnection (Carrier *carrier, ConnectionID id) override
 
void OnFailedToConnect (Carrier *carrier, ConnectionID id, CarrierDisconnectReason reason) override
 
void OnConnectionEstablished (Carrier *carrier, ConnectionID id) override
 
void OnDisconnect (Carrier *carrier, ConnectionID id, CarrierDisconnectReason reason) override
 
void OnDriverError (Carrier *carrier, ConnectionID id, const DriverError &error) override
 
void OnSecurityError (Carrier *carrier, ConnectionID id, const SecurityError &error) override
 
void OnNewHost (bool isHost, ReplicaManager *manager) override
 
int ReserveSlot (bool isInvited)
 Return slot type 1 for public slot, 2 private slot and 0 for no slot.
 
void FreeSlot (int slotType)
 Frees a slot based on a slot type.
 
virtual GridMemberCreateRemoteMember (const AZStd::string &address, ReadBuffer &data, RemotePeerMode peerMode, ConnectionID connId=InvalidConnectionID)=0
 Creates remote player, when he wants to join.
 
virtual bool IsAddressInMemberList (const AZStd::string &address)
 Returns true if this address belongs to a member in the list, otherwise false.
 
virtual bool IsConnectionIdInMemberList (const ConnectionID &connId)
 
virtual bool AddMember (GridMember *member)
 Adds a created member to the session. Return false if no free slow was found!
 
virtual bool RemoveMember (const MemberID &id)
 Remove and delete current member from the session.
 
virtual void ElectNewHost ()
 Called by the state machine to elect a new host.
 
void CastNewHostVote (GridMember *newHost)
 Called by default from ElectNewHost to cast the new host vote.
 
virtual void OnSessionParamChanged (const GridSessionParam &param)=0
 Called when a session parameter is added/changed.
 
virtual void OnSessionParamRemoved (const AZStd::string &paramId)=0
 Called when a session parameter is deleted.
 
virtual void SetUpStateMachine ()
 
virtual bool OnStateNoSession (AZ::HSM &sm, const AZ::HSM::Event &e)
 
virtual bool OnStateStartup (AZ::HSM &sm, const AZ::HSM::Event &e)
 
virtual bool OnStateCreate (AZ::HSM &sm, const AZ::HSM::Event &e)
 
virtual bool OnStateInSession (AZ::HSM &sm, const AZ::HSM::Event &e)
 
virtual bool OnStateJoin (AZ::HSM &sm, const AZ::HSM::Event &e)
 
virtual bool OnStateIdle (AZ::HSM &sm, const AZ::HSM::Event &e)
 
virtual bool OnStateStart (AZ::HSM &sm, const AZ::HSM::Event &e)
 
virtual bool OnStateInGame (AZ::HSM &sm, const AZ::HSM::Event &e)
 
virtual bool OnStateEnd (AZ::HSM &sm, const AZ::HSM::Event &e)
 
virtual bool OnStateDelete (AZ::HSM &sm, const AZ::HSM::Event &e)
 
virtual bool OnStateHostMigrateElection (AZ::HSM &sm, const AZ::HSM::Event &e)
 
virtual bool OnStateHostMigrateSession (AZ::HSM &sm, const AZ::HSM::Event &e)
 
virtual void RequestEvent (int id, const void *userData, unsigned int userDataSize, bool isProcessRequired, EventCommand::DataCloner cloner=nullptr, EventCommand::DataDeleter deleter=nullptr)
 
virtual void ProcessEvents ()
 If you queue events, you can override this function to process them when appropriate.
 
template<class T >
void RequestEventData (int id, const T &userData, bool isProcessRequired=false)
 T must be copy constructible.
 
void RequestEventParam (int id, size_t param, bool isProcessRequired=false)
 
void RequestEvent (int id, bool isProcessRequired=false)
 
void EventToQueue (const AZ::HSM::Event &event, unsigned int userDataSize, bool isProcessRequired, EventCommand::DataCloner cloner, EventCommand::DataDeleter deleter)
 
void ProcessEventOnQueue ()
 

Static Protected Member Functions

template<class T >
static void * UserDataCopier (const void *sourceData, unsigned int sourceDataSize)
 
template<class T >
static void UserDataDeleter (void *pointer, unsigned int dataSize)
 

Protected Attributes

SessionID m_sessionId
 Session id. Content of the string will vary based on session types and platforms.
 
CarrierDesc m_carrierDesc
 
Carrierm_carrier
 
ReplicaManagerm_replicaMgr
 
Internal::GridSessionHandshake * m_handshake
 
ConnectionIDSet m_connections
 
AZStd::string m_hostAddress
 
bool m_isShutdown
 
GridMemberm_myMember
 Created with the session and bound when the server replica arrives.
 
AZStd::intrusive_ptr< Internal::GridSessionReplica > m_state
 Pointer to HOST owned session state.
 
SessionServicem_service
 Pointer to session service.
 
IGridMatem_gridMate
 Pointer to the owner GridMate interface.
 
MemberArrayType m_members
 List of valid members.
 
unordered_set< Internal::GridMemberStateReplica * > m_unboundMemberStates
 
TimeStamp m_hostMigrationStart
 Time when the host migration started.
 
unsigned int m_hostMigrationTimeOut
 Host migration time out in milliseconds.
 
unsigned int m_hostMigrationVotingTime
 Minimum time that we will spend in SS_HOST_MIGRATE_ELECTION state (before we check for majority). It should be < than m_hostMigrationTimeOut/2.
 
bool m_hostMigrationInProcess
 True if we are in host migration, otherwise false. More...
 
bool m_hostMigrationSessionMigrated
 
bool m_hostMigrationReplicaMigrated
 
NotConnectedArrayType m_membersNotFullyConnected
 
TimeStamp m_lastConnectivityUpdate
 
queue< EventCommandm_eventQueue
 Queue with events for the state machine to process.
 
AZ::HSM m_sm
 Hierarchical state machine for the session management;.
 
AZStd::chrono::milliseconds m_disconnectKickedPlayersDelay
 number of milliseconds before forcing kicked player to disconnect
 
GridMate::vector< AZStd::pair< TimeStamp, MemberIDCompact > > m_futureKickedPlayers
 

Friends

class GridMember
 
class SessionService
 

Detailed Description

Session interface class.

Member Enumeration Documentation

◆ BaseStateEvents

Enumerator
SE_UPDATE 

Called every frame to update a state.

SE_HM_SESSION_MIGRATED 

Event executed on the host, when the session is migrated.

SE_HM_MIGRATE_CLIENT 

Event executed on the client, when he must join a migrated session.

SE_HM_CLIENT_SESSION_MIGRATED 

Event executes on the client, when the client joined the migrated session.

SE_HM_REPLICAS_MIGRATED 

Called when all replicas have been successfully migrated.

Member Function Documentation

◆ Leave()

void GridMate::GridSession::Leave ( bool  isMigrateHost)

Leaves the session. If the local system is the host, isMigrateHost will determine the host migration. If the local system is NOT the host, it will just leave the session.

Note
When you call this you need to make sure you session supports host migration. The code is allowed to assert if such operation is NOT supported. IMPORTANT: You can't use the session pointer after this call.

◆ RequestEvent()

virtual void GridMate::GridSession::RequestEvent ( int  id,
const void *  userData,
unsigned int  userDataSize,
bool  isProcessRequired,
EventCommand::DataCloner  cloner = nullptr,
EventCommand::DataDeleter  deleter = nullptr 
)
protectedvirtual

Request a state machine event. You might override and queue the events if you have async operations. if isProcessRequired is set to true, the event dispatch will verify that a state function returned true (processed the event) otherwise it will trigger an assert and dispatch(SE_DELETE) event.

Note
we can add optional completion callbacks if needed.
Important function function is to be used with POD data by default, provide DataCloner and DataDestructor for non POD.

◆ SetHandshakeUserData()

void GridMate::GridSession::SetHandshakeUserData ( const void *  data,
size_t  size 
)
protected

Sets the GridSessionHandshake user data, which will be delivered with each connection request and passed as a ReadBuffer into CreateRemoteMember.

Member Data Documentation

◆ m_hostMigrationInProcess

bool GridMate::GridSession::m_hostMigrationInProcess
protected

True if we are in host migration, otherwise false.

Note
We use a bool instead of m_sm.IsInState(SS_HOST_MIGRATE_ELECTION)||m_sm.IsInState(SS_HOST_MIGRATE_SESSION) because if the migration failles or timeout it will switch states. This will cause inconsistency with the user callbacks.

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