From 32ed705fc46c2c33fecc15ff36870acba53bc906 Mon Sep 17 00:00:00 2001 From: DCFApixels <99481254+DCFApixels@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:20:39 +0800 Subject: [PATCH] add EcsWorld.InitEntitySlot --- src/EcsWorld.cs | 11 ++++++++++- src/Utils/Exceptions.cs | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index 4a7c860..8563944 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -389,7 +389,16 @@ namespace DCFApixels.DragonECS return *(entlong*)&x; } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public unsafe EntitySlotInfo GetEntitySlotInfoDebug(int entityID) + public void InitEntitySlot(int entityID, short gen) + { +#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS + if (Count > 0) { Throw.World_MethodCalledAfterEntityCreation(nameof(InitEntitySlot)); } +#endif + _entityDispenser.Upsize(entityID); + _entities[entityID].gen = gen; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public EntitySlotInfo GetEntitySlotInfoDebug(int entityID) { return new EntitySlotInfo(entityID, _entities[entityID].gen, ID); } diff --git a/src/Utils/Exceptions.cs b/src/Utils/Exceptions.cs index a6655d2..19a4aa6 100644 --- a/src/Utils/Exceptions.cs +++ b/src/Utils/Exceptions.cs @@ -113,6 +113,11 @@ namespace DCFApixels.DragonECS.Internal { throw new EcsFrameworkException("This world can't be destroyed"); } + [MethodImpl(MethodImplOptions.NoInlining)] + public static void World_MethodCalledAfterEntityCreation(string methodName) + { + throw new EcsFrameworkException($"The method {methodName} can only be executed before creating entities in the world."); + } [MethodImpl(MethodImplOptions.NoInlining)] internal static void Ent_ThrowIsNotAlive(entlong entity)