You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
945 B
35 lines
945 B
using System; |
|
using Unity.Collections; |
|
using Unity.Mathematics; |
|
|
|
namespace GameCore.TinyECS |
|
{ |
|
public struct EntityDatabase<TEnum, TData> : IDisposable where TEnum : unmanaged where TData : unmanaged, IEntityDataStruct |
|
{ |
|
public TData dataStruct; |
|
public EntityGenerator<TEnum> generator; |
|
public EntityCollection<TEnum> collection; |
|
|
|
public Entity<TEnum> AddEntity() |
|
{ |
|
var entity = generator.Create(); |
|
collection.Add(entity); |
|
dataStruct.Add(); |
|
return entity; |
|
} |
|
|
|
public void RemoveEntity(Entity<TEnum> entity) |
|
{ |
|
generator.Delete(entity); |
|
if (collection.Remove(entity, out var index, out var _)) |
|
dataStruct.Remove(index); |
|
} |
|
|
|
public void Dispose() |
|
{ |
|
generator.Dispose(); |
|
collection.Dispose(); |
|
dataStruct.Dispose(); |
|
} |
|
} |
|
} |