This commit is contained in:
DCFApixels 2025-08-23 22:45:32 +08:00
parent 1605108e49
commit 64fd11b072
5 changed files with 23 additions and 8 deletions

View File

@ -182,7 +182,11 @@ namespace DCFApixels.DragonECS
if (worldID < 0 || (worldID == NULL_WORLD_ID && nullWorld == false)) if (worldID < 0 || (worldID == NULL_WORLD_ID && nullWorld == false))
{ {
worldID = (short)_worldIdDispenser.UseFree(); int newID = _worldIdDispenser.UseFree();
#if DEBUG && DRAGONECS_DEEP_DEBUG
if (newID > short.MaxValue) { Throw.DeepDebugException(); }
#endif
worldID = (short)newID;
} }
else else
{ {

View File

@ -234,6 +234,12 @@ namespace DCFApixels.DragonECS
Array.Resize(ref _mapping, _worlds.Length); Array.Resize(ref _mapping, _worlds.Length);
} }
ref short itemIndex = ref _mapping[worldID]; ref short itemIndex = ref _mapping[worldID];
#if DEBUG && DRAGONECS_DEEP_DEBUG
if (itemIndex >= _worlds.Length)
{
Throw.UndefinedException();
}
#endif
if (itemIndex != 0) if (itemIndex != 0)
{ {
_interface.OnDestroy(ref _items[itemIndex], _worlds[worldID]); _interface.OnDestroy(ref _items[itemIndex], _worlds[worldID]);
@ -241,8 +247,8 @@ namespace DCFApixels.DragonECS
{ {
Array.Resize(ref _recycledItems, _recycledItems.Length << 1); Array.Resize(ref _recycledItems, _recycledItems.Length << 1);
} }
_items[itemIndex] = default;
_recycledItems[_recycledItemsCount++] = itemIndex; _recycledItems[_recycledItemsCount++] = itemIndex;
_items[itemIndex] = default;
itemIndex = 0; itemIndex = 0;
} }
} }

View File

@ -128,8 +128,8 @@ namespace DCFApixels.DragonECS
{ {
ref int itemIndex = ref _mapping[entityID]; ref int itemIndex = ref _mapping[entityID];
#if DEBUG #if DEBUG
if (entityID == EcsConsts.NULL_ENTITY_ID) { Throw.Ent_ThrowIsNotAlive(_source, entityID); } if (entityID == EcsConsts.NULL_ENTITY_ID) { EcsPoolThrowHelper.ThrowEntityIsNotAlive(_source, entityID); }
if (_source.IsUsed(entityID) == false) { Throw.Ent_ThrowIsNotAlive(_source, entityID); } if (_source.IsUsed(entityID) == false) { EcsPoolThrowHelper.ThrowEntityIsNotAlive(_source, entityID); }
if (itemIndex > 0) { EcsPoolThrowHelper.ThrowAlreadyHasComponent<T>(entityID); } if (itemIndex > 0) { EcsPoolThrowHelper.ThrowAlreadyHasComponent<T>(entityID); }
if (_isLocked) { EcsPoolThrowHelper.ThrowPoolLocked(); } if (_isLocked) { EcsPoolThrowHelper.ThrowPoolLocked(); }
#elif DRAGONECS_STABILITY_MODE #elif DRAGONECS_STABILITY_MODE
@ -179,7 +179,7 @@ namespace DCFApixels.DragonECS
public ref T TryAddOrGet(int entityID) public ref T TryAddOrGet(int entityID)
{ {
#if DEBUG #if DEBUG
if (entityID == EcsConsts.NULL_ENTITY_ID) { Throw.Ent_ThrowIsNotAlive(_source, entityID); } if (entityID == EcsConsts.NULL_ENTITY_ID) { EcsPoolThrowHelper.ThrowEntityIsNotAlive(_source, entityID); }
#endif #endif
ref int itemIndex = ref _mapping[entityID]; ref int itemIndex = ref _mapping[entityID];
if (itemIndex <= 0) if (itemIndex <= 0)
@ -222,7 +222,7 @@ namespace DCFApixels.DragonECS
{ {
ref int itemIndex = ref _mapping[entityID]; ref int itemIndex = ref _mapping[entityID];
#if DEBUG #if DEBUG
if (entityID == EcsConsts.NULL_ENTITY_ID) { Throw.Ent_ThrowIsNotAlive(_source, entityID); } if (entityID == EcsConsts.NULL_ENTITY_ID) { EcsPoolThrowHelper.ThrowEntityIsNotAlive(_source, entityID); }
if (itemIndex <= 0) { EcsPoolThrowHelper.ThrowNotHaveComponent<T>(entityID); } if (itemIndex <= 0) { EcsPoolThrowHelper.ThrowNotHaveComponent<T>(entityID); }
if (_isLocked) { EcsPoolThrowHelper.ThrowPoolLocked(); } if (_isLocked) { EcsPoolThrowHelper.ThrowPoolLocked(); }
#elif DRAGONECS_STABILITY_MODE #elif DRAGONECS_STABILITY_MODE

View File

@ -45,6 +45,11 @@ namespace DCFApixels.DragonECS.PoolsCore
throw new ArgumentException($"Entity({entityID}) has no component {EcsDebugUtility.GetGenericTypeName<T>()}."); throw new ArgumentException($"Entity({entityID}) has no component {EcsDebugUtility.GetGenericTypeName<T>()}.");
} }
[MethodImpl(MethodImplOptions.NoInlining)] [MethodImpl(MethodImplOptions.NoInlining)]
internal static void ThrowEntityIsNotAlive(EcsWorld world, int entityID)
{
Throw.Ent_ThrowIsNotAlive((world, entityID));
}
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowAlreadyHasComponent(Type type, int entityID) public static void ThrowAlreadyHasComponent(Type type, int entityID)
{ {
throw new ArgumentException($"Entity({entityID}) already has component {EcsDebugUtility.GetGenericTypeName(type)}."); throw new ArgumentException($"Entity({entityID}) already has component {EcsDebugUtility.GetGenericTypeName(type)}.");
@ -316,7 +321,7 @@ namespace DCFApixels.DragonECS
self.InvokeOnGet(entityID, self.Count); self.InvokeOnGet(entityID, self.Count);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static void InvokeOnGet(this List<IEcsPoolEventListener> self, int entityID, int cachedCount) public static void InvokeOnGet(this List<IEcsPoolEventListener> self, int entityID, int cachedCount)
{ {
for (int i = 1; i < cachedCount; i++) { self[i].OnGet(entityID); } for (int i = 1; i < cachedCount; i++) { self[i].OnGet(entityID); }
} }

View File

@ -116,7 +116,7 @@ namespace DCFApixels.DragonECS
public void Add(int entityID) public void Add(int entityID)
{ {
#if DEBUG #if DEBUG
if (_source.IsUsed(entityID) == false) { Throw.Ent_ThrowIsNotAlive(_source, entityID); } if (_source.IsUsed(entityID) == false) { EcsPoolThrowHelper.ThrowEntityIsNotAlive(_source, entityID); }
if (Has(entityID)) { EcsPoolThrowHelper.ThrowAlreadyHasComponent<T>(entityID); } if (Has(entityID)) { EcsPoolThrowHelper.ThrowAlreadyHasComponent<T>(entityID); }
if (_isLocked) { EcsPoolThrowHelper.ThrowPoolLocked(); } if (_isLocked) { EcsPoolThrowHelper.ThrowPoolLocked(); }
#elif DRAGONECS_STABILITY_MODE #elif DRAGONECS_STABILITY_MODE