public static Action <ConnectionId, IPEndPoint, BasicMessage.ToObject, NetBuffer> ToObject( ReplicatedObjectStore objectStore) { return((connectionId, endpoint, message, reader) => { // TODO How many bytes of the reader should be read? objectStore.DispatchMessage(connectionId, message.ReceiverId, reader); }); }
public static Action <MessageMetaData, BasicMessage.ToObject, NetBuffer> ToObject( ObjectMessageParser messageParser, ReplicatedObjectStore objectStore) { return((metadata, message, reader) => { var objectMessage = messageParser.Parse(reader); //Debug.Log("receiving message of type " + objectMessage.Content.GetType() + " for " + message.ReceiverId); objectStore.DispatchMessage(metadata.ConnectionId, message.ReceiverId, objectMessage, metadata.SequenceNumber, metadata.Latency); }); }
public static Action <MessageMetaData, BasicMessage.CreateObject, NetBuffer> CreateObject( ObjectMessageParser messageParser, ReplicatedObjectStore objectStore) { return((metadata, message, reader) => { var instance = objectStore.Instantiate(message.ObjectType, message.ObjectRole, message.ObjectId, metadata.ConnectionId, message.Position, message.Rotation); var bytesRead = 0; while (bytesRead < message.AdditionalData.WriterPosition()) { var objectMessage = messageParser.Parse(message.AdditionalData); bytesRead = message.AdditionalData.ReaderPosition(); objectStore.DispatchMessage(metadata.ConnectionId, message.ObjectId, objectMessage, new SequenceNumber(1), metadata.Latency); } objectStore.Activate(instance); }); }
public void Activate(ReplicatedObject replicatedObject) { // Generate initial state and send it to self _initialStateBuffer.Reset(); replicatedObject.ReplicationConstructor.SerializeInitialState(_initialStateBuffer); var bytesRead = 0; while (bytesRead < _initialStateBuffer.WriterPosition()) { var objectMessage = _messageParser.Parse(_initialStateBuffer); bytesRead = _initialStateBuffer.ReaderPosition(); _store.DispatchMessage(ConnectionId.Self, replicatedObject.Id, objectMessage, new SequenceNumber(1), latency: 0f); } _store.Activate(replicatedObject); _networkReplicator.Replicate(_connectionGroup.ActiveConnections, replicatedObject); }