From 6d2b674ebcc0e0b5a8c17d7210d537c4ecc1ae75 Mon Sep 17 00:00:00 2001 From: Rich Date: Sun, 17 Dec 2023 21:00:50 -0500 Subject: [PATCH] allow getting and setting of recycled entity ids for persistence --- .../Dangerous/DangerousWorldExtensions.cs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/Arch/Core/Extensions/Dangerous/DangerousWorldExtensions.cs b/src/Arch/Core/Extensions/Dangerous/DangerousWorldExtensions.cs index be21ce9..1123f31 100644 --- a/src/Arch/Core/Extensions/Dangerous/DangerousWorldExtensions.cs +++ b/src/Arch/Core/Extensions/Dangerous/DangerousWorldExtensions.cs @@ -39,6 +39,36 @@ public static void EnsureCapacity(this World world, int capacity) world.EntityInfo.EnsureCapacity(capacity); } + /// + /// Gets the recycled entities for the world. + /// + /// The instance. + /// /// a tuple (id, version) list of the recycled entities. + 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; + } + + /// + /// Sets the recycled entities for the world. + /// + /// The instance. + /// A tuple (id, version) list of recycled entites. + 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)); + } + } + /// /// Sets the for an . ///