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 Member Functions | Protected Attributes | List of all members
GridMate::Carrier Class Referenceabstract

#include <Carrier.h>

Classes

struct  FlowInformation
 
struct  ReceiveResult
 

Public Types

enum  DataPriority {
  PRIORITY_SYSTEM, PRIORITY_HIGH, PRIORITY_NORMAL, PRIORITY_LOW,
  PRIORITY_MAX
}
 
enum  DataReliability { SEND_UNRELIABLE, SEND_RELIABLE, SEND_RELIABILITY_MAX }
 
enum  ConnectionStates { CST_CONNECTING, CST_CONNECTED, CST_DISCONNECTING, CST_DISCONNECTED }
 
typedef TrafficControl::Statistics Statistics
 

Public Member Functions

virtual void Shutdown ()=0
 
virtual ConnectionID Connect (const char *hostAddress, unsigned int port)=0
 Connect with host and port. This is ASync operation, the connection is active after OnConnectionEstablished is called.
 
virtual ConnectionID Connect (const AZStd::string &address)=0
 Connect with internal address format. This is ASync operation, the connection is active after OnConnectionEstablished is called.
 
virtual void Disconnect (ConnectionID id)=0
 Request a disconnect procedure. This is ASync operation, the connection is closed after OnDisconnect is called.
 
virtual unsigned int GetPort () const =0
 
virtual unsigned int GetMessageMTU ()=0
 Returns the maximum message size that will fit in one datagram.
 
virtual AZStd::string ConnectionToAddress (ConnectionID id)=0
 Returns maximum message size (with splitting or without). Splitting will make your message reliable, which might not be optimal for Unreliable messages. It's better to send two unreliable.
 
virtual void SendWithCallback (const char *data, unsigned int dataSize, AZStd::unique_ptr< CarrierACKCallback > ackCallback, ConnectionID target=AllConnections, DataReliability reliability=SEND_RELIABLE, DataPriority priority=PRIORITY_NORMAL, unsigned char channel=0)=0
 
virtual void Send (const char *data, unsigned int dataSize, ConnectionID target=AllConnections, DataReliability reliability=SEND_RELIABLE, DataPriority priority=PRIORITY_NORMAL, unsigned char channel=0)=0
 
virtual ReceiveResult Receive (char *data, unsigned int maxDataSize, ConnectionID from, unsigned char channel=0)=0
 
unsigned int QueryNextReceiveMessageMaxSize (ConnectionID from, unsigned char channel=0)
 
virtual void Update ()=0
 
virtual unsigned int GetNumConnections () const =0
 
virtual ConnectionStates QueryStatistics (ConnectionID id, TrafficControl::Statistics *lastSecond=nullptr, TrafficControl::Statistics *lifetime=nullptr, TrafficControl::Statistics *effectiveLastSecond=nullptr, TrafficControl::Statistics *effectiveLifetime=nullptr, FlowInformation *flowInformation=nullptr)=0
 
virtual void DebugStatusReport (ConnectionID id, unsigned char channel=0)
 
virtual void DebugDeleteConnection (ConnectionID id)
 
virtual void DebugEnableDisconnectDetection (bool isEnabled)
 
virtual bool DebugIsEnableDisconnectDetection () const
 
virtual ConnectionID DebugGetConnectionId (unsigned int index) const =0
 
virtual void StartClockSync (unsigned int syncInterval=1000, bool isReset=false)=0
 
virtual void StopClockSync ()=0
 
virtual AZ::u32 GetTime ()=0
 
unsigned int GetMaxSendRate () const
 Returns the max frequency we will grab messages from the queues and send in milliseconds.
 
AZ_FORCE_INLINE IGridMateGetGridMate () const
 Return the owning instance of the gridmate.
 

Protected Member Functions

 Carrier (IGridMate *gridMate)
 
 Carrier (const Carrier &rhs)
 
Carrieroperator= (const Carrier &rhs)
 

Protected Attributes

IGridMatem_gridMate
 Pointer to the owning gridmate instance.
 
unsigned int m_maxSendRateMS
 Maximum send rate in milliseconds.
 
unsigned int m_connectionRetryIntervalBase
 
unsigned int m_connectionRetryIntervalMax
 
unsigned int m_batchPacketCount
 Number of packets queued to force send (rather than wait for m_maxSendRateMS expiration)
 

Detailed Description

Carrier Interface.

Member Enumeration Documentation

◆ DataPriority

Data delivery priorities.

Enumerator
PRIORITY_SYSTEM 

System priority messages have the highest priority. (reserved for INTERNAL USE)

PRIORITY_HIGH 

