Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow getting and setting of recycled entity ids for persistence #193

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading