61 lines
1.6 KiB
C#
61 lines
1.6 KiB
C#
using Encompass.Collections;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Encompass
|
|
{
|
|
internal class ComponentBitSet
|
|
{
|
|
Dictionary<Entity, BitSet512> entities = new Dictionary<Entity, BitSet512>();
|
|
Dictionary<Type, int> TypeToIndex { get; }
|
|
|
|
public ComponentBitSet(Dictionary<Type, int> typeToIndex)
|
|
{
|
|
TypeToIndex = typeToIndex;
|
|
}
|
|
|
|
public void FinishRegistering()
|
|
{
|
|
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
entities.Clear();
|
|
}
|
|
|
|
public void AddEntity(Entity entity)
|
|
{
|
|
entities.Add(entity, BitSet512Builder.Zeroes());
|
|
}
|
|
|
|
public void Set<TComponent>(Entity entity) where TComponent : struct, IComponent
|
|
{
|
|
if (!entities.ContainsKey(entity)) { AddEntity(entity); }
|
|
entities[entity] = entities[entity].Set(TypeToIndex[typeof(TComponent)]);
|
|
}
|
|
|
|
public void RemoveComponent<TComponent>(Entity entity) where TComponent : struct, IComponent
|
|
{
|
|
if (entities.ContainsKey(entity))
|
|
{
|
|
entities[entity] = entities[entity].UnSet(TypeToIndex[typeof(TComponent)]);
|
|
}
|
|
}
|
|
|
|
public void RemoveEntity(Entity entity)
|
|
{
|
|
if (entities.ContainsKey(entity))
|
|
{
|
|
entities.Remove(entity);
|
|
}
|
|
}
|
|
|
|
public BitSet512 EntityBitArray(Entity entity)
|
|
{
|
|
return entities.ContainsKey(entity) ? entities[entity] : BitSet512Builder.Zeroes();
|
|
}
|
|
}
|
|
}
|