public void Convert_DateTime() { var dt = new DateTime(2018, 1, 30, 11, 12, 13, DateTimeKind.Utc); var obj = ProtoConverter.Convert(JToken.FromObject(dt)); Assert.Equal(dt.ToString("o"), obj.StringValue); }
public void Convert_Uri() { var uri = new Uri("https://example.com:8081/path?param=eter&an=other"); var obj = ProtoConverter.Convert(JToken.FromObject(uri)); Assert.Equal(uri.ToString(), obj.StringValue); }
public void Convert_Guid() { var guid = Guid.NewGuid(); var obj = ProtoConverter.Convert(JToken.FromObject(guid)); Assert.Equal(guid.ToString("B"), obj.StringValue); }
public override async Task Stream( IAsyncStreamReader <ClientEvent> requestStream, IServerStreamWriter <ServerEvent> responseStream, ServerCallContext context) { var guid = Guid.NewGuid(); writers.TryAdd(guid, responseStream); SimulationEntity entity = null; while (await requestStream.MoveNext()) { var current = requestStream.Current; var id = Guid.Parse(current.Entity.Id); if (!universe.TryGetEntity(id, out entity)) { entity = new SimulationEntity(id); entity.Components.Add(new EntityComponent()); entity.Components.Add(new PhysicsComponent(new Body())); universe.Add(entity); } var pc = entity.GetComponent <PhysicsComponent>(); pc.Body.LinearPosition = ProtoConverter.Convert(current.Entity.Position); pc.Body.LinearVelocity = ProtoConverter.Convert(current.Entity.Velocity); pc.Body.AngularPosition = ProtoConverter.Convert(current.Entity.Rotation); } if (entity != null) { universe.Remove(entity); } writers.TryRemove(guid, out var unused); }
public static BuildItem FromProtoBuilding(Vector3D location) { var item = new BuildItem(); item.info.lossyScale = new UnityEngine.Vector3(1.33f, 1.33f, 1.33f); item.info.position = ProtoConverter.ToUnityVector(location); return(item); }
public EntityServiceImpl() { universe = new Universe(); universe.Add(new BehaviorProcessor()); runner = new Runner(); runner.Universe = universe; running = runner.Run(); universe.Stepped += (s, e) => { var se = new ServerEvent(); foreach (var entity in universe.Entities) { var pc = entity.GetComponent <PhysicsComponent>(); var ec = entity.GetComponent <EntityComponent>(); se.Entities.Add(new Proto.Entity { Id = entity.Identifier.ToString(), Position = ProtoConverter.Convert(pc.Body.LinearPosition), Velocity = ProtoConverter.Convert(pc.Body.LinearVelocity), Rotation = ProtoConverter.Convert(pc.Body.AngularPosition), Class = ec?.Class ?? "" }); } // Console.WriteLine("Emitting " + se.Entities.Count); foreach (var writer in writers) { writer.Value.WriteAsync(se); } }; for (int i = 0; i < 10; i++) { var bloid = new SimulationEntity(); bloid.Components.Add(new TransformComponent { Scaling = new Vector3(0.2f, 0.2f, 0.2f) }); bloid.Components.Add(new BehaviorComponent()); bloid.Components.Add(new PhysicsComponent(new Body { LinearPosition = Functions.Random.NextVector3(-10, 10), LinearVelocity = Functions.Random.NextVector3(-10, 10), AngularPosition = Functions.Random.NextQuaternion() })); bloid.Components.Add(new EntityComponent { Class = "ai" }); universe.Add(bloid); } }
public void Convert_Primitives() { Assert.Equal(Value.KindOneofCase.NullValue, ProtoConverter.Convert(null).KindCase); Assert.Equal("Hello world", ProtoConverter.Convert("Hello world").StringValue); Assert.Equal(42.0, ProtoConverter.Convert(42).NumberValue); Assert.Equal(42.0, ProtoConverter.Convert(42L).NumberValue); Assert.Equal(42.5, ProtoConverter.Convert(42.5).NumberValue); Assert.Equal(42.5, ProtoConverter.Convert(42.5f).NumberValue); Assert.True(ProtoConverter.Convert(true).BoolValue); }
public void Convert_Bytes() { var bytesShort = new byte[] { 1, 2, 3 }; var objShort = ProtoConverter.Convert(JToken.FromObject(bytesShort)); Assert.Equal("01 02 03", objShort.StringValue); var bytesLong = Enumerable.Repeat((byte)0xff, 1000).ToArray(); var objLong = ProtoConverter.Convert(JToken.FromObject(bytesLong)); Assert.Equal(string.Join(" ", Enumerable.Repeat("ff", 32)) + "...(length:1000)", objLong.StringValue); }
private void FillBigChunkHeights(List <Gardarike.GetWorldMapResponse> serverChunks) { int chunkSize = (int)GlobalConstants.SERVER_CHUNK_SIZE; foreach (var chunk in serverChunks) { var offsetX = (chunk.Map.X - centralCell.x + 1) * chunkSize; var offsetY = (chunk.Map.Y - centralCell.y + 1) * chunkSize; var chunkData = ProtoConverter.ToHeightsFromProto(chunk.Map.Data); data.SetHeights(offsetX, offsetY, chunkData); } }
private void ProcessMapChunk(GetWorldMapResponse chunkInfo) { Debug.Log("Processing map chunk..."); Debug.Log("Towns on the chunk: " + chunkInfo.Map.Towns.Count); Debug.Log("Trees on chank: " + chunkInfo.Map.Trees); Debug.Log("Plants on chank: " + chunkInfo.Map.Plants); Debug.Log("Stones on chank: " + chunkInfo.Map.Stones); PlayerPrefs.SetString("View", "Global"); MapCache.StoreWorldChunk(chunkInfo); var heights = ProtoConverter.ToHeightsFromProto(chunkInfo.Map.Data); EventBus.instance.TerrainLoaded(heights, chunkInfo.Map.X, chunkInfo.Map.Y); }
public void Convert_Object() { var obj = ProtoConverter.Convert(new JObject { { "a", "a" }, { "b", 2 }, { "c", false }, { "d", new JArray { 1, 2 } } }); var fields = obj.StructValue.Fields; Assert.Equal("a", fields["a"].StringValue); Assert.Equal(2.0, fields["b"].NumberValue); Assert.False(fields["c"].BoolValue); Assert.Equal(new[] { 1.0, 2.0 }, fields["d"].ListValue.Values.Select(x => x.NumberValue)); }
public void Convert_Array() { var array = ProtoConverter.Convert(new JArray { 1, 2, 3 }); Assert.Equal(new[] { 1.0, 2.0, 3.0 }, array.ListValue.Values.Select(x => x.NumberValue)); var arrayPoly = ProtoConverter.Convert(new JArray { true, "s", 1.5, null }); var values = arrayPoly.ListValue.Values; Assert.True(values[0].BoolValue); Assert.Equal("s", values[1].StringValue); Assert.Equal(1.5, values[2].NumberValue); Assert.Equal(Value.KindOneofCase.NullValue, values[3].KindCase); }
void Start() { var size = 4; var protoHeights = new RepeatedField <float>(); for (int height = 0; height < 16; height++) { protoHeights.Add(height); } var resultHeights = ProtoConverter.ToHeightsFromProto(protoHeights); Debug.Log("["); for (int i = 0; i < size; i++) { Debug.Log("\n"); for (int j = 0; j < size; j++) { Debug.Log(resultHeights[i, j] + ", "); } } }
public void Convert_TimeSpan() { var obj = ProtoConverter.Convert(JToken.FromObject(TimeSpan.FromSeconds(2))); Assert.Equal(TimeSpan.FromSeconds(2).ToString("c"), obj.StringValue); }