Navigation
Unreal Engine C++ API Reference > Plugins > ConcertSyncClient
References
Module | ConcertSyncClient |
Header | /Engine/Plugins/Developer/Concert/ConcertSync/ConcertSyncClient/Source/ConcertSyncClient/Public/IConcertClientDataStore.h |
Include | #include "IConcertClientDataStore.h" |
Syntax
class IConcertClientDataStore
Remarks
Interacts with a key/value store shared by one or more clients connected to a Concert session. The store is like a TMap
The store is type safe, in the sense that a client cannot transmute the type of a stored value into another type. For example if the value "foo" is an integer, it cannot be transformed into a double later one.
The store is used to share variables with other clients. For example, it can be used for to manage a distributed counter like "cameraId" to uniquely number cameras created concurrently by multiple users while editing a level.
The store API returns TFuture to implement asynchronous or blocking operations. While is far more easier to use the blocking operations model, i.e. waiting on future to gets its result (TFuture::Get()) in the caller thread, it is recommended to use the asynchronous API and use continuations. Since the store implies network operation, expect latency and avoid waiting the response in a thread like the game thread.
To implement a sequence of operations using the store asynchronously inside a single thread (game thread), it is recommended to implement it as a finite state machine 'ticked' at each loop.
Example: Initialize a shared value. The code snippet below shows how multiple clients can concurrently create or sync a shared integer value to be ready to compare exchange it later to generate a new unique id.
voidMyClass::InitCameraIdAsync(){FNameKey(TEXT("CameraId"));//Thesharedvariablename.int64Value=0;//Theinitialvalueifnotexistingyet.//Trytofetchthespecifiedkeyvalue(abasictype),ifthekeydoesn'texist,additwiththespecifiedvalue.GetDataStore().FetchOrAdd(Key,Value).Next(this,Key,Value{//Ifthekeywasaddedorfetched.if(Result){CameraId=Result.GetValue();bCameraIdAcquired=true;}else{//Thekeyalreadyexisted,butthevaluewasnotaint64.check(Response.GetCode()==EConcertDataStoreResultCode::TypeMismatch);}});
Example: Use custom types. The code snippet below shows how a user can use a custom type with the data store. For simplicity, the example block until the result is available and assumes the all operations succeeded.
USTRUCT()structFPoint2D{int32x;int32y;};USTRUCT()structFShape{TArray
Destructors
Type | Name | Description | |
---|---|---|---|
![]() ![]() |
Destructor. |
Functions
Type | Name | Description | |
---|---|---|---|
![]() |
TFuture< TConcertDataStoreResult< T > > | CompareExchange
(
const FName& Key, |
Exchanges the stored value to Desired if a stored value corresponding to Key exists, has the same type and its value is equal to Expected, otherwise, the operation fails. |
![]() ![]() |
TFuture< TConcertDataStoreResult< T > > | Looks up the specified key, if found and types match, fetches the corresponding value. | |
![]() |
TFuture< TConcertDataStoreResult< T > > | FetchOrAdd
(
const FName& Key, |
Searches the store for the specified key, if not found, adds a new key/value pair, otherwise, if the stored value type matches the initial value type, fetches the stored value. |
![]() |
TFuture< FConcertDataStoreResult > | InternalCompareExchange
(
const FName& Key, |
Compares and exchanges a key value from the store. |
![]() ![]() |
TFuture< FConcertDataStoreResult > | InternalFetchAs
(
const FName& Key, |
Fetches a key value from the store. |
![]() |
TFuture< FConcertDataStoreResult > | InternalFetchOrAdd
(
const FName& Key, |
Fetches or adds a key/value in the store. |
![]() |
void | InternalRegisterChangeNotificationHandler
(
const FName& Key, |
Registers a delegate invoked when the specified key is added or modified. |
![]() |
void | InternalUnregisterChangeNotificationHandler
(
const FName& Key |
Unregisters the delegate corresponding to the specified key (if any) to stop receiving the key change notifications. |
![]() |
void | RegisterChangeNotificationHandler
(
const FName& InKey, |
Registers(or replaces) a handler invoked every time another client successfully adds or updates the specified key. |
![]() |
void | UnregisterChangeNotificationHander
(
const FName& Key |
Unregisters the function callback corresponding to the specified key (if any) to stop receiving the key change notifications. |
Typedefs
Name | Description |
---|---|
FChangeNotificationHandler | The function called back when the data store is updated by another client. |