Ejemplo n.º 1
0
 public static void SaveTemporary(IPersistentObject obj)
 {
     using (var stream = new FileStream(GetTempLocation().FullName, FileMode.Create))
         using (var writer = new BinaryWriter(stream))
         {
             writer.Write(KTempVersion);
             writer.Write((byte)SaveType.Temporary);
             BackEnd.Persist(stream, obj.EnumeratePersistedObjects());
         }
 }
Ejemplo n.º 2
0
        public void StreamingRoundTrip()
        {
            var input = new UTinyRegistry();

            var type = input.CreateType(
                UTinyId.New(),
                "TestStruct",
                UTinyTypeCode.Struct);

            type.CreateField("IntField", (UTinyType.Reference)UTinyType.Int32);
            type.CreateField("FloatField", (UTinyType.Reference)UTinyType.Int32);
            type.CreateField("StringField", (UTinyType.Reference)UTinyType.Int32);

            var module = input.CreateModule(
                UTinyId.New(),
                "TestModule");

            module.AddStructReference((UTinyType.Reference)type);

            using (var command = new MemoryStream())
            {
                // Write the data model to a stream as json
                // mem -> command
                BackEnd.Persist(command,
                                type,
                                module);

                command.Position = 0;

                // Create a registry to hold accepted objects
                var output = new UTinyRegistry();

                // Process the command
                // commands -> mem
                FrontEnd.Accept(command, output);

                Assert.IsNotNull(output.FindById <UTinyType>(type.Id));
                Assert.IsNotNull(output.FindById <UTinyModule>(module.Id));
            }
        }
 public string ToJson()
 {
     return(BackEnd.Persist(this));
 }
Ejemplo n.º 4
0
        public void CommandStreamEntityPerformance()
        {
            var registry = new UTinyRegistry();

            var vector3Type = registry.CreateType(
                UTinyId.New(),
                "Vector3",
                UTinyTypeCode.Struct);

            vector3Type.CreateField("X", (UTinyType.Reference)UTinyType.Float32);
            vector3Type.CreateField("Y", (UTinyType.Reference)UTinyType.Float32);
            vector3Type.CreateField("Z", (UTinyType.Reference)UTinyType.Float32);

            var transformType = registry.CreateType(
                UTinyId.New(),
                "Transform",
                UTinyTypeCode.Component);

            transformType.CreateField("Position", (UTinyType.Reference)vector3Type);
            transformType.CreateField("Scale", (UTinyType.Reference)vector3Type);

            const int kCount   = 1000;
            var       entities = new UTinyEntity[kCount];
            var       transformTypeReference = (UTinyType.Reference)transformType;

            {
                var watch = System.Diagnostics.Stopwatch.StartNew();

                for (var i = 0; i < kCount; i++)
                {
                    entities[i] = registry.CreateEntity(UTinyId.New(), "Entity_" + i);
                    var transform = entities[i].AddComponent(transformTypeReference);

                    // if (i < kCount)
                    {
                        transform.Refresh(null, true);

                        var position = transform["Position"] as UTinyObject;
                        position["X"] = i * 2f;
                    }
                }

                watch.Stop();
                Debug.Log($"Create Objects Entities=[{kCount}] {watch.ElapsedMilliseconds}ms");
            }

            using (var command = new MemoryStream())
            {
                // Write the data model to a stream as json
                // mem -> command

                // Push the types to the command stream before the accept
                BackEnd.Persist(command, vector3Type, transformType);

                {
                    var watch = System.Diagnostics.Stopwatch.StartNew();

                    BackEnd.Persist(command, (IEnumerable <UTinyEntity>)entities);

                    watch.Stop();
                    Debug.Log($"CommandStream.BackEnd.Persist Entities=[{kCount}] {watch.ElapsedMilliseconds}ms Len=[{command.Position}]");
                }

                command.Position = 0;

                // Create a registry to hold accepted objects
                var output = new UTinyRegistry();

                // Process the command
                // commands -> mem
                {
                    var watch = System.Diagnostics.Stopwatch.StartNew();

                    FrontEnd.Accept(command, output);

                    watch.Stop();
                    Debug.Log($"CommandStream.FrontEnd.Accept Entities=[{kCount}] {watch.ElapsedMilliseconds}ms");
                }
            }
        }
 public static string ToJson(TreeNode node)
 {
     return(BackEnd.Persist(node));
 }
 public override string ToString()
 {
     return(BackEnd.Persist(this));
 }
 public CommandMemento(UTinyRegistryObjectBase obj)
 {
     Version = obj.Version;
     Data    = new MemoryStream();
     BackEnd.Persist(Data, obj);
 }