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)