Ejemplo n.º 1
0
        /// <summary>
        /// Clone this world.
        /// </summary>
        /// <returns>The cloned world.</returns>
        public RevolutionWorld Clone()
        {
            var cloned = new RevolutionWorld(entityInitialCapacity: this.entityToChunk.Count);

            CopyToAndIgnoreDuplicate(cloned);
            return(cloned);
        }
Ejemplo n.º 2
0
        public void TestWorldClone()
        {
            using var worldSource = new RevolutionWorld();
            var entSource  = worldSource.CreateEntity();
            var compSource = entSource.SetComponent(new Component1 {
                Value = 42
            });

            using var clone = worldSource.Clone();
            // Since it is a clone, the entity indexes are the sames.
            Assert.AreEqual(compSource.Value, clone.GetComponent <Component1>(entSource.Raw).Value);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Copy entities and components of another world into a destination. Entities that already exist in destination will be ignored.
        /// </summary>
        /// <param name="destination"></param>
        public void CopyToAndIgnoreDuplicate(RevolutionWorld destination)
        {
            foreach (var chunk in Chunks)
            {
                var clonedChunk   = destination.GetOrCreateChunk(chunk.ComponentTypes);
                var chunkEntities = chunk.Span;
                for (var i = 0; i < chunkEntities.Length; i++)
                {
                    // todo: copy identity
                    var ent = destination.CreateEntityInChunk(clonedChunk);
                }

                foreach (var(type, componentArray) in chunk.Components)
                {
                    var clonedComponentArray = clonedChunk.Components[type];
                    componentArray.CopyTo(clonedComponentArray);
                }
            }
        }
Ejemplo n.º 4
0
        public void TestMillionClone()
        {
            using var worldSource = new RevolutionWorld();
            var sw = new Stopwatch();

            sw.Restart();
            for (var i = 0; i != 1_000_000; i++)
            {
                worldSource.CreateEntity();
            }

            sw.Stop();
            Console.WriteLine($"Time to create entities in source: {sw.Elapsed.TotalMilliseconds}ms");

            sw.Restart();
            using var clone = worldSource.Clone();
            sw.Stop();
            Console.WriteLine($"Time to clone: {sw.Elapsed.TotalMilliseconds}ms");

            Assert.AreEqual(worldSource.Chunks.Length, clone.Chunks.Length);
            Assert.AreEqual(worldSource.Chunks[0].Span.Length, clone.Chunks[0].Span.Length);
        }
Ejemplo n.º 5
0
 public RevolutionSerializer()
 {
     Clients = new List <RevolutionClient>();
     World   = new RevolutionWorld(64);
 }