-
Notifications
You must be signed in to change notification settings - Fork 0
/
EntityComponentMap.cs
38 lines (30 loc) · 1.06 KB
/
EntityComponentMap.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.Collections.Generic;
namespace MelonECS
{
public class EntityComponentMap
{
private HashSet<int>[] components;
public EntityComponentMap(int capacity)
{
components = new HashSet<int>[capacity];
}
public void Add(Entity entity, int componentType)
{
ArrayUtil.EnsureLength(ref components, entity.Index + 1);
if (components[entity.Index] == null)
components[entity.Index] = new HashSet<int>();
components[entity.Index].Add(componentType);
}
public void Remove(Entity entity, int componentType)
{
components[entity.Index].Remove(componentType);
}
public void RemoveAll(Entity entity)
{
components[entity.Index].Clear();
}
public HashSet<int> Get(Entity entity) => components[entity.Index];
public ArrayRef<HashSet<int>> Read() => new ArrayRef<HashSet<int>>(components, 0, components.Length);
}
}