High priority messages are send before normal priority messages.

PRIORITY_NORMAL 

Normal priority messages are send before low priority messages.

PRIORITY_LOW 

Low priority messages are only sent when no other messages are waiting.

◆ DataReliability

Data delivery reliability.

Enumerator
SEND_UNRELIABLE 

Send data unreliable ordered, out of order packets will be dropped.

SEND_RELIABLE 

Send data reliable ordered.

Member Function Documentation

◆ DebugStatusReport()

virtual void GridMate::Carrier::DebugStatusReport ( ConnectionID  id,
unsigned char  channel = 0 
)
inlinevirtual

Debug function, prints the connection status report to the stdout.

◆ GetTime()

virtual AZ::u32 GridMate::Carrier::GetTime ( )
pure virtual

Returns current carrier time in milliseconds. If nobody syncs the clock the time will be relative to the carrier creation.

◆ QueryNextReceiveMessageMaxSize()

unsigned int GridMate::Carrier::QueryNextReceiveMessageMaxSize ( ConnectionID  from,
unsigned char  channel = 0 
)
inline

Query the next received message (which can the retreived with receive) maximum size.

Note
This is NOT always the actually message size, but a big enough buffer (rounded the nearest internal max datagram size) to hold that message.

◆ QueryStatistics()

virtual ConnectionStates GridMate::Carrier::QueryStatistics ( ConnectionID  id,
TrafficControl::Statistics lastSecond = nullptr,
TrafficControl::Statistics lifetime = nullptr,
TrafficControl::Statistics effectiveLastSecond = nullptr,
TrafficControl::Statistics effectiveLifetime = nullptr,
FlowInformation flowInformation = nullptr 
)
pure virtual

Stores connection statistics, it's ok to pass NULL for any of the statistics

Parameters
idConnection ID
lastSecondlast second statistics for all data
lifetimelifetime statistics for all data
effectiveLastSecondlast second statistics for effective data (actual data - carrier overhead excluded)
effectiveLifetimelifetime statistics for effective data (actual data - carrier overhead excluded)
Returns
connection state

◆ Receive()

virtual ReceiveResult GridMate::Carrier::Receive ( char *  data,
unsigned int  maxDataSize,
ConnectionID  from,
unsigned char  channel = 0 
)
pure virtual

Receive the data for the specific connection.

Note
Internal buffers are used make sure you periodically receive data for all connections, otherwise you might cause buffer overflow error.

◆ Send()

virtual void GridMate::Carrier::Send ( const char *  data,
unsigned int  dataSize,
ConnectionID  target = AllConnections,
DataReliability  reliability = SEND_RELIABLE,
DataPriority  priority = PRIORITY_NORMAL,
unsigned char  channel = 0 
)
pure virtual

Sends a buffer to the target with the parameterized reliability, priority and channel.

Note: Unreliable sends with buffers larger than the MTU will get upgraded to reliable.

◆ SendWithCallback()

virtual void GridMate::Carrier::SendWithCallback ( const char *  data,
unsigned int  dataSize,
AZStd::unique_ptr< CarrierACKCallback ackCallback,
ConnectionID  target = AllConnections,
DataReliability  reliability = SEND_RELIABLE,
DataPriority  priority = PRIORITY_NORMAL,
unsigned char  channel = 0 
)
pure virtual

Sends buffer with an ACK callback. When the transport layer recieves an ACK it will run the callback. The carrier runs in the main game thread, so if the callback executes a function in another thread it is the responsibility of the callback creator to add thread safety.

This adds reasonable overhead to the carrier data handling, and so should only be used when a callback is essential to operations.

Note: ACK callback is not supported with broadcast targets and will assert.

◆ StartClockSync()

virtual void GridMate::Carrier::StartClockSync ( unsigned int  syncInterval = 1000,
bool  isReset = false 
)
pure virtual

Enables sync of the clock every syncInterval milliseconds. Only one peer in the connected grid can have the clock sync enabled, all the others will sync to it, if you enable it on two or more an assert will occur.

Note
syncInterval is just so the clocks stay is sync, GetTime will adjust the time using the last received sync value (or the creation of the carrier). keep the synIterval high >= 1 sec. Systems will use their internal timer to adjust anyway, this will minimize the bandwidth usage. We adjust the time with the RTT so the accuracy will depend on the RTT and it's fluctuations. On average you can expect accuracy <250 ms (implantation dependent) in practice we can reduce this to <100 but this will require a lot more complex clock scheme.

◆ Update()

virtual void GridMate::Carrier::Update ( )
pure virtual

Update must be called once per frame. In processes system messages and callback data from the carrier thread.


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