Field module creates a virtual world where all connected clients can “see” each other without selecting a server to connect to. Clients that “see” each other automatically exchange messages in real-time. The default size of the virtual world is 37,7970,000 square meters (Roughly the same surface area as Japan) and the field of vision for all clients is 100 meters.
How To Set Up Field Module
The Field module must be set up with either TCP or UDP class instances.
With TCP Client: TCP client has to connect to the server.
Diarkis.Tcp tcp = new Diarkis.Tcp();
Diarkis.Modules.Field field = new Diarkis.Modules.Field();
field.SetupAsTcp(tcp);
With UDP Client: UDP client has to connect to the server.
Diarkis.Udp udp = new Diarkis.Udp();
Diarkis.Modules.Field field = new Diarkis.Modules.Field();
field.SetupAsTcp(udp);
How To Initialize The Client On The Server
In order to start with the Field module server, you must “initialize” the client.
// We receive a response from the server once the client is successfully initialized on the server
field.OnResponseSyncInit += HandleDiarkisFieldInit;
// Initialize the client by sending its current X and Y coordinates along with the Z (It is not height, but Z represents dimension)
// syncLimit controls the maximum number of remote clients to synchronize with
int syncLimit = 30;
// customFilterID executes custom filter function on the server (This is not available for Diarkis Cloud)
int customFilterID = 0;
// message will be sent to all remote clients that are within the field of view
field.SyncInit(x, y, z, syncLimit, customFilterID, message);
// The event is raised when the client is successfully initialized on the server by SyncInit
private void HandleDiarkisFieldInit(List<byte[]> remoteMessages)
{
// remoteMessages contains messages of the remote clients within the field of view
}
How To Synchronize With Remote Clients In The Field
By calling the Sync method at a certain interval, the client is able to synchronize the client’s coordinates and send messages to remote clients.
How Coordinate Zero Is Treated By Field Module
The clients with coordinates 0 will NOT overlap the field of vision of the clients with other coordinates than 0.
How Negative Coordinates Are Treated By Field Module
The clients with negative coordinate values will NOT overlap the field of vision of the clients with positive coordinates.
NOTE: SyncInit must be called before using Sync
// This is how to receive remote clients' messages sent by their Sync
field.OnSync += HandleDiarkisFieldSync;
// Sending its current X and Y coordinates along with the Z (It is not height, but Z represents dimension)
// syncLimit controls the maximum number of remote clients to synchronize with
int syncLimit = 30;
// customFilterID executes custom filter function on the server (This is not available for Diarkis Cloud)
int customFilterID = 0;
// message will be sent to all remote clients that are within the field of view
// for UDP, reliable=true will make the message an RUDP packet
bool reliable = false;
field.Sync(x, y, z, syncLimit, customFilterID, message, reliable);
// message is the byte array sent from remote clients
private void HandleDiarkisFieldSync(byte[] message)
{
// remoteMessages contains messages of the remote clients within the field of view
}
How To Remove Itself From The Field
You may need to notify remote clients that your client is no longer in the field. The example below shows how to send a notification of client disappearance and the event listener to handle notifications from the remote clients.
// This is the event handler for remote client disappearance
field.OnDisappear += HandleDiarkisFieldDisappear;
// Notify all remote clients within the field of view that you are no longer in the field
field.Disappear();
private void HandleDiarkisFieldDisappear(string uid)
{
// uid is the User ID of the client disappeared
}