Skip to content

Commit

Permalink
allow getting and setting of recycled entity ids for persistence (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
richdog authored Dec 18, 2023
1 parent 967b8b8 commit 1d6b832
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/Arch/Core/Extensions/Dangerous/DangerousWorldExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,36 @@ public static void EnsureCapacity(this World world, int capacity)
world.EntityInfo.EnsureCapacity(capacity);
}

/// <summary>
/// Gets the recycled entities for the world.
/// </summary>
/// <param name="world">The <see cref="World"/> instance.</param>
/// /// <returns>a tuple (id, version) list of the recycled entities.</returns>
public static List<(int, int)> GetRecycledEntityIds(this World world)
{
List<(int, int)> recycledIdsList = new();
foreach (RecycledEntity id in world.RecycledIds)
{
recycledIdsList.Add((id.Id, id.Version));
}

return recycledIdsList;
}

/// <summary>
/// Sets the recycled entities for the world.
/// </summary>
/// <param name="world">The <see cref="World"/> instance.</param>
/// <param name="recycledEntities">A tuple (id, version) list of recycled entites.</param>
public static void SetRecycledEntityIds(this World world, List<(int, int)> recycledEntities)
{
world.RecycledIds.Clear();
foreach ((int, int) recycledEntity in recycledEntities)
{
world.RecycledIds.Enqueue(new RecycledEntity(recycledEntity.Item1, recycledEntity.Item2));
}
}

/// <summary>
/// Sets the <see cref="EntityInfo.Archetype"/> for an <see cref="Entity"/>.
/// </summary>
Expand Down

0 comments on commit 1d6b832

Please sign in to comment.