Пример #1
0
 CommandRequestSerialize(global::System.UInt32 componentId,
                         global::System.UIntPtr userData,
                         global::System.UIntPtr handle)
 {
     try
     {
         var _pool = global::Improbable.Worker.Internal.ClientHandles.Instance.GetGcHandlePool(handle);
         var data  = (global::Improbable.Worker.Internal.GenericCommandObject)
                     global::Improbable.Worker.Internal.ClientHandles.Instance.Dereference(handle);
         if (data.CommandId == 1)
         {
             var command       = new global::Improbable.Worker.CInterop.SchemaCommandRequest(60, 1);
             var requestObject = (Commands.Disconnect.Request)data.CommandObject;
             global::Improbable.Restricted.DisconnectRequest_Internal.Write(_pool, requestObject.Value, command.GetObject());
             return(command);
         }
     }
     catch (global::System.Exception e)
     {
         global::Improbable.Worker.ClientError.LogClientException(e);
     }
     return(null);
 }
Пример #2
0
            public override void SendCommands(ComponentGroup commandGroup, ComponentSystemBase system, global::Improbable.Worker.CInterop.Connection connection)
            {
                Profiler.BeginSample("ComponentWithNoFieldsWithCommands");
                var entityType = system.GetArchetypeChunkEntityType();

                {
                    var senderType    = system.GetArchetypeChunkComponentType <Improbable.Gdk.Tests.ComponentsWithNoFields.ComponentWithNoFieldsWithCommands.CommandSenders.Cmd>(true);
                    var responderType = system.GetArchetypeChunkComponentType <Improbable.Gdk.Tests.ComponentsWithNoFields.ComponentWithNoFieldsWithCommands.CommandResponders.Cmd>(true);

                    var chunks = commandGroup.CreateArchetypeChunkArray(Allocator.TempJob);
                    foreach (var chunk in chunks)
                    {
                        var entities   = chunk.GetNativeArray(entityType);
                        var senders    = chunk.GetNativeArray(senderType);
                        var responders = chunk.GetNativeArray(responderType);
                        for (var i = 0; i < senders.Length; i++)
                        {
                            var requests  = senders[i].RequestsToSend;
                            var responses = responders[i].ResponsesToSend;
                            if (requests.Count > 0)
                            {
                                foreach (var request in requests)
                                {
                                    var schemaCommandRequest = new global::Improbable.Worker.CInterop.SchemaCommandRequest(ComponentId, 1);
                                    global::Improbable.Gdk.Tests.ComponentsWithNoFields.Empty.Serialization.Serialize(request.Payload, schemaCommandRequest.GetObject());

                                    var requestId = connection.SendCommandRequest(request.TargetEntityId.Id,
                                                                                  new global::Improbable.Worker.CInterop.CommandRequest(schemaCommandRequest),
                                                                                  request.TimeoutMillis,
                                                                                  request.AllowShortCircuiting ? ShortCircuitParameters : null);

                                    cmdStorage.CommandRequestsInFlight[requestId] =
                                        new CommandRequestStore <global::Improbable.Gdk.Tests.ComponentsWithNoFields.Empty>(entities[i], request.Payload, request.Context, request.RequestId);
                                }

                                requests.Clear();
                            }

                            if (responses.Count > 0)
                            {
                                foreach (var response in responses)
                                {
                                    var requestId = response.RequestId;

                                    if (response.FailureMessage != null)
                                    {
                                        // Send a command failure if the string is non-null.
                                        connection.SendCommandFailure((uint)requestId, response.FailureMessage);
                                        continue;
                                    }

                                    var schemaCommandResponse = new global::Improbable.Worker.CInterop.SchemaCommandResponse(ComponentId, 1);
                                    global::Improbable.Gdk.Tests.ComponentsWithNoFields.Empty.Serialization.Serialize(response.Payload.Value, schemaCommandResponse.GetObject());

                                    connection.SendCommandResponse((uint)requestId, new global::Improbable.Worker.CInterop.CommandResponse(schemaCommandResponse));
                                }

                                responses.Clear();
                            }
                        }
                    }

                    chunks.Dispose();
                }

                Profiler.EndSample();
            }
Пример #3
0
 CommandRequestDeserialize(global::System.UInt32 componentId,
                           global::System.UIntPtr userData,
                           global::Improbable.Worker.CInterop.SchemaCommandRequest source,
                           out global::System.UIntPtr handleOut)
 {
     handleOut = global::System.UIntPtr.Zero;
     try
     {
         var data   = new global::Improbable.Worker.Internal.GenericCommandObject();
         var handle = global::Improbable.Worker.Internal.ClientHandles.HandleAlloc();
         *handle   = global::Improbable.Worker.Internal.ClientHandles.Instance.CreateHandle(data);
         handleOut = (global::System.UIntPtr)handle;
         if (source.GetCommandIndex() == 1)
         {
             data.CommandId     = 1;
             data.CommandObject = new Commands.Disconnect.Request(global::Improbable.Restricted.DisconnectRequest_Internal.Read(source.GetObject()));
             return(true);
         }
         return(false);
     }
     catch (global::System.Exception e)
     {
         global::Improbable.Worker.ClientError.LogClientException(e);
         return(false);
     }
 }