Diarkis Field module allows you to synchronize with other user clients based on X and Y coordinates.
Diarkis Field はクライアントの X と Y 座標を基にお互の同期を取ることができます。
クライアントはサーバに自身の X と Y 座標と Z の値を同期したいデータと一緒にサーバに通信します。
サーバでは、クライアントから送られてきた座標を基に自動で視界に入ると判断したクライアントにデータを通知してクライアント同士の同期を成立させます。
Z の値と扱いについて
Z の値は「空間世界」を示します。つまり同じ座標であったとしても別の Z の値「空間世界」を持つクライアント同士は同期を取ることがありません。パラレルワールドのように考えるとわかりやすいかもしれません。
Diarkis Field の同期の仕組みについて
Diarkis Field はクライアントから送られてくる X と Y の座標と Z の値を使って同期する必要があるクライアントを見つけます。座標と一緒にクライアントから送られてくるデータのバイト配列をクライアント間で送受信させることで同期をさせます。
ステップ:
- まず最初にフィールドに参加した際に SyncInit を呼び出して自身の視界に入るクライアントの同期データを取得すると同時に他のクライアントに自身を同期させます。
- その後クライアントは更新(移動など)をする度に Sync を呼び出すことで視界に入る他のクライアントと同期を続けます。
- フィールドにいる限り上記のステップ 2 を任意に繰り返します。
C# Code Example For SyncInit:
// this event receives the synchronization data from other user clients in sight
field.OnSyncInitResponse += (List<byte[]> synchronizeDataList) =>
{
// we do something here with synchronizeDataList
};
uint syncLimit = 40; // maximum number of user clients to synchronize with
uint customFilterID = 0; // passing 0 means no customFilter to be executed on the server
byte[] synchronizeData; // data to be synchronized with other user clients
field.SyncInit(x, y, z, syncLimit, customFilterID, synchronizeData);
C# Code Example For Sync:
// this event receives the synchronization data from the other user clients in sight
field.OnSync += (byte[] synchronizeData) =>
{
// we do something nice here with synchronizeData
};
uint syncLimit = 40; // maximum number of user clients to synchronize with
uint customFilterID = 0; // passing 0 means no customFilter to be executed on the server
byte[] synchronizeData; // data to be synchronized with other user clients
bool reliable = false; // if you are using UDP client, setting this flag to true will turn this into RUDP communication
field.Sync(x, y, z, syncLimit, customFilterID, synchronizeData, reliable);
Diarkis Field によるワールドマップの取り扱い
Diarkis Field は自動でマップ全体を「グリッド」と呼ばれる小さなマップに分割してそれぞれのサーバに割り振って管理します。
Diarkis のサーバ・クラスタに変化(スケール・イン/アウトなど)がある度にこの「グリッド」は自動で再計算されて自動で割り振りが更新されます。
フィールドにいるクライアントはそれぞれの座標に応じて正しいグリッドに自動で割り振られます。
クライアントはマップを移動することで「グリッド」間を移動しマップ全体を散策することが可能になります。