ensured only one component per type can be present on a single entity
This commit is contained in:
@ -5,6 +5,7 @@ namespace EngineSharp.Core.ECS;
|
||||
|
||||
public class Scene
|
||||
{
|
||||
// TODO: Maybe instead of a List, use a HashSet instead. Maybe implement a equality comparer to ensure, only one element per type can be present
|
||||
private readonly Dictionary<long, List<LogicComponent>> _logicComponents = new();
|
||||
private readonly Dictionary<long, List<DataComponent>> _dataComponents = new();
|
||||
private readonly Dictionary<long, List<RenderComponent>> _renderComponents = new();
|
||||
@ -40,6 +41,9 @@ public class Scene
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If the component already exists on the entity, it will not be added
|
||||
/// </summary>
|
||||
internal void AddComponent<T>(Entity entity, T component)
|
||||
where T : class, IComponent
|
||||
{
|
||||
@ -81,11 +85,14 @@ public class Scene
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If the component already exists on the entity, it will not be added
|
||||
/// </summary>
|
||||
private static void AddComponent<TComponent, TArchetype>(long id, TComponent component, Dictionary<long, List<TArchetype>> componentStore)
|
||||
where TArchetype : class, IComponent
|
||||
where TComponent : TArchetype
|
||||
{
|
||||
if (componentStore.TryGetValue(id, out var components))
|
||||
if (componentStore.TryGetValue(id, out var components) && !components.OfType<TComponent>().Any())
|
||||
{
|
||||
components.Add(component);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user