![]() |
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.
|
#include <ReplicaChunk.h>
Inherited by GridMate::ReplicaChunk, and GridMate::ReplicaStatus.
Public Types | |
using | RPCQueue = AZStd::ring_buffer< Internal::RpcRequest *, SysContAlloc > |
Public Member Functions | |
void | Init (ReplicaChunkClassId chunkTypeId) |
Initializes the chunk. Must be called before the chunk can be used. | |
void | Init (ReplicaChunkDescriptor *descriptor) |
bool | IsClassType (ReplicaChunkClassId classId) const |
ReplicaChunkDescriptor * | GetDescriptor () const |
ReplicaId | GetReplicaId () const |
PeerId | GetPeerId () const |
virtual ReplicaManager * | GetReplicaManager () |
bool | IsActive () const |
bool | IsPrimary () const |
bool | IsProxy () const |
virtual void | OnAttachedToReplica (Replica *replica) |
virtual void | OnDetachedFromReplica (Replica *replica) |
virtual bool | IsReplicaMigratable ()=0 |
virtual void | UpdateChunk (const ReplicaContext &rc) |
virtual void | UpdateFromChunk (const ReplicaContext &rc) |
virtual bool | AcceptChangeOwnership (PeerId requestor, const ReplicaContext &rc) |
virtual void | OnReplicaActivate (const ReplicaContext &rc) |
virtual void | OnReplicaDeactivate (const ReplicaContext &rc) |
virtual void | OnReplicaChangeOwnership (const ReplicaContext &rc) |
virtual bool | IsUpdateFromReplicaEnabled () |
Replica * | GetReplica () |
void | SetHandler (ReplicaChunkInterface *handler) |
ReplicaChunkInterface * | GetHandler () |
ReplicaPriority | GetPriority () const |
void | SetPriority (ReplicaPriority priority) |
virtual bool | ShouldSendToPeer (ReplicaPeer *peer) const |
template<typename T > | |
bool | IsType () |
virtual bool | IsBroadcast () |
AZ::u64 | GetLastChangeStamp () const |
virtual bool | ShouldBindToNetwork () |
Public Attributes | |
friend | Replica |
friend | RpcBase |
friend | DataSetBase |
Static Public Attributes | |
static constexpr AZStd::size_t | MaxRpcQueueSize = 512 |
Specify the maximum size of a RPC queues for each replica chunk. This queue can grow while RPCs are being delivered back to all clients. | |
Protected Types | |
enum | Flags { RepChunk_Updated = 1 << 0 } |
Protected Member Functions | |
virtual AZ::u32 | CalculateDirtyDataSetMask (MarshalContext &mc) |
virtual void | OnDataSetChanged (const DataSetBase &dataSet) |
virtual void | Marshal (MarshalContext &mc, AZ::u32 chunkIndex) |
virtual void | Unmarshal (UnmarshalContext &mc, AZ::u32 chunkIndex) |
AZ_FORCE_INLINE void | add_ref () |
void | release () |
void | AttachedToReplica (Replica *replica) |
void | DetachedFromReplica () |
bool | IsDirty (AZ::u32 marshalFlags) const |
PrepareDataResult | PrepareData (EndianType endianType, AZ::u32 marshalFlags) |
void | MarshalDataSets (MarshalContext &mc, AZ::u32 chunkIndex) |
void | MarshalRpcs (MarshalContext &mc, AZ::u32 chunkIndex) |
void | UnmarshalDataSets (UnmarshalContext &mc, AZ::u32 chunkIndex) |
void | UnmarshalRpcs (UnmarshalContext &mc, AZ::u32 chunkIndex) |
void | AddDataSetEvent (DataSetBase *dataset) |
void | SignalDataSetChanged (const DataSetBase &dataset) |
void | EnqueueMarshalTask () |
void | QueueRPCRequest (GridMate::Internal::RpcRequest *rpc) |
bool | ProcessRPCs (const ReplicaContext &rc) |
void | MarkRPCsAsRelayed () |
void | ClearPendingRPCs () |
Protected Attributes | |
unsigned int | m_refCount |
Replica * | m_replica |
ReplicaChunkDescriptor * | m_descriptor |
AZ::u32 | m_flags |
RPCQueue | m_rpcQueue {MaxRpcQueueSize} |
ReplicaChunkInterface * | m_handler |
AZStd::bitset< GM_MAX_DATASETS_IN_CHUNK > | m_reliableDirtyBits |
AZStd::bitset< GM_MAX_DATASETS_IN_CHUNK > | m_unreliableDirtyBits |
AZStd::bitset< GM_MAX_DATASETS_IN_CHUNK > | m_nonDefaultValueBits |
AZ::u32 | m_nDownstreamReliableRPCs |
AZ::u32 | m_nDownstreamUnreliableRPCs |
AZ::u32 | m_nUpstreamReliableRPCs |
AZ::u32 | m_nUpstreamUnreliableRPCs |
AZ::u32 | m_dirtiedDataSets |
ReplicaPriority | m_priority |
AZ::u64 | m_revision |
Friends | |
template<typename DataType , typename Marshaler , typename Throttle > | |
class | DataSet |
template<class T > | |
struct | AZStd::IntrusivePtrCountPolicy |
A single unit of network functionality A ReplicaChunk is a user extendable network object. One or more ReplicaChunks can be owned by a Replica, which is both a container and manager for them. A replica is owned by a Primary, and is propagated to other network nodes, who interact with is as a Proxy. The data a ReplicaChunk contains should generally be related to the other data stored within it. Since multiple chunks can be attached to a Replica, unrelated data can simply be stored in other chunks on the same Replica.
A ReplicaChunk has two primary ways to interact with it: DataSets and Remote Procedure Calls (RPCs). DataSets store arbitrary data, which only the Primary is able to modify. Any changes are propagated to the Proxy ReplicaChunks on the other nodes. RPCs are methods that can be executed on a remote node. They are first invoked on the Primary, who then decides if the invocation should be propagated to the Proxies.
ReplicaChunks can be created by inheriting from the class and registered by calling ReplicaChunkDescriptorTable::RegisterChunkType() to create the factory required by the network. Every concrete replica chunk type needs to implement a static member function const char* GetChunkName(). The string returned by this function will be used to generate a ReplicaChunkClassId which will be used to identify this chunk type throughout the system.
Replica chunks can be instantiated directly in a Replica, or standalone and attached to a Replica afterwards. Once attached to a replica they are bound to the network.
To add a handler interface for RPC calls and DataSet changed events, call SetHandler with an object that inherits from ReplicaChunkInterface.
Use ReplicaChunkBase as the parent class when the event handler logic is separate from the chunk itself. This is useful for example when a client and server want to connect different logic to the chunk.