Exemplo n.º 1
0
        private static void EntityQueryCallback(EntityQueryResponseOp op)
        {
            busPoints.Clear();
            foreach (System.Collections.Generic.KeyValuePair <EntityId, Entity> KVPair in op.Result)
            {
                BusStopData?busStopData = KVPair.Value.Get(BusStop.Metaclass);
                if (busStopData.HasValue)
                {
                    originX = busStopData.Value.originX;
                    originY = busStopData.Value.originY;
                    offsetX = busStopData.Value.offsetX;
                    offsetY = busStopData.Value.offsetY;
                }

                PositionData?posData = KVPair.Value.Get(Position.Metaclass);
                if (posData.HasValue && !busStopData.HasValue) // Don't update the positions if it's bus stops
                {
                    Coordinates coords = posData.Value.coords;
                    PointShape  point  = CoordsToPoint(coords);
                    if (point != null)
                    {
                        busPoints.Add(KVPair.Key, point);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void OnEntityQueryResponse(EntityQueryResponseOp op)
        {
            EntityQueryRequest request = requestIdToEntityQueryRequest[op.RequestId.Id];

            requestIdToEntityQueryRequest.Remove(op.RequestId.Id);

            var result = new Dictionary <long, Worker.Entity>();

            foreach (var pair in op.Result)
            {
                result.Add(pair.Key.Id, pair.Value);
            }

            Entity entity;

            if (!TryGetEntityFromEntityId(request.SenderEntityId, "EntityQuery", out entity))
            {
                return;
            }

            var response =
                new EntityQueryResponse((CommandStatusCode)op.StatusCode, op.Message, op.ResultCount, result, request);

            view.AddCommandResponse(entity, response, entityQueryResponsePool);
        }
Exemplo n.º 3
0
        public static WrappedOp <EntityQueryResponseOp> CreateEntityQueryResponseOp(long requestId)
        {
            var op = new EntityQueryResponseOp
            {
                RequestId = new RequestId <EntityQueryRequest>(requestId)
            };

            return(new WrappedOp <EntityQueryResponseOp>(op));
        }
Exemplo n.º 4
0
        public static WrappedOp <EntityQueryResponseOp> CreateEntityQueryResponseOp(long requestId)
        {
            var op = new EntityQueryResponseOp
            {
                RequestId   = new RequestId <EntityQueryRequest>(requestId),
                Result      = new Dictionary <EntityId, Entity>(),
                ResultCount = 0,
            };

            return(new WrappedOp <EntityQueryResponseOp>(op));
        }
Exemplo n.º 5
0
        private void CompleteCommand(EntityQueryResponseOp r)
        {
            if (!requestsToComplete.TryRemove(r.RequestId, out var completer))
            {
                return;
            }

            if (r.StatusCode == StatusCode.Success)
            {
                completer.Complete(new CommandResponses {
                    EntityQuery = r
                });
            }
            else
            {
                completer.Fail(r.StatusCode, r.Message);
            }
        }
Exemplo n.º 6
0
        private void OnEntityQueryResponse(EntityQueryResponseOp op)
        {
            if (!entityQueryStorage.CommandRequestsInFlight.TryGetValue(op.RequestId.Id, out var requestBundle))
            {
                worker.LogDispatcher.HandleLog(LogType.Error, new LogEvent(RequestIdNotFound)
                                               .WithField(LoggingUtils.LoggerName, LoggerName)
                                               .WithField("RequestId", op.RequestId.Id)
                                               .WithField("Command Type", "EntityQuery"));
                return;
            }

            var entity = requestBundle.Entity;

            entityQueryStorage.CommandRequestsInFlight.Remove(op.RequestId.Id);

            if (!EntityManager.Exists(entity))
            {
                worker.LogDispatcher.HandleLog(LogType.Log, new LogEvent(EntityNotFound)
                                               .WithField(LoggingUtils.LoggerName, LoggerName)
                                               .WithField("Op", "EntityQueryResponseOp")
                                               );
                return;
            }

            List <WorldCommands.EntityQuery.ReceivedResponse> responses;

            if (EntityManager.HasComponent <WorldCommands.EntityQuery.CommandResponses>(entity))
            {
                responses = EntityManager.GetComponentData <WorldCommands.EntityQuery.CommandResponses>(entity)
                            .Responses;
            }
            else
            {
                var data = new WorldCommands.EntityQuery.CommandResponses
                {
                    Handle = WorldCommands.EntityQuery.ResponsesProvider.Allocate(World)
                };
                responses = data.Responses = new List <WorldCommands.EntityQuery.ReceivedResponse>();
                EntityManager.AddComponentData(entity, data);
            }

            responses.Add(
                new WorldCommands.EntityQuery.ReceivedResponse(op, requestBundle.Request, requestBundle.Context));
        }
Exemplo n.º 7
0
                internal ReceivedResponse(EntityQueryResponseOp op, Entity sendingEntity, Request req, long requestId)
                {
                    SendingEntity  = sendingEntity;
                    StatusCode     = op.StatusCode;
                    Message        = op.Message;
                    ResultCount    = op.ResultCount;
                    RequestPayload = req;
                    Context        = req.Context;
                    RequestId      = requestId;

                    if (op.Result == null)
                    {
                        Result = null;
                        return;
                    }

                    Result = new Dictionary <EntityId, EntitySnapshot>();
                    foreach (var entityIdToEntity in op.Result)
                    {
                        Result.Add(new EntityId(entityIdToEntity.Key), new EntitySnapshot(entityIdToEntity.Value));
                    }
                }
Exemplo n.º 8
0
 private void HandleEntityQueryResponse(EntityQueryResponseOp op)
 {
     entityQueryResponseCallbacks.InvokeAll(op);
 }