/// <summary> /// Adds a client to the session. /// Returns null if the identifier is being used. /// </summary> /// <param name="identifier"></param> /// <param name="client"></param> /// <returns></returns> public virtual URollbackClient AddClient(int identifier, URollbackClient client) { if (clients.ContainsKey(identifier)) { return(null); } clients.Add(identifier, client); OnClientAdded?.Invoke(identifier); return(clients[identifier]); }
/// <summary> /// Get the client with the highest RTT value. /// </summary> /// <returns></returns> public virtual URollbackClient GetHighestRTTClient() { URollbackClient highestRTTClient = new URollbackClient(-1); foreach (URollbackClient client in clients.Values) { if (client.RTT >= highestRTTClient.RTT) { highestRTTClient = client; } } return(highestRTTClient); }
/// <summary> /// Advances the input frame coutner for a remote client, /// and calculates a remoteFrameLag value for that client. /// </summary> /// <param name="localIdentifier"></param> /// <param name="identifier"></param> public virtual URollbackErrorCode AddRemoteInput(int localIdentifier, int remoteIdentifier, ClientInputDefinition clientInput) { if (!clients.ContainsKey(remoteIdentifier) || !clients.ContainsKey(localIdentifier)) { return(URollbackErrorCode.INVALID_CLIENT); } URollbackClient localClient = GetClient(localIdentifier); URollbackClient remoteClient = GetClient(remoteIdentifier); remoteClient.AddInput(clientInput); remoteClient.AddRemoteFrameLag(localClient.InputFrame); return(URollbackErrorCode.OK); }
/// <summary> /// Adds an input for the local client, and adds a /// localFrameLag value for remote clients. /// </summary> /// <param name="identifier"></param> public virtual URollbackErrorCode AddLocalInput(int identifier, ClientInputDefinition clientInput) { if (!clients.ContainsKey(identifier)) { return(URollbackErrorCode.INVALID_CLIENT); } URollbackClient localClient = GetClient(identifier); localClient.AddInput(clientInput); OnAdvanceLocalInput?.Invoke(identifier); // Calculate how many frames we're predicting for remote client(s). foreach (URollbackClient remoteClient in clients.Values) { if (remoteClient != localClient) { remoteClient.AddLocalFrameLag(localClient.InputFrame); } } return(URollbackErrorCode.OK); }