Diarkis Field モジュールを使用すると、X 座標とY 座標に基づいて、他のユーザークライアントと同期することができます。
Zは「ワールド」を表します。Zが異なる場合、ユーザクライアントは分離されたパラレルワールドに存在する扱いになります。
他のユーザークライアントとの同期は非常に簡単です。
まず、クライアントから「SyncInt」を呼び出して、フィールド内に存在する他のユーザークライアントからデータを受信し始める必要があります。
次に、「Sync」を移動しながら呼び出し、視野内の他ユーザクライアントと同期したいデータを送信します。
しかし、誰とどのように同期させるかを自分でコントロールしたい場合もあるかと思います。
ここで「カスタムフィルター」が活躍します。
カスタムフィルターのしくみ
カスタムフィルターを使用するには、サーバー上でカスタムフィルターごとに一意のIDを使用して独自のカスタムフィルターを定義する必要があります。
カスタムフィルターは、視界内のユーザークライアントのリストを受け取ります。このリストを処理して、同期する相手を変更するロジックを独自に記述します。
カスタムフィルターの実装例:
// import "github.com/Diarkis/diarkis/field"
exampleCustomFilterID uint8 = 1
field.SetCustomFilter(exampleCustomFilterID, exampleFilter)
func exampleFilter(userData *user.User, usersInSight []*UserEntity) []*UserEntity {
// usersInSight is a list of users that are in sight of you
// The server will be sending your synchronize data to these users
// *UserEntity has the following functions:
// GetSID(), GetID(), and GetDistance()
// here you will execute your own logic and return the handled list of UserEntities
return handledUserEntities
}
クライアントは、カスタムフィルターIDを「Sync」に指定することにより、サーバーで実行するカスタムフィルターを選択します。
カスタムフィルターIDを使用して Sync を呼び出すC#クライアントコードの例:
uint syncLimit = 40; // we set the maximum number of user clients to synchronize with
uint exampleCustomFilterID = 1;
bool reliable = true; // if you are using UDP client, setting this flag true will turn your communication to RUDP
field.Sync(x, y, z, syncLimit, exampleCustomFilterID, msgBytes, reliable);