This commit is contained in:
2025-12-12 17:22:41 +09:00
parent a3863c1263
commit 7db4be1e6e
5 changed files with 44 additions and 37 deletions

View File

@@ -157,7 +157,9 @@ internal unsafe struct Chunk : IDisposable
public void Dispose()
{
_data.Dispose();
Console.WriteLine($"Disposing chunk data");
_versions.Dispose();
Console.WriteLine($"Disposing chunk versions");
}
}
@@ -587,9 +589,12 @@ internal unsafe struct Archetype : IIdentifierType, IDisposable
{
if (_chunks.IsCreated)
{
var i= 0;
foreach (ref var chunk in _chunks)
{
Console.WriteLine($"Disposing chunk {i} of archetype {_id}");
chunk.Dispose();
i++;
}
}

View File

@@ -68,7 +68,7 @@ public partial class EntityManager
/// <returns>True if the ManagedEntity exists, false otherwise.</returns>
public bool Exists(ManagedEntity managedEntity)
{
return _scriptComponents.Contain(managedEntity.id, managedEntity.generation);
return _scriptComponents.Contains(managedEntity.id, managedEntity.generation);
}
/// <summary>

View File

@@ -60,7 +60,7 @@ public unsafe partial class EntityManager : IDisposable
public Entity CreateEntity()
{
var entities = (Span<Entity>)stackalloc Entity[1];
CreateEntities(1, entities);
CreateEntities(entities);
return entities[0];
}
@@ -73,7 +73,7 @@ public unsafe partial class EntityManager : IDisposable
public Entity CreateEntity(params ReadOnlySpan<Identifier<IComponent>> componentTypeIDs)
{
var entities = (Span<Entity>)stackalloc Entity[1];
CreateEntities(1, entities, componentTypeIDs);
CreateEntities(entities, componentTypeIDs);
return entities[0];
}
@@ -81,14 +81,13 @@ public unsafe partial class EntityManager : IDisposable
/// <summary>
/// Create multiple entities with no components.
/// </summary>
/// <param name="count">The number of entities to create.</param>
/// <param name="entities">The span to store the created entities.</param>
public void CreateEntities(int count, Span<Entity> entities)
public void CreateEntities(Span<Entity> entities)
{
ref var emptyArchetype = ref _world.GetArchetypeReference(World.EmptyArchetypeID);
emptyArchetype.AllocateEntity(out var chunkIndex, out var rowIndex);
for (var i = 0; i < count; i++)
for (var i = 0; i < entities.Length; i++)
{
var id = _entityLocations.Add(new EntityLocation
{
@@ -130,11 +129,10 @@ public unsafe partial class EntityManager : IDisposable
/// <summary>
/// Create multiple entities with specified components.
/// </summary>
/// <param name="count">The number of entities to create.</param>
/// <param name="allocator">The allocator to use for the returned array.</param>
/// <param name="componentTypeIDs">The component type IDs to add to the entities. </param>
/// <returns>An array of the created entities.</returns>
public void CreateEntities(int count, Span<Entity> entities, params ReadOnlySpan<Identifier<IComponent>> componentTypeIDs)
public void CreateEntities(Span<Entity> entities, params ReadOnlySpan<Identifier<IComponent>> componentTypeIDs)
{
var signatureHash = ComponentRegister.GetHashCode(componentTypeIDs);
var arcID = _world.GetArchetypeIDBySignatureHash(signatureHash);
@@ -146,7 +144,7 @@ public unsafe partial class EntityManager : IDisposable
ref var archetype = ref _world.GetArchetypeReference(arcID);
for (var i = 0; i < count; i++)
for (var i = 0; i < entities.Length; i++)
{
archetype.AllocateEntity(out var chunkIndex, out var rowIndex);
@@ -230,6 +228,18 @@ public unsafe partial class EntityManager : IDisposable
return ErrorStatus.None;
}
/// <summary>
/// Destroy the specified entities.
/// </summary>
/// <param name="entities">The entities to destroy.</param>
public void DestroyEntities(ReadOnlySpan<Entity> entities)
{
for (var i = 0; i < entities.Length; i++)
{
DestroyEntity(entities[i]);
}
}
/// <summary>
/// Check if the specified entity exists.
/// </summary>
@@ -714,9 +724,6 @@ public unsafe partial class EntityManager : IDisposable
return;
}
Debug.Assert(_entityLocations.Count == 0, "There are still entities alive when disposing EntityManager.");
Debug.Assert(_scriptComponents.Count == 0, "There are still managed entities alive when disposing EntityManager.");
_entityLocations.Dispose();
_disposed = true;