Diarkis Field Module - Custom Filter To Control How To Synchronize With Other User Clients

Diarkis Field module allows you to synchronize with other user clients based on X and Y coordinates.

Z represents "world". Different Z are parallel worlds that the user clients will be separated by Z.

Synchronizing with other user clients is very simple.

First you must invoke "SyncInt" from the client to receive data from other user clients that are within the field of your view.

Then, as you move about, you invoked "Sync" with whatever data that you wish to synchronize with the others within the field of view.

However; there may be a situation where you want to have some control over who and how you want to synchronize with the other user clients.

This is where "Custom Filter" comes into the picture.

How Custom Filter Works

In order to use custom filters, you must define your own custom filters on the server with a unique ID for each custom filter.

Your custom filter receives a list of user clients in sight. You write your own logic to handle the list of user clients in sight to change who you want to synchronize with.

Custom Filter Example:

// 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

The client chooses which custom filter to execute on the server by giving the custom filter ID to "Sync".

C# Client Code Example Of Invoking Sync With Custom Filter ID:

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);