public void AddMetaData(CommandMetaData commandMetaData) { if (commandMetaData.IsEmpty()) { pool.Return(commandMetaData); } else { lock (metaDataToAdd) { metaDataToAdd.Add(commandMetaData); } } }
public void SerializeFrom(MessagesToSend messages, CommandMetaData commandMetaData) { messages.GetSerializedComponentUpdates().CopyTo(updates); foreach (var serializer in commandSerializers) { serializer.Serialize(messages, this, commandMetaData); } foreach (var metrics in messages.GetMetrics()) { metricsToSend.Add(metrics); } messages.GetLogMessages().CopyTo(logMessages); foreach (var serializer in componentSerializers) { serializer.Serialize(messages, this); } }
public void SerializeFrom(MessagesToSend messages, CommandMetaData commandMetaData) { foreach (var serializer in commandSerializers) { serializer.Serialize(messages, this, commandMetaData); } foreach (var metrics in messages.GetMetrics()) { metricsToSend.Add(metrics); } messages.GetLogMessages().CopyTo(logMessages); messages.GetAuthorityLossAcknowledgements().CopyTo(authorityLossAcks); foreach (var serializer in componentSerializers) { serializer.Serialize(messages, this); } }
private void SerializeMessages() { // Block until a new message is available to serialize. while (messagesToSerialize.TryTake(out var messagesToSend, -1)) { // If adding is complete then there is no reason to deserialize the message. if (messagesToSerialize.IsAddingCompleted) { return; } SerializedMessagesToSend serialized = serializedMessagesToSendPool.Rent(); CommandMetaData metaData = commandMetaDataManager.GetEmptyMetaDataStorage(); // Serialize the messages and add them to the queue to be sent serialized.SerializeFrom(messagesToSend, metaData); messagesToSend.Clear(); messagesToSendPool.Return(messagesToSend); serializedMessages.Enqueue(serialized); } }
internal void AddMetaData(CommandMetaData commandMetaData) { metaData.Add(commandMetaData); }
public void Serialize(MessagesToSend messages, SerializedMessagesToSend serializedMessages, CommandMetaData commandMetaData) { var storage = messages.GetWorldCommandStorage(); SerializeCreateEntityRequests(storage, serializedMessages, commandMetaData); SerializeDeleteEntityRequests(storage, serializedMessages, commandMetaData); SerializeReserveEntityIdsRequests(storage, serializedMessages, commandMetaData); SerializeEntityQueryRequests(storage, serializedMessages, commandMetaData); }
private void SerializeCreateEntityRequests(WorldCommandsToSendStorage storage, SerializedMessagesToSend serializedMessages, CommandMetaData commandMetaData) { var requests = storage.GetCreateEntityResponses(); for (var i = 0; i < requests.Count; ++i) { ref readonly var request = ref requests[i];
public void SendAndClear(Connection connection, CommandMetaData commandMetaData, NetFrameStats frameStats) { for (var i = 0; i < updates.Count; ++i) { ref readonly var update = ref updates[i];
/// <summary> /// Iterate over the op list and populate a ViewDiff from the data contained. /// </summary> /// <returns>True if the current ViewDiff is inside a critical section.</returns> public bool ParseOpListIntoDiff(OpList opList, CommandMetaData commandMetaData) { if (shouldClear) { viewDiff.Clear(); shouldClear = false; } var netStats = viewDiff.GetNetStats(); for (var i = 0; i < opList.GetOpCount(); ++i) { switch (opList.GetOpType(i)) { case OpType.Disconnect: viewDiff.Disconnect(opList.GetDisconnectOp(i).Reason); break; case OpType.FlagUpdate: var flagOp = opList.GetFlagUpdateOp(i); viewDiff.SetWorkerFlag(flagOp.Name, flagOp.Value); break; case OpType.LogMessage: var logOp = opList.GetLogMessageOp(i); viewDiff.AddLogMessage(logOp.Message, logOp.Level); break; case OpType.Metrics: var metricsOp = opList.GetMetricsOp(i); viewDiff.AddMetrics(metricsOp.Metrics); break; case OpType.CriticalSection: var criticalSectionOp = opList.GetCriticalSectionOp(i); viewDiff.SetCriticalSection(criticalSectionOp.InCriticalSection); break; case OpType.AddEntity: viewDiff.AddEntity(opList.GetAddEntityOp(i).EntityId); break; case OpType.RemoveEntity: viewDiff.RemoveEntity(opList.GetRemoveEntityOp(i).EntityId); break; case OpType.ReserveEntityIdsResponse: var reserveEntityIdsOp = opList.GetReserveEntityIdsResponseOp(i); ComponentOpDeserializer.ApplyReserveEntityIdsResponse(reserveEntityIdsOp, viewDiff, commandMetaData); netStats.AddWorldCommandResponse(WorldCommand.ReserveEntityIds); break; case OpType.CreateEntityResponse: var createEntityOp = opList.GetCreateEntityResponseOp(i); ComponentOpDeserializer.ApplyCreateEntityResponse(createEntityOp, viewDiff, commandMetaData); netStats.AddWorldCommandResponse(WorldCommand.CreateEntity); break; case OpType.DeleteEntityResponse: var deleteEntityOp = opList.GetDeleteEntityResponseOp(i); ComponentOpDeserializer.ApplyDeleteEntityResponse(deleteEntityOp, viewDiff, commandMetaData); netStats.AddWorldCommandResponse(WorldCommand.DeleteEntity); break; case OpType.EntityQueryResponse: var entityQueryOp = opList.GetEntityQueryResponseOp(i); ComponentOpDeserializer.ApplyEntityQueryResponse(entityQueryOp, viewDiff, commandMetaData); netStats.AddWorldCommandResponse(WorldCommand.EntityQuery); break; case OpType.AddComponent: ComponentOpDeserializer.DeserializeAndAddComponent(opList.GetAddComponentOp(i), viewDiff); break; case OpType.RemoveComponent: var removeComponentOp = opList.GetRemoveComponentOp(i); viewDiff.RemoveComponent(removeComponentOp.EntityId, removeComponentOp.ComponentId); break; case OpType.AuthorityChange: var authorityOp = opList.GetAuthorityChangeOp(i); viewDiff.SetAuthority(authorityOp.EntityId, authorityOp.ComponentId, authorityOp.Authority); break; case OpType.ComponentUpdate: var updateOp = opList.GetComponentUpdateOp(i); ComponentOpDeserializer.DeserializeAndApplyComponentUpdate(updateOp, viewDiff, componentUpdateId); ++componentUpdateId; netStats.AddUpdate(updateOp.Update); break; case OpType.CommandRequest: var commandRequestOp = opList.GetCommandRequestOp(i); ComponentOpDeserializer.DeserializeAndApplyCommandRequestReceived(commandRequestOp, viewDiff); netStats.AddCommandRequest(commandRequestOp.Request); break; case OpType.CommandResponse: var commandResponseOp = opList.GetCommandResponseOp(i); ComponentOpDeserializer.DeserializeAndApplyCommandResponseReceived( commandResponseOp, viewDiff, commandMetaData); netStats.AddCommandResponse(commandResponseOp.Response, commandResponseOp.Message); break; default: throw new ArgumentOutOfRangeException( $"Can not deserialise unkown op type {opList.GetOpType(i)}"); } } return(viewDiff.InCriticalSection); }