49 lines
1.5 KiB
C#
49 lines
1.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Immutable;
|
|
|
|
namespace Encompass
|
|
{
|
|
public struct EntitySetQuery : IEnumerable<Entity>
|
|
{
|
|
private EntitySetQuery(ComponentManager componentManager, ImmutableArray<Type> includes, ImmutableArray<Type> excludes)
|
|
{
|
|
ComponentManager = componentManager;
|
|
Includes = includes;
|
|
Excludes = excludes;
|
|
}
|
|
|
|
internal EntitySetQuery(ComponentManager componentManager)
|
|
{
|
|
ComponentManager = componentManager;
|
|
Includes = ImmutableArray.Create<Type>();
|
|
Excludes = ImmutableArray.Create<Type>();
|
|
}
|
|
|
|
private ComponentManager ComponentManager { get; }
|
|
private ImmutableArray<Type> Includes { get; }
|
|
private ImmutableArray<Type> Excludes { get; }
|
|
|
|
public EntitySetQuery With<TComponent>() where TComponent : struct, IComponent
|
|
{
|
|
return new EntitySetQuery(ComponentManager, Includes.Add(typeof(TComponent)), Excludes);
|
|
}
|
|
|
|
public EntitySetQuery Without<TComponent>() where TComponent : struct, IComponent
|
|
{
|
|
return new EntitySetQuery(ComponentManager, Includes, Excludes.Add(typeof(TComponent)));
|
|
}
|
|
|
|
public IEnumerator<Entity> GetEnumerator()
|
|
{
|
|
return ComponentManager.EntitiesWithComponents(Includes).GetEnumerator();
|
|
}
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
{
|
|
return GetEnumerator();
|
|
}
|
|
}
|
|
}
|