diff --git a/Arch.Persistence/Binary.cs b/Arch.Persistence/Binary.cs index 3f221cf..93887b6 100644 --- a/Arch.Persistence/Binary.cs +++ b/Arch.Persistence/Binary.cs @@ -1,11 +1,11 @@ -using System.Runtime.CompilerServices; -using Arch.Core; +using Arch.Core; using Arch.Core.Extensions; using Arch.Core.Extensions.Dangerous; using Arch.Core.Utils; using Arch.LowLevel.Jagged; using MessagePack; using MessagePack.Formatters; +using System.Runtime.CompilerServices; using Utf8Json; namespace Arch.Persistence; @@ -17,14 +17,14 @@ namespace Arch.Persistence; /// public partial class SingleEntityFormatter : IMessagePackFormatter { - + public void Serialize(ref MessagePackWriter writer, Entity value, MessagePackSerializerOptions options) { // Write id writer.WriteInt32(value.Id); #if !PURE_ECS - + // Write world writer.WriteInt32(value.WorldId); #endif @@ -32,7 +32,7 @@ public void Serialize(ref MessagePackWriter writer, Entity value, MessagePackSer // Write size var componentTypes = value.GetComponentTypes(); writer.WriteInt32(componentTypes.Length); - + // Write components foreach (ref var type in componentTypes.AsSpan()) { @@ -51,7 +51,7 @@ public Entity Deserialize(ref MessagePackReader reader, MessagePackSerializerOpt var entityId = reader.ReadInt32(); #if !PURE_ECS - + // Read world id var worldId = reader.ReadInt32(); #endif @@ -59,7 +59,7 @@ public Entity Deserialize(ref MessagePackReader reader, MessagePackSerializerOpt // Read size var size = reader.ReadInt32(); var components = new object[size]; - + // Read components for (var index = 0; index < size; index++) { @@ -71,7 +71,7 @@ public Entity Deserialize(ref MessagePackReader reader, MessagePackSerializerOpt // Create the entity var entity = EntityWorld.Create(); - EntityWorld.AddRange(entity,components.AsSpan()); + EntityWorld.AddRange(entity, components.AsSpan()); return entity; } } @@ -104,11 +104,11 @@ public partial class ArrayFormatter : IMessagePackFormatter public void Serialize(ref MessagePackWriter writer, Array value, MessagePackSerializerOptions options) { var type = value.GetType().GetElementType(); - + // Write type and size MessagePackSerializer.Serialize(ref writer, type, options); writer.WriteUInt32((uint)value.Length); - + // Write array for (var index = 0; index < value.Length; index++) { @@ -122,10 +122,10 @@ public Array Deserialize(ref MessagePackReader reader, MessagePackSerializerOpti // Write type and size var type = MessagePackSerializer.Deserialize(ref reader, options); var size = reader.ReadUInt32(); - + // Create array var array = Array.CreateInstance(type, size); - + // Read array for (var index = 0; index < size; index++) { @@ -167,7 +167,7 @@ public JaggedArray Deserialize(ref MessagePackReader reader, MessagePackSeria { var capacity = reader.ReadInt32(); var jaggedArray = new JaggedArray(CpuL1CacheSize / Unsafe.SizeOf(), _filler,capacity); - + for (var index = 0; index < capacity; index++) { var item = MessagePackSerializer.Deserialize(ref reader, options); @@ -176,7 +176,7 @@ public JaggedArray Deserialize(ref MessagePackReader reader, MessagePackSeria return jaggedArray; } -} +} /// /// The class @@ -188,7 +188,7 @@ public void Serialize(ref MessagePackWriter writer, ComponentType value, Message { // Write id writer.WriteUInt32((uint)value.Id); - + // Write bytesize writer.WriteUInt32((uint)value.ByteSize); } @@ -213,13 +213,17 @@ public void Serialize(ref MessagePackWriter writer, World value, MessagePackSeri { // Write entity info MessagePackSerializer.Serialize(ref writer, value.GetVersions(), options); - + // Write slots MessagePackSerializer.Serialize(ref writer, value.GetSlots(), options); - + + //Write recycled entity ids + List<(int, int)> recycledEntityIDs = value.GetRecycledEntityIds(); + MessagePackSerializer.Serialize(ref writer, recycledEntityIDs, options); + // Write archetypes writer.WriteUInt32((uint)value.Archetypes.Count); - foreach(var archetype in value) + foreach (Archetype archetype in value) { MessagePackSerializer.Serialize(ref writer, archetype, options); } @@ -228,31 +232,35 @@ public void Serialize(ref MessagePackWriter writer, World value, MessagePackSeri public World Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) { // Create world and setup formatter - var world = World.Create(); - var archetypeFormatter = options.Resolver.GetFormatter() as ArchetypeFormatter; - var entityFormatter = options.Resolver.GetFormatter() as EntityFormatter; + World world = World.Create(); + ArchetypeFormatter? archetypeFormatter = options.Resolver.GetFormatter() as ArchetypeFormatter; + EntityFormatter? entityFormatter = options.Resolver.GetFormatter() as EntityFormatter; entityFormatter.WorldId = world.Id; archetypeFormatter.World = world; // Read versions - var versions = MessagePackSerializer.Deserialize>(ref reader, options); - + JaggedArray versions = MessagePackSerializer.Deserialize>(ref reader, options); + // Read slots - var slots = MessagePackSerializer.Deserialize>(ref reader, options); - + JaggedArray<(int, int)> slots = MessagePackSerializer.Deserialize>(ref reader, options); + + //Read recycled entity ids + List<(int, int)> recycledEntityIDs = MessagePackSerializer.Deserialize>(ref reader, options); + // Read archetypes - var size = reader.ReadInt32(); - var archetypes = new List(); - - for(var index = 0; index < size; index++) + int size = reader.ReadInt32(); + List archetypes = new(); + + for (int index = 0; index < size; index++) { - var archetype = archetypeFormatter.Deserialize(ref reader, options); + Archetype archetype = archetypeFormatter.Deserialize(ref reader, options); archetypes.Add(archetype); } - + // Forward values to the world world.SetArchetypes(archetypes); world.SetVersions(versions); + world.SetRecycledEntityIds(recycledEntityIDs); world.SetSlots(slots); world.EnsureCapacity(versions.Capacity); return world; @@ -266,7 +274,7 @@ public World Deserialize(ref MessagePackReader reader, MessagePackSerializerOpti /// public partial class ArchetypeFormatter : IMessagePackFormatter { - + public void Serialize(ref MessagePackWriter writer, Archetype value, MessagePackSerializerOptions options) { // Setup formatters @@ -280,10 +288,10 @@ public void Serialize(ref MessagePackWriter writer, Archetype value, MessagePack // Write lookup array MessagePackSerializer.Serialize(ref writer, value.GetLookupArray(), options); - + // Write chunk size writer.WriteUInt32((uint)value.Size); - + // Write chunks for (var index = 0; index < value.Size; index++) { @@ -294,15 +302,15 @@ public void Serialize(ref MessagePackWriter writer, Archetype value, MessagePack public Archetype Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) { - + var chunkFormatter = options.Resolver.GetFormatter() as ChunkFormatter; - + // Types var types = MessagePackSerializer.Deserialize(ref reader, options); // Archetype lookup array var lookupArray = MessagePackSerializer.Deserialize(ref reader, options); - + // Archetype chunk size and list var chunkSize = reader.ReadUInt32(); @@ -310,13 +318,13 @@ public Archetype Deserialize(ref MessagePackReader reader, MessagePackSerializer var chunks = new List((int)chunkSize); var archetype = DangerousArchetypeExtensions.CreateArchetype(types.ToArray()); archetype.SetSize((int)chunkSize); - + // Pass types and lookup array to the chunk formatter for saving performance and memory chunkFormatter.World = World; chunkFormatter.Archetype = archetype; chunkFormatter.Types = types; chunkFormatter.LookupArray = lookupArray; - + // Deserialise each chunk and put it into the archetype. var entities = 0; for (var index = 0; index < chunkSize; index++) @@ -325,7 +333,7 @@ public Archetype Deserialize(ref MessagePackReader reader, MessagePackSerializer chunks.Add(chunk); entities += chunk.Size; } - + archetype.SetChunks(chunks); archetype.SetEntities(entities); return archetype; @@ -342,10 +350,10 @@ public void Serialize(ref MessagePackWriter writer, Chunk value, MessagePackSeri { // Write size writer.WriteUInt32((uint)value.Size); - + // Write capacity writer.WriteUInt32((uint)value.Capacity); - + // Write entitys MessagePackSerializer.Serialize(ref writer, value.Entities, options); @@ -364,16 +372,16 @@ public Chunk Deserialize(ref MessagePackReader reader, MessagePackSerializerOpti { // Read chunk size var size = reader.ReadUInt32(); - + // Read chunk size var capacity = reader.ReadUInt32(); - + // Read entities var entities = MessagePackSerializer.Deserialize(ref reader, options); - + // Create chunk var chunk = DangerousChunkExtensions.CreateChunk((int)capacity, LookupArray, Types); - entities.CopyTo(chunk.Entities,0); + entities.CopyTo(chunk.Entities, 0); chunk.SetSize((int)size); // Updating World.EntityInfoStorage to their new archetype @@ -383,16 +391,16 @@ public Chunk Deserialize(ref MessagePackReader reader, MessagePackSerializerOpti entity = DangerousEntityExtensions.CreateEntityStruct(entity.Id, World.Id); World.SetArchetype(entity, Archetype); } - + // Persist arrays as an array... for (var index = 0; index < Types.Length; index++) { // Read array of the type var array = MessagePackSerializer.Deserialize(ref reader, options); var chunkArray = chunk.GetArray(array.GetType().GetElementType()); - Array.Copy(array,chunkArray, (int)size); + Array.Copy(array, chunkArray, (int)size); } - + return chunk; } } diff --git a/Arch.Persistence/Json.cs b/Arch.Persistence/Json.cs index c0cb769..1ddd812 100644 --- a/Arch.Persistence/Json.cs +++ b/Arch.Persistence/Json.cs @@ -1,13 +1,11 @@ -using System.Runtime.CompilerServices; -using Arch.Core; +using Arch.Core; using Arch.Core.Extensions; using Arch.Core.Extensions.Dangerous; using Arch.Core.Utils; using Arch.LowLevel.Jagged; using CommunityToolkit.HighPerformance; +using System.Runtime.CompilerServices; using Utf8Json; -using Utf8Json.Formatters; -using Utf8Json.Resolvers; namespace Arch.Persistence; @@ -18,28 +16,28 @@ namespace Arch.Persistence; /// public partial class SingleEntityFormatter : IJsonFormatter { - + /// /// The the entity belongs to. /// internal World EntityWorld { get; set; } - + public void Serialize(ref JsonWriter writer, Entity value, IJsonFormatterResolver formatterResolver) { writer.WriteBeginObject(); - + // Write id writer.WritePropertyName("id"); writer.WriteInt32(value.Id); writer.WriteValueSeparator(); #if !PURE_ECS - + // Write world writer.WritePropertyName("worldId"); writer.WriteInt32(value.WorldId); writer.WriteValueSeparator(); - + #endif // Write size @@ -47,7 +45,7 @@ public void Serialize(ref JsonWriter writer, Entity value, IJsonFormatterResolve writer.WritePropertyName("size"); writer.WriteInt32(componentTypes.Length); writer.WriteValueSeparator(); - + // Write components writer.WritePropertyName("components"); writer.WriteBeginArray(); @@ -67,7 +65,7 @@ public void Serialize(ref JsonWriter writer, Entity value, IJsonFormatterResolve writer.WriteValueSeparator(); } writer.AdvanceOffset(-1); - + writer.WriteEndArray(); writer.WriteEndObject(); } @@ -82,12 +80,12 @@ public Entity Deserialize(ref JsonReader reader, IJsonFormatterResolver formatte reader.ReadIsValueSeparator(); #if !PURE_ECS - + // Read world id reader.ReadPropertyName(); var worldId = reader.ReadInt32(); reader.ReadIsValueSeparator(); - + #endif // Read size @@ -97,14 +95,14 @@ public Entity Deserialize(ref JsonReader reader, IJsonFormatterResolver formatte var components = new object[size]; var count = 0; - + // Read components reader.ReadPropertyName(); reader.ReadIsBeginArray(); while (!reader.ReadIsEndArrayWithSkipValueSeparator(ref count)) { reader.ReadIsBeginObject(); - + // Read type reader.ReadPropertyName(); var type = JsonSerializer.Deserialize(ref reader); @@ -112,14 +110,14 @@ public Entity Deserialize(ref JsonReader reader, IJsonFormatterResolver formatte reader.ReadPropertyName(); var cmp = JsonSerializer.NonGeneric.Deserialize(type.Type, ref reader, formatterResolver); - components[count-1] = cmp; + components[count - 1] = cmp; reader.ReadIsEndObject(); } // Creat the entity var entity = EntityWorld.Create(); - EntityWorld.AddRange(entity,components.AsSpan()); - + EntityWorld.AddRange(entity, components.AsSpan()); + reader.ReadIsEndObject(); return entity; } @@ -127,13 +125,13 @@ public Entity Deserialize(ref JsonReader reader, IJsonFormatterResolver formatte public partial class EntityFormatter : IJsonFormatter, IObjectPropertyNameFormatter { - + /// /// The all deserialized s will belong to. /// Due to the nature of deserialisation and changing world landscape we need to assign new WorldIds to the deserialized entities. /// internal int WorldId { get; set; } - + public void Serialize(ref JsonWriter writer, Entity value, IJsonFormatterResolver formatterResolver) { writer.WriteInt32(value.Id); @@ -174,17 +172,17 @@ public partial class ArrayFormatter : IJsonFormatter public void Serialize(ref JsonWriter writer, Array value, IJsonFormatterResolver formatterResolver) { var type = value.GetType().GetElementType(); - + // Write type and size writer.WriteBeginObject(); writer.WritePropertyName("type"); JsonSerializer.Serialize(ref writer, type, formatterResolver); writer.WriteValueSeparator(); - + writer.WritePropertyName("size"); writer.WriteUInt32((uint)value.Length); writer.WriteValueSeparator(); - + // Write array writer.WritePropertyName("items"); writer.WriteBeginArray(); @@ -206,14 +204,14 @@ public Array Deserialize(ref JsonReader reader, IJsonFormatterResolver formatter reader.ReadPropertyName(); var type = JsonSerializer.Deserialize(ref reader, formatterResolver); reader.ReadIsValueSeparator(); - + reader.ReadPropertyName(); var size = reader.ReadUInt32(); reader.ReadIsValueSeparator(); - + // Create array var array = Array.CreateInstance(type, size); - + // Read array reader.ReadPropertyName(); reader.ReadIsBeginArray(); @@ -238,14 +236,13 @@ public partial class JaggedArrayFormatter : IJsonFormatter> { public void Serialize(ref JsonWriter writer, JaggedArray value, IJsonFormatterResolver formatterResolver) { - writer.WriteBeginObject(); - + // Write length/capacity and items writer.WritePropertyName("capacity"); writer.WriteInt32(value.Capacity); writer.WriteValueSeparator(); - + // Write items writer.WritePropertyName("items"); writer.WriteBeginArray(); @@ -274,7 +271,7 @@ public JaggedArray Deserialize(ref JsonReader reader, IJsonFormatterResolver reader.ReadPropertyName(); var capacity = reader.ReadInt32(); reader.ReadIsValueSeparator(); - + // Read items var jaggedArray = new JaggedArray(CpuL1CacheSize / Unsafe.SizeOf(), _filler,capacity); reader.ReadPropertyName(); @@ -290,7 +287,7 @@ public JaggedArray Deserialize(ref JsonReader reader, IJsonFormatterResolver return jaggedArray; } -} +} /// /// The class @@ -301,12 +298,12 @@ public partial class ComponentTypeFormatter : IJsonFormatter public void Serialize(ref JsonWriter writer, ComponentType value, IJsonFormatterResolver formatterResolver) { writer.WriteBeginObject(); - + // Write id writer.WritePropertyName("id"); writer.WriteUInt32((uint)value.Id); writer.WriteValueSeparator(); - + // Write bytesize writer.WritePropertyName("byteSize"); writer.WriteUInt32((uint)value.ByteSize); @@ -325,7 +322,7 @@ public ComponentType Deserialize(ref JsonReader reader, IJsonFormatterResolver f reader.ReadPropertyName(); var bytesize = reader.ReadUInt32(); reader.ReadIsValueSeparator(); - + reader.ReadIsEndObject(); return new ComponentType((int)id, (int)bytesize); @@ -350,15 +347,41 @@ public void Serialize(ref JsonWriter writer, World value, IJsonFormatterResolver writer.WritePropertyName("versions"); JsonSerializer.Serialize(ref writer, value.GetVersions(), formatterResolver); writer.WriteValueSeparator(); - + // Write slots writer.WritePropertyName("slots"); JsonSerializer.Serialize(ref writer, value.GetSlots(), formatterResolver); writer.WriteValueSeparator(); + //Write recycled entity ids + writer.WritePropertyName("recycledEntityIDs"); + writer.WriteBeginArray(); + List<(int, int)> recycledEntityIDs = value.GetRecycledEntityIds(); + foreach ((int, int) recycledId in recycledEntityIDs) + { + writer.WriteBeginObject(); + writer.WritePropertyName("id"); + writer.WriteInt32(recycledId.Item1); + writer.WriteValueSeparator(); + writer.WritePropertyName("version"); + writer.WriteInt32(recycledId.Item2); + writer.WriteEndObject(); + + writer.WriteValueSeparator(); + } + // Cut last value seperator + if (recycledEntityIDs.Count > 0) + { + writer.AdvanceOffset(-1); + } + writer.WriteEndArray(); + + writer.WriteValueSeparator(); + + //Write archetypes writer.WritePropertyName("archetypes"); writer.WriteBeginArray(); - foreach(var archetype in value) + foreach (Archetype archetype in value) { JsonSerializer.Serialize(ref writer, archetype, formatterResolver); writer.WriteValueSeparator(); @@ -381,34 +404,58 @@ public World Deserialize(ref JsonReader reader, IJsonFormatterResolver formatter var entityFormatter = formatterResolver.GetFormatter() as EntityFormatter; entityFormatter.WorldId = world.Id; archetypeFormatter.World = world; - + reader.ReadIsBeginObject(); // Read versions reader.ReadPropertyName(); var versions = JsonSerializer.Deserialize>(ref reader, formatterResolver); reader.ReadIsValueSeparator(); - + // Read slots reader.ReadPropertyName(); - var slots = JsonSerializer.Deserialize>(ref reader, formatterResolver); + JaggedArray<(int, int)> slots = JsonSerializer.Deserialize>(ref reader, formatterResolver); + reader.ReadIsValueSeparator(); + + // Read recycled ids + int count = 0; + List<(int, int)> recycledIds = new(); + + reader.ReadPropertyName(); + reader.ReadIsBeginArray(); + + while (!reader.ReadIsEndArrayWithSkipValueSeparator(ref count)) + { + reader.ReadIsBeginObject(); + reader.ReadPropertyName(); + int id = reader.ReadInt32(); + reader.ReadIsValueSeparator(); + reader.ReadPropertyName(); + int value = reader.ReadInt32(); + reader.ReadIsEndObject(); + + (int, int) recycledId = new(id, value); + + recycledIds.Add(recycledId); + } + reader.ReadIsValueSeparator(); // Read archetypes - var count = 0; - var archetypes = new List(); - + count = 0; + List archetypes = new(); reader.ReadPropertyName(); reader.ReadIsBeginArray(); while (!reader.ReadIsEndArrayWithSkipValueSeparator(ref count)) { - var archetype = archetypeFormatter.Deserialize(ref reader, formatterResolver); + Archetype archetype = archetypeFormatter.Deserialize(ref reader, formatterResolver); archetypes.Add(archetype); } - + // Forward values to the world world.SetArchetypes(archetypes); world.SetVersions(versions); + world.SetRecycledEntityIds(recycledIds); world.SetSlots(slots); world.EnsureCapacity(versions.Capacity); @@ -423,12 +470,12 @@ public World Deserialize(ref JsonReader reader, IJsonFormatterResolver formatter /// public partial class ArchetypeFormatter : IJsonFormatter { - + /// /// The which is being used by this formatter during serialisation/deserialisation. /// internal World World { get; set; } - + public void Serialize(ref JsonWriter writer, Archetype value, IJsonFormatterResolver formatterResolver) { // Setup formatters @@ -436,7 +483,7 @@ public void Serialize(ref JsonWriter writer, Archetype value, IJsonFormatterReso var chunks = value.Chunks; var chunkFormatter = formatterResolver.GetFormatter() as ChunkFormatter; chunkFormatter.Types = types; - + writer.WriteBeginObject(); // Write type array @@ -448,7 +495,7 @@ public void Serialize(ref JsonWriter writer, Archetype value, IJsonFormatterReso writer.WritePropertyName("lookup"); JsonSerializer.Serialize(ref writer, value.GetLookupArray(), formatterResolver); writer.WriteValueSeparator(); - + // Write chunk size writer.WritePropertyName("chunkSize"); writer.WriteUInt32((uint)value.Size); @@ -469,7 +516,7 @@ public void Serialize(ref JsonWriter writer, Archetype value, IJsonFormatterReso { writer.AdvanceOffset(-1); } - + writer.WriteEndArray(); writer.WriteEndObject(); } @@ -489,7 +536,7 @@ public Archetype Deserialize(ref JsonReader reader, IJsonFormatterResolver forma reader.ReadPropertyName(); var lookupArray = JsonSerializer.Deserialize(ref reader, formatterResolver); reader.ReadIsValueSeparator(); - + // Archetype chunk size and list reader.ReadPropertyName(); var chunkSize = reader.ReadUInt32(); @@ -499,17 +546,17 @@ public Archetype Deserialize(ref JsonReader reader, IJsonFormatterResolver forma var chunks = new List((int)chunkSize); var archetype = DangerousArchetypeExtensions.CreateArchetype(types.ToArray()); archetype.SetSize((int)chunkSize); - + // Pass types and lookup array to the chunk formatter for saving performance and memory chunkFormatter.World = World; chunkFormatter.Archetype = archetype; chunkFormatter.Types = types; chunkFormatter.LookupArray = lookupArray; - + // Deserialise each chunk and put it into the archetype. reader.ReadPropertyName(); reader.ReadIsBeginArray(); - + var entities = 0; for (var index = 0; index < chunkSize; index++) { @@ -518,10 +565,10 @@ public Archetype Deserialize(ref JsonReader reader, IJsonFormatterResolver forma entities += chunk.Size; reader.ReadIsValueSeparator(); } - + archetype.SetChunks(chunks); archetype.SetEntities(entities); - + reader.ReadIsEndArray(); reader.ReadIsEndObject(); return archetype; @@ -534,19 +581,19 @@ public Archetype Deserialize(ref JsonReader reader, IJsonFormatterResolver forma /// public partial class ChunkFormatter : IJsonFormatter { - + /// /// The the current (de)serialized belongs to. /// Since chunks do not know this, we need to pass this information along it. /// internal World World { get; set; } - + /// /// The the current (de)serialized belongs to. /// Since chunks do not know this, we need to pass this information along it. /// internal Archetype Archetype { get; set; } - + /// /// The types used in the in each (de)serialized by this formatter. /// Since does not have a reference to them and its controlled by its . @@ -558,21 +605,21 @@ public partial class ChunkFormatter : IJsonFormatter /// Since does not have a reference to them and its controlled by its . /// internal int[] LookupArray { get; set; } = Array.Empty(); - + public void Serialize(ref JsonWriter writer, Chunk value, IJsonFormatterResolver formatterResolver) { writer.WriteBeginObject(); - + // Write size writer.WritePropertyName("size"); writer.WriteUInt32((uint)value.Size); writer.WriteValueSeparator(); - + // Write capacity writer.WritePropertyName("capacity"); writer.WriteUInt32((uint)value.Capacity); writer.WriteValueSeparator(); - + // Write entitys writer.WritePropertyName("entitys"); JsonSerializer.NonGeneric.Serialize(ref writer, value.Entities, formatterResolver); @@ -596,7 +643,7 @@ public void Serialize(ref JsonWriter writer, Chunk value, IJsonFormatterResolver { writer.AdvanceOffset(-1); } - + writer.WriteEndArray(); writer.WriteEndObject(); } @@ -609,20 +656,20 @@ public Chunk Deserialize(ref JsonReader reader, IJsonFormatterResolver formatter reader.ReadPropertyName(); var size = reader.ReadUInt32(); reader.ReadIsValueSeparator(); - + // Read chunk size reader.ReadPropertyName(); var capacity = reader.ReadUInt32(); reader.ReadIsValueSeparator(); - + // Read entities reader.ReadPropertyName(); var entities = JsonSerializer.Deserialize(ref reader, formatterResolver); reader.ReadIsValueSeparator(); - + // Create chunk var chunk = DangerousChunkExtensions.CreateChunk((int)capacity, LookupArray, Types); - entities.CopyTo(chunk.Entities,0); + entities.CopyTo(chunk.Entities, 0); chunk.SetSize((int)size); // Updating World.EntityInfoStorage to their new archetype @@ -632,7 +679,7 @@ public Chunk Deserialize(ref JsonReader reader, IJsonFormatterResolver formatter entity = DangerousEntityExtensions.CreateEntityStruct(entity.Id, World.Id); World.SetArchetype(entity, Archetype); } - + // Persist arrays as an array... reader.ReadPropertyName(); reader.ReadIsBeginArray(); @@ -641,10 +688,10 @@ public Chunk Deserialize(ref JsonReader reader, IJsonFormatterResolver formatter // Read array of the type var array = JsonSerializer.Deserialize(ref reader, formatterResolver); var chunkArray = chunk.GetArray(array.GetType().GetElementType()); - Array.Copy(array,chunkArray, (int)size); + Array.Copy(array, chunkArray, (int)size); reader.ReadIsValueSeparator(); } - + reader.ReadIsEndArray(); reader.ReadIsEndObject(); return chunk;