Skip to content

Commit ba0549c

Browse files
committed
implement world copy leveraging archetype copy
1 parent 04d52e7 commit ba0549c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/Arch/Core/World.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,4 +1744,31 @@ public Signature GetSignature(Entity entity)
17441744
}
17451745
}
17461746

1747+
public partial class World
1748+
{
1749+
/// <summary>
1750+
/// Creates a deep copy of the world, copying archetypes and chunks.
1751+
/// </summary>
1752+
/// <returns>A newly created World with all data copied from the original.</returns>
1753+
public World Copy()
1754+
{
1755+
var copy = Create();
1756+
var archetypes = Archetypes.Items;
1757+
for (var index= 0; index < archetypes.Count; index++)
1758+
{
1759+
var archetype = archetypes[index];
1760+
if (archetype.EntityCount <= 0)
1761+
{
1762+
continue;
1763+
}
1764+
1765+
var newArchetype = GetOrCreate(archetype.Signature);
1766+
Archetype.Copy(archetype, newArchetype);
1767+
copy.Archetypes.Add(newArchetype);
1768+
}
1769+
1770+
return copy;
1771+
}
1772+
}
1773+
17471774
#endregion

0 commit comments

Comments
 (0)