Ejemplo n.º 1
0
        public byte[] GetMetadata(Guid entityId, int index, int type)
        {
            var entity   = _entities[entityId];
            var metadata = entity.Metadata[index];

            if (metadata.Type != type)
            {
                throw new ArgumentOutOfRangeException(nameof(type), "Mismatched Type");
            }

            return(_metadataSerializer.Serialize(metadata.Type, metadata.Value));
        }
Ejemplo n.º 2
0
        private async Task Run()
        {
            var id = (await _createClient.GetResponse <CreateEntityResponse>(new { TypeId = 1 })).Message.EntityId;

            _logger.LogInformation($"Test ID: {id:D}");
            var s = Stopwatch.StartNew();

            while (true)
            {
                var first = (await _getMetadataClient.GetResponse <GetEntityMetadataResponse>(new
                                                                                              { EntityId = id, Index = 0, Type = 0 })).Message;
                var old            = (int)_serializer.Deserialize(first.Type, first.Data);
                var firstTransform =
                    (await _getTransformClient.GetResponse <GetEntityTransformResponse>(new { EntityId = id })).Message;
                _logger.LogInformation($"Old Value: {old} | {firstTransform.Position} | {firstTransform.Velocity}");

                if (old >= 10000)
                {
                    break;
                }

                await _sendEndpointProvider.Send <UpdateEntityMetadata>(new
                                                                        { EntityId = id, Index = 0, Type = 0, Data = _serializer.Serialize(0, old + 1) });

                await _sendEndpointProvider.Send <UpdateTransform>(new
                {
                    EntityId = id, Position = firstTransform.Position + Vector3.UnitX,
                    Velocity = firstTransform.Velocity + Vector3.UnitZ
                });

                var second =
                    (await _getMetadataClient.GetResponse <GetEntityMetadataResponse>(new
                                                                                      { EntityId = id, Index = 0, Type = 0 })).Message;
                var secondTransform =
                    (await _getTransformClient.GetResponse <GetEntityTransformResponse>(new { EntityId = id })).Message;
                var @new = (int)_serializer.Deserialize(second.Type, second.Data);
                _logger.LogInformation($"New Value: {@new} | {secondTransform.Position} | {secondTransform.Velocity}");
            }
            s.Stop();
            _logger.LogInformation($"Took {s.Elapsed}");
        }