Changed the `Component` class to an interface `IComponentData` to support a data-oriented design. Changed the `Transform` class from a class to a struct, implementing `IComponentData` and updating properties. Changed the `GameObject` class to use a dictionary for components and added properties for state management. Changed the `PlayerLoopService` class to `GameLoopService` and updated methods to integrate with the new `SceneManager`. Changed the `World` class to manage multiple worlds and enhance entity management with new querying methods. Added the `Scene` class to manage root game objects and their lifecycle. Added new utility classes like `ComponentMask`, `Box<T>`, and `TypeHandle<T>` for better component management. Added the `ScriptComponent` class to allow for modular scriptable components attached to entities. Added the `QueryEnumerable` class to facilitate flexible querying of entities with specific components. Updated the `Test` class in `Program.cs` to demonstrate the new entity and component management system. Updated project files to include new references and settings supporting the changes made in the codebase.
1485 lines
53 KiB
C#
1485 lines
53 KiB
C#
|
|
|
|
using Ghost.Entities.Query;
|
|
using Ghost.Entities.Utilities;
|
|
using Misaki.HighPerformance.Unsafe.Collections;
|
|
|
|
namespace Ghost.Entities;
|
|
|
|
public struct QueryEnumerable<T0>
|
|
where T0 : struct, IComponentData
|
|
{
|
|
private readonly World _world;
|
|
|
|
private readonly ComponentPool<T0> _pool0;
|
|
private readonly int _count;
|
|
|
|
private QueryFilter _filters;
|
|
internal readonly QueryFilter Filters => _filters;
|
|
|
|
internal QueryEnumerable(World world, ComponentPool<T0> pool0, int count)
|
|
{
|
|
_world = world;
|
|
|
|
_pool0 = pool0;
|
|
|
|
_count = count;
|
|
|
|
_filters = new();
|
|
_filters._all.Add(TypeHandle<T0>.Value);
|
|
}
|
|
|
|
public Enumerator GetEnumerator() => new Enumerator(_world, _pool0, _count, _filters);
|
|
|
|
public ref struct Enumerator
|
|
{
|
|
private readonly World _world;
|
|
private readonly ReadOnlySpan<Entity> _entities;
|
|
|
|
private readonly ComponentPool<T0> _pool0;
|
|
|
|
private int _index;
|
|
private readonly int _count;
|
|
|
|
private BitSet _filterMask;
|
|
|
|
public QueryItem<T0> Current
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
internal Enumerator(World world, ComponentPool<T0> pool0, int count, QueryFilter filters)
|
|
{
|
|
_world = world;
|
|
_entities = _world.EntityManager.Entities;
|
|
|
|
_pool0 = pool0;
|
|
|
|
_count = count;
|
|
_index = -1;
|
|
filters.ComputeFilterBitMask(_world, ref _filterMask);
|
|
|
|
Current = default;
|
|
}
|
|
|
|
public bool MoveNext()
|
|
{
|
|
_index = _filterMask.NextSetBit(_index + 1);
|
|
if (_index < 0 || _index >= _world.EntityManager.EntityCount)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
Current = new QueryItem<T0>(_entities[_index], _pool0);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0> WithAll<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._all.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0> WithAny<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._any.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0> WithAbsent<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._absent.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0> WithDisabled<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._disabled.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0> WithAll<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._all.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._all.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0> WithAny<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._any.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._any.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0> WithAbsent<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._absent.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._absent.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0> WithDisabled<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._disabled.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._disabled.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0> WithAll<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._all.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._all.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._all.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0> WithAny<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._any.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._any.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._any.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0> WithAbsent<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._absent.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._absent.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._absent.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0> WithDisabled<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._disabled.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._disabled.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._disabled.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
}
|
|
|
|
public struct QueryEnumerable<T0, T1>
|
|
where T0 : struct, IComponentData where T1 : struct, IComponentData
|
|
{
|
|
private readonly World _world;
|
|
|
|
private readonly ComponentPool<T0> _pool0;
|
|
private readonly ComponentPool<T1> _pool1;
|
|
private readonly int _count;
|
|
|
|
private QueryFilter _filters;
|
|
internal readonly QueryFilter Filters => _filters;
|
|
|
|
internal QueryEnumerable(World world, ComponentPool<T0> pool0, ComponentPool<T1> pool1, int count)
|
|
{
|
|
_world = world;
|
|
|
|
_pool0 = pool0;
|
|
_pool1 = pool1;
|
|
|
|
_count = count;
|
|
|
|
_filters = new();
|
|
_filters._all.Add(TypeHandle<T0>.Value);
|
|
_filters._all.Add(TypeHandle<T1>.Value);
|
|
}
|
|
|
|
public Enumerator GetEnumerator() => new Enumerator(_world, _pool0, _pool1, _count, _filters);
|
|
|
|
public ref struct Enumerator
|
|
{
|
|
private readonly World _world;
|
|
private readonly ReadOnlySpan<Entity> _entities;
|
|
|
|
private readonly ComponentPool<T0> _pool0;
|
|
private readonly ComponentPool<T1> _pool1;
|
|
|
|
private int _index;
|
|
private readonly int _count;
|
|
|
|
private BitSet _filterMask;
|
|
|
|
public QueryItem<T0, T1> Current
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
internal Enumerator(World world, ComponentPool<T0> pool0, ComponentPool<T1> pool1, int count, QueryFilter filters)
|
|
{
|
|
_world = world;
|
|
_entities = _world.EntityManager.Entities;
|
|
|
|
_pool0 = pool0;
|
|
_pool1 = pool1;
|
|
|
|
_count = count;
|
|
_index = -1;
|
|
filters.ComputeFilterBitMask(_world, ref _filterMask);
|
|
|
|
Current = default;
|
|
}
|
|
|
|
public bool MoveNext()
|
|
{
|
|
_index = _filterMask.NextSetBit(_index + 1);
|
|
if (_index < 0 || _index >= _world.EntityManager.EntityCount)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
Current = new QueryItem<T0, T1>(_entities[_index], _pool0, _pool1);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1> WithAll<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._all.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1> WithAny<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._any.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1> WithAbsent<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._absent.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1> WithDisabled<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._disabled.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1> WithAll<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._all.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._all.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1> WithAny<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._any.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._any.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1> WithAbsent<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._absent.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._absent.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1> WithDisabled<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._disabled.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._disabled.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1> WithAll<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._all.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._all.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._all.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1> WithAny<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._any.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._any.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._any.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1> WithAbsent<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._absent.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._absent.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._absent.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1> WithDisabled<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._disabled.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._disabled.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._disabled.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
}
|
|
|
|
public struct QueryEnumerable<T0, T1, T2>
|
|
where T0 : struct, IComponentData where T1 : struct, IComponentData where T2 : struct, IComponentData
|
|
{
|
|
private readonly World _world;
|
|
|
|
private readonly ComponentPool<T0> _pool0;
|
|
private readonly ComponentPool<T1> _pool1;
|
|
private readonly ComponentPool<T2> _pool2;
|
|
private readonly int _count;
|
|
|
|
private QueryFilter _filters;
|
|
internal readonly QueryFilter Filters => _filters;
|
|
|
|
internal QueryEnumerable(World world, ComponentPool<T0> pool0, ComponentPool<T1> pool1, ComponentPool<T2> pool2, int count)
|
|
{
|
|
_world = world;
|
|
|
|
_pool0 = pool0;
|
|
_pool1 = pool1;
|
|
_pool2 = pool2;
|
|
|
|
_count = count;
|
|
|
|
_filters = new();
|
|
_filters._all.Add(TypeHandle<T0>.Value);
|
|
_filters._all.Add(TypeHandle<T1>.Value);
|
|
_filters._all.Add(TypeHandle<T2>.Value);
|
|
}
|
|
|
|
public Enumerator GetEnumerator() => new Enumerator(_world, _pool0, _pool1, _pool2, _count, _filters);
|
|
|
|
public ref struct Enumerator
|
|
{
|
|
private readonly World _world;
|
|
private readonly ReadOnlySpan<Entity> _entities;
|
|
|
|
private readonly ComponentPool<T0> _pool0;
|
|
private readonly ComponentPool<T1> _pool1;
|
|
private readonly ComponentPool<T2> _pool2;
|
|
|
|
private int _index;
|
|
private readonly int _count;
|
|
|
|
private BitSet _filterMask;
|
|
|
|
public QueryItem<T0, T1, T2> Current
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
internal Enumerator(World world, ComponentPool<T0> pool0, ComponentPool<T1> pool1, ComponentPool<T2> pool2, int count, QueryFilter filters)
|
|
{
|
|
_world = world;
|
|
_entities = _world.EntityManager.Entities;
|
|
|
|
_pool0 = pool0;
|
|
_pool1 = pool1;
|
|
_pool2 = pool2;
|
|
|
|
_count = count;
|
|
_index = -1;
|
|
filters.ComputeFilterBitMask(_world, ref _filterMask);
|
|
|
|
Current = default;
|
|
}
|
|
|
|
public bool MoveNext()
|
|
{
|
|
_index = _filterMask.NextSetBit(_index + 1);
|
|
if (_index < 0 || _index >= _world.EntityManager.EntityCount)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
Current = new QueryItem<T0, T1, T2>(_entities[_index], _pool0, _pool1, _pool2);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2> WithAll<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._all.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2> WithAny<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._any.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2> WithAbsent<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._absent.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2> WithDisabled<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._disabled.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2> WithAll<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._all.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._all.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2> WithAny<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._any.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._any.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2> WithAbsent<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._absent.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._absent.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2> WithDisabled<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._disabled.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._disabled.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2> WithAll<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._all.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._all.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._all.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2> WithAny<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._any.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._any.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._any.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2> WithAbsent<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._absent.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._absent.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._absent.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2> WithDisabled<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._disabled.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._disabled.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._disabled.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
}
|
|
|
|
public struct QueryEnumerable<T0, T1, T2, T3>
|
|
where T0 : struct, IComponentData where T1 : struct, IComponentData where T2 : struct, IComponentData where T3 : struct, IComponentData
|
|
{
|
|
private readonly World _world;
|
|
|
|
private readonly ComponentPool<T0> _pool0;
|
|
private readonly ComponentPool<T1> _pool1;
|
|
private readonly ComponentPool<T2> _pool2;
|
|
private readonly ComponentPool<T3> _pool3;
|
|
private readonly int _count;
|
|
|
|
private QueryFilter _filters;
|
|
internal readonly QueryFilter Filters => _filters;
|
|
|
|
internal QueryEnumerable(World world, ComponentPool<T0> pool0, ComponentPool<T1> pool1, ComponentPool<T2> pool2, ComponentPool<T3> pool3, int count)
|
|
{
|
|
_world = world;
|
|
|
|
_pool0 = pool0;
|
|
_pool1 = pool1;
|
|
_pool2 = pool2;
|
|
_pool3 = pool3;
|
|
|
|
_count = count;
|
|
|
|
_filters = new();
|
|
_filters._all.Add(TypeHandle<T0>.Value);
|
|
_filters._all.Add(TypeHandle<T1>.Value);
|
|
_filters._all.Add(TypeHandle<T2>.Value);
|
|
_filters._all.Add(TypeHandle<T3>.Value);
|
|
}
|
|
|
|
public Enumerator GetEnumerator() => new Enumerator(_world, _pool0, _pool1, _pool2, _pool3, _count, _filters);
|
|
|
|
public ref struct Enumerator
|
|
{
|
|
private readonly World _world;
|
|
private readonly ReadOnlySpan<Entity> _entities;
|
|
|
|
private readonly ComponentPool<T0> _pool0;
|
|
private readonly ComponentPool<T1> _pool1;
|
|
private readonly ComponentPool<T2> _pool2;
|
|
private readonly ComponentPool<T3> _pool3;
|
|
|
|
private int _index;
|
|
private readonly int _count;
|
|
|
|
private BitSet _filterMask;
|
|
|
|
public QueryItem<T0, T1, T2, T3> Current
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
internal Enumerator(World world, ComponentPool<T0> pool0, ComponentPool<T1> pool1, ComponentPool<T2> pool2, ComponentPool<T3> pool3, int count, QueryFilter filters)
|
|
{
|
|
_world = world;
|
|
_entities = _world.EntityManager.Entities;
|
|
|
|
_pool0 = pool0;
|
|
_pool1 = pool1;
|
|
_pool2 = pool2;
|
|
_pool3 = pool3;
|
|
|
|
_count = count;
|
|
_index = -1;
|
|
filters.ComputeFilterBitMask(_world, ref _filterMask);
|
|
|
|
Current = default;
|
|
}
|
|
|
|
public bool MoveNext()
|
|
{
|
|
_index = _filterMask.NextSetBit(_index + 1);
|
|
if (_index < 0 || _index >= _world.EntityManager.EntityCount)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
Current = new QueryItem<T0, T1, T2, T3>(_entities[_index], _pool0, _pool1, _pool2, _pool3);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3> WithAll<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._all.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3> WithAny<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._any.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3> WithAbsent<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._absent.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3> WithDisabled<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._disabled.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3> WithAll<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._all.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._all.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3> WithAny<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._any.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._any.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3> WithAbsent<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._absent.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._absent.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3> WithDisabled<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._disabled.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._disabled.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3> WithAll<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._all.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._all.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._all.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3> WithAny<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._any.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._any.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._any.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3> WithAbsent<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._absent.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._absent.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._absent.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3> WithDisabled<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._disabled.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._disabled.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._disabled.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
}
|
|
|
|
public struct QueryEnumerable<T0, T1, T2, T3, T4>
|
|
where T0 : struct, IComponentData where T1 : struct, IComponentData where T2 : struct, IComponentData where T3 : struct, IComponentData where T4 : struct, IComponentData
|
|
{
|
|
private readonly World _world;
|
|
|
|
private readonly ComponentPool<T0> _pool0;
|
|
private readonly ComponentPool<T1> _pool1;
|
|
private readonly ComponentPool<T2> _pool2;
|
|
private readonly ComponentPool<T3> _pool3;
|
|
private readonly ComponentPool<T4> _pool4;
|
|
private readonly int _count;
|
|
|
|
private QueryFilter _filters;
|
|
internal readonly QueryFilter Filters => _filters;
|
|
|
|
internal QueryEnumerable(World world, ComponentPool<T0> pool0, ComponentPool<T1> pool1, ComponentPool<T2> pool2, ComponentPool<T3> pool3, ComponentPool<T4> pool4, int count)
|
|
{
|
|
_world = world;
|
|
|
|
_pool0 = pool0;
|
|
_pool1 = pool1;
|
|
_pool2 = pool2;
|
|
_pool3 = pool3;
|
|
_pool4 = pool4;
|
|
|
|
_count = count;
|
|
|
|
_filters = new();
|
|
_filters._all.Add(TypeHandle<T0>.Value);
|
|
_filters._all.Add(TypeHandle<T1>.Value);
|
|
_filters._all.Add(TypeHandle<T2>.Value);
|
|
_filters._all.Add(TypeHandle<T3>.Value);
|
|
_filters._all.Add(TypeHandle<T4>.Value);
|
|
}
|
|
|
|
public Enumerator GetEnumerator() => new Enumerator(_world, _pool0, _pool1, _pool2, _pool3, _pool4, _count, _filters);
|
|
|
|
public ref struct Enumerator
|
|
{
|
|
private readonly World _world;
|
|
private readonly ReadOnlySpan<Entity> _entities;
|
|
|
|
private readonly ComponentPool<T0> _pool0;
|
|
private readonly ComponentPool<T1> _pool1;
|
|
private readonly ComponentPool<T2> _pool2;
|
|
private readonly ComponentPool<T3> _pool3;
|
|
private readonly ComponentPool<T4> _pool4;
|
|
|
|
private int _index;
|
|
private readonly int _count;
|
|
|
|
private BitSet _filterMask;
|
|
|
|
public QueryItem<T0, T1, T2, T3, T4> Current
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
internal Enumerator(World world, ComponentPool<T0> pool0, ComponentPool<T1> pool1, ComponentPool<T2> pool2, ComponentPool<T3> pool3, ComponentPool<T4> pool4, int count, QueryFilter filters)
|
|
{
|
|
_world = world;
|
|
_entities = _world.EntityManager.Entities;
|
|
|
|
_pool0 = pool0;
|
|
_pool1 = pool1;
|
|
_pool2 = pool2;
|
|
_pool3 = pool3;
|
|
_pool4 = pool4;
|
|
|
|
_count = count;
|
|
_index = -1;
|
|
filters.ComputeFilterBitMask(_world, ref _filterMask);
|
|
|
|
Current = default;
|
|
}
|
|
|
|
public bool MoveNext()
|
|
{
|
|
_index = _filterMask.NextSetBit(_index + 1);
|
|
if (_index < 0 || _index >= _world.EntityManager.EntityCount)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
Current = new QueryItem<T0, T1, T2, T3, T4>(_entities[_index], _pool0, _pool1, _pool2, _pool3, _pool4);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4> WithAll<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._all.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4> WithAny<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._any.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4> WithAbsent<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._absent.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4> WithDisabled<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._disabled.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4> WithAll<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._all.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._all.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4> WithAny<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._any.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._any.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4> WithAbsent<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._absent.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._absent.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4> WithDisabled<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._disabled.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._disabled.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4> WithAll<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._all.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._all.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._all.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4> WithAny<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._any.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._any.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._any.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4> WithAbsent<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._absent.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._absent.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._absent.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4> WithDisabled<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._disabled.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._disabled.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._disabled.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
}
|
|
|
|
public struct QueryEnumerable<T0, T1, T2, T3, T4, T5>
|
|
where T0 : struct, IComponentData where T1 : struct, IComponentData where T2 : struct, IComponentData where T3 : struct, IComponentData where T4 : struct, IComponentData where T5 : struct, IComponentData
|
|
{
|
|
private readonly World _world;
|
|
|
|
private readonly ComponentPool<T0> _pool0;
|
|
private readonly ComponentPool<T1> _pool1;
|
|
private readonly ComponentPool<T2> _pool2;
|
|
private readonly ComponentPool<T3> _pool3;
|
|
private readonly ComponentPool<T4> _pool4;
|
|
private readonly ComponentPool<T5> _pool5;
|
|
private readonly int _count;
|
|
|
|
private QueryFilter _filters;
|
|
internal readonly QueryFilter Filters => _filters;
|
|
|
|
internal QueryEnumerable(World world, ComponentPool<T0> pool0, ComponentPool<T1> pool1, ComponentPool<T2> pool2, ComponentPool<T3> pool3, ComponentPool<T4> pool4, ComponentPool<T5> pool5, int count)
|
|
{
|
|
_world = world;
|
|
|
|
_pool0 = pool0;
|
|
_pool1 = pool1;
|
|
_pool2 = pool2;
|
|
_pool3 = pool3;
|
|
_pool4 = pool4;
|
|
_pool5 = pool5;
|
|
|
|
_count = count;
|
|
|
|
_filters = new();
|
|
_filters._all.Add(TypeHandle<T0>.Value);
|
|
_filters._all.Add(TypeHandle<T1>.Value);
|
|
_filters._all.Add(TypeHandle<T2>.Value);
|
|
_filters._all.Add(TypeHandle<T3>.Value);
|
|
_filters._all.Add(TypeHandle<T4>.Value);
|
|
_filters._all.Add(TypeHandle<T5>.Value);
|
|
}
|
|
|
|
public Enumerator GetEnumerator() => new Enumerator(_world, _pool0, _pool1, _pool2, _pool3, _pool4, _pool5, _count, _filters);
|
|
|
|
public ref struct Enumerator
|
|
{
|
|
private readonly World _world;
|
|
private readonly ReadOnlySpan<Entity> _entities;
|
|
|
|
private readonly ComponentPool<T0> _pool0;
|
|
private readonly ComponentPool<T1> _pool1;
|
|
private readonly ComponentPool<T2> _pool2;
|
|
private readonly ComponentPool<T3> _pool3;
|
|
private readonly ComponentPool<T4> _pool4;
|
|
private readonly ComponentPool<T5> _pool5;
|
|
|
|
private int _index;
|
|
private readonly int _count;
|
|
|
|
private BitSet _filterMask;
|
|
|
|
public QueryItem<T0, T1, T2, T3, T4, T5> Current
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
internal Enumerator(World world, ComponentPool<T0> pool0, ComponentPool<T1> pool1, ComponentPool<T2> pool2, ComponentPool<T3> pool3, ComponentPool<T4> pool4, ComponentPool<T5> pool5, int count, QueryFilter filters)
|
|
{
|
|
_world = world;
|
|
_entities = _world.EntityManager.Entities;
|
|
|
|
_pool0 = pool0;
|
|
_pool1 = pool1;
|
|
_pool2 = pool2;
|
|
_pool3 = pool3;
|
|
_pool4 = pool4;
|
|
_pool5 = pool5;
|
|
|
|
_count = count;
|
|
_index = -1;
|
|
filters.ComputeFilterBitMask(_world, ref _filterMask);
|
|
|
|
Current = default;
|
|
}
|
|
|
|
public bool MoveNext()
|
|
{
|
|
_index = _filterMask.NextSetBit(_index + 1);
|
|
if (_index < 0 || _index >= _world.EntityManager.EntityCount)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
Current = new QueryItem<T0, T1, T2, T3, T4, T5>(_entities[_index], _pool0, _pool1, _pool2, _pool3, _pool4, _pool5);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5> WithAll<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._all.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5> WithAny<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._any.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5> WithAbsent<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._absent.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5> WithDisabled<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._disabled.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5> WithAll<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._all.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._all.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5> WithAny<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._any.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._any.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5> WithAbsent<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._absent.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._absent.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5> WithDisabled<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._disabled.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._disabled.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5> WithAll<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._all.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._all.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._all.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5> WithAny<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._any.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._any.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._any.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5> WithAbsent<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._absent.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._absent.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._absent.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5> WithDisabled<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._disabled.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._disabled.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._disabled.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
}
|
|
|
|
public struct QueryEnumerable<T0, T1, T2, T3, T4, T5, T6>
|
|
where T0 : struct, IComponentData where T1 : struct, IComponentData where T2 : struct, IComponentData where T3 : struct, IComponentData where T4 : struct, IComponentData where T5 : struct, IComponentData where T6 : struct, IComponentData
|
|
{
|
|
private readonly World _world;
|
|
|
|
private readonly ComponentPool<T0> _pool0;
|
|
private readonly ComponentPool<T1> _pool1;
|
|
private readonly ComponentPool<T2> _pool2;
|
|
private readonly ComponentPool<T3> _pool3;
|
|
private readonly ComponentPool<T4> _pool4;
|
|
private readonly ComponentPool<T5> _pool5;
|
|
private readonly ComponentPool<T6> _pool6;
|
|
private readonly int _count;
|
|
|
|
private QueryFilter _filters;
|
|
internal readonly QueryFilter Filters => _filters;
|
|
|
|
internal QueryEnumerable(World world, ComponentPool<T0> pool0, ComponentPool<T1> pool1, ComponentPool<T2> pool2, ComponentPool<T3> pool3, ComponentPool<T4> pool4, ComponentPool<T5> pool5, ComponentPool<T6> pool6, int count)
|
|
{
|
|
_world = world;
|
|
|
|
_pool0 = pool0;
|
|
_pool1 = pool1;
|
|
_pool2 = pool2;
|
|
_pool3 = pool3;
|
|
_pool4 = pool4;
|
|
_pool5 = pool5;
|
|
_pool6 = pool6;
|
|
|
|
_count = count;
|
|
|
|
_filters = new();
|
|
_filters._all.Add(TypeHandle<T0>.Value);
|
|
_filters._all.Add(TypeHandle<T1>.Value);
|
|
_filters._all.Add(TypeHandle<T2>.Value);
|
|
_filters._all.Add(TypeHandle<T3>.Value);
|
|
_filters._all.Add(TypeHandle<T4>.Value);
|
|
_filters._all.Add(TypeHandle<T5>.Value);
|
|
_filters._all.Add(TypeHandle<T6>.Value);
|
|
}
|
|
|
|
public Enumerator GetEnumerator() => new Enumerator(_world, _pool0, _pool1, _pool2, _pool3, _pool4, _pool5, _pool6, _count, _filters);
|
|
|
|
public ref struct Enumerator
|
|
{
|
|
private readonly World _world;
|
|
private readonly ReadOnlySpan<Entity> _entities;
|
|
|
|
private readonly ComponentPool<T0> _pool0;
|
|
private readonly ComponentPool<T1> _pool1;
|
|
private readonly ComponentPool<T2> _pool2;
|
|
private readonly ComponentPool<T3> _pool3;
|
|
private readonly ComponentPool<T4> _pool4;
|
|
private readonly ComponentPool<T5> _pool5;
|
|
private readonly ComponentPool<T6> _pool6;
|
|
|
|
private int _index;
|
|
private readonly int _count;
|
|
|
|
private BitSet _filterMask;
|
|
|
|
public QueryItem<T0, T1, T2, T3, T4, T5, T6> Current
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
internal Enumerator(World world, ComponentPool<T0> pool0, ComponentPool<T1> pool1, ComponentPool<T2> pool2, ComponentPool<T3> pool3, ComponentPool<T4> pool4, ComponentPool<T5> pool5, ComponentPool<T6> pool6, int count, QueryFilter filters)
|
|
{
|
|
_world = world;
|
|
_entities = _world.EntityManager.Entities;
|
|
|
|
_pool0 = pool0;
|
|
_pool1 = pool1;
|
|
_pool2 = pool2;
|
|
_pool3 = pool3;
|
|
_pool4 = pool4;
|
|
_pool5 = pool5;
|
|
_pool6 = pool6;
|
|
|
|
_count = count;
|
|
_index = -1;
|
|
filters.ComputeFilterBitMask(_world, ref _filterMask);
|
|
|
|
Current = default;
|
|
}
|
|
|
|
public bool MoveNext()
|
|
{
|
|
_index = _filterMask.NextSetBit(_index + 1);
|
|
if (_index < 0 || _index >= _world.EntityManager.EntityCount)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
Current = new QueryItem<T0, T1, T2, T3, T4, T5, T6>(_entities[_index], _pool0, _pool1, _pool2, _pool3, _pool4, _pool5, _pool6);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5, T6> WithAll<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._all.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5, T6> WithAny<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._any.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5, T6> WithAbsent<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._absent.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5, T6> WithDisabled<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._disabled.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5, T6> WithAll<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._all.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._all.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5, T6> WithAny<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._any.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._any.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5, T6> WithAbsent<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._absent.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._absent.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5, T6> WithDisabled<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._disabled.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._disabled.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5, T6> WithAll<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._all.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._all.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._all.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5, T6> WithAny<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._any.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._any.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._any.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5, T6> WithAbsent<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._absent.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._absent.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._absent.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5, T6> WithDisabled<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._disabled.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._disabled.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._disabled.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
}
|
|
|
|
public struct QueryEnumerable<T0, T1, T2, T3, T4, T5, T6, T7>
|
|
where T0 : struct, IComponentData where T1 : struct, IComponentData where T2 : struct, IComponentData where T3 : struct, IComponentData where T4 : struct, IComponentData where T5 : struct, IComponentData where T6 : struct, IComponentData where T7 : struct, IComponentData
|
|
{
|
|
private readonly World _world;
|
|
|
|
private readonly ComponentPool<T0> _pool0;
|
|
private readonly ComponentPool<T1> _pool1;
|
|
private readonly ComponentPool<T2> _pool2;
|
|
private readonly ComponentPool<T3> _pool3;
|
|
private readonly ComponentPool<T4> _pool4;
|
|
private readonly ComponentPool<T5> _pool5;
|
|
private readonly ComponentPool<T6> _pool6;
|
|
private readonly ComponentPool<T7> _pool7;
|
|
private readonly int _count;
|
|
|
|
private QueryFilter _filters;
|
|
internal readonly QueryFilter Filters => _filters;
|
|
|
|
internal QueryEnumerable(World world, ComponentPool<T0> pool0, ComponentPool<T1> pool1, ComponentPool<T2> pool2, ComponentPool<T3> pool3, ComponentPool<T4> pool4, ComponentPool<T5> pool5, ComponentPool<T6> pool6, ComponentPool<T7> pool7, int count)
|
|
{
|
|
_world = world;
|
|
|
|
_pool0 = pool0;
|
|
_pool1 = pool1;
|
|
_pool2 = pool2;
|
|
_pool3 = pool3;
|
|
_pool4 = pool4;
|
|
_pool5 = pool5;
|
|
_pool6 = pool6;
|
|
_pool7 = pool7;
|
|
|
|
_count = count;
|
|
|
|
_filters = new();
|
|
_filters._all.Add(TypeHandle<T0>.Value);
|
|
_filters._all.Add(TypeHandle<T1>.Value);
|
|
_filters._all.Add(TypeHandle<T2>.Value);
|
|
_filters._all.Add(TypeHandle<T3>.Value);
|
|
_filters._all.Add(TypeHandle<T4>.Value);
|
|
_filters._all.Add(TypeHandle<T5>.Value);
|
|
_filters._all.Add(TypeHandle<T6>.Value);
|
|
_filters._all.Add(TypeHandle<T7>.Value);
|
|
}
|
|
|
|
public Enumerator GetEnumerator() => new Enumerator(_world, _pool0, _pool1, _pool2, _pool3, _pool4, _pool5, _pool6, _pool7, _count, _filters);
|
|
|
|
public ref struct Enumerator
|
|
{
|
|
private readonly World _world;
|
|
private readonly ReadOnlySpan<Entity> _entities;
|
|
|
|
private readonly ComponentPool<T0> _pool0;
|
|
private readonly ComponentPool<T1> _pool1;
|
|
private readonly ComponentPool<T2> _pool2;
|
|
private readonly ComponentPool<T3> _pool3;
|
|
private readonly ComponentPool<T4> _pool4;
|
|
private readonly ComponentPool<T5> _pool5;
|
|
private readonly ComponentPool<T6> _pool6;
|
|
private readonly ComponentPool<T7> _pool7;
|
|
|
|
private int _index;
|
|
private readonly int _count;
|
|
|
|
private BitSet _filterMask;
|
|
|
|
public QueryItem<T0, T1, T2, T3, T4, T5, T6, T7> Current
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
internal Enumerator(World world, ComponentPool<T0> pool0, ComponentPool<T1> pool1, ComponentPool<T2> pool2, ComponentPool<T3> pool3, ComponentPool<T4> pool4, ComponentPool<T5> pool5, ComponentPool<T6> pool6, ComponentPool<T7> pool7, int count, QueryFilter filters)
|
|
{
|
|
_world = world;
|
|
_entities = _world.EntityManager.Entities;
|
|
|
|
_pool0 = pool0;
|
|
_pool1 = pool1;
|
|
_pool2 = pool2;
|
|
_pool3 = pool3;
|
|
_pool4 = pool4;
|
|
_pool5 = pool5;
|
|
_pool6 = pool6;
|
|
_pool7 = pool7;
|
|
|
|
_count = count;
|
|
_index = -1;
|
|
filters.ComputeFilterBitMask(_world, ref _filterMask);
|
|
|
|
Current = default;
|
|
}
|
|
|
|
public bool MoveNext()
|
|
{
|
|
_index = _filterMask.NextSetBit(_index + 1);
|
|
if (_index < 0 || _index >= _world.EntityManager.EntityCount)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
Current = new QueryItem<T0, T1, T2, T3, T4, T5, T6, T7>(_entities[_index], _pool0, _pool1, _pool2, _pool3, _pool4, _pool5, _pool6, _pool7);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5, T6, T7> WithAll<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._all.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5, T6, T7> WithAny<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._any.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5, T6, T7> WithAbsent<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._absent.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5, T6, T7> WithDisabled<TComponent0>()
|
|
where TComponent0 : struct, IComponentData
|
|
{
|
|
_filters._disabled.Add(TypeHandle<TComponent0>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5, T6, T7> WithAll<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._all.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._all.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5, T6, T7> WithAny<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._any.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._any.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5, T6, T7> WithAbsent<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._absent.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._absent.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5, T6, T7> WithDisabled<TComponent0, TComponent1>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData
|
|
{
|
|
_filters._disabled.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._disabled.Add(TypeHandle<TComponent1>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5, T6, T7> WithAll<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._all.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._all.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._all.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5, T6, T7> WithAny<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._any.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._any.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._any.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5, T6, T7> WithAbsent<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._absent.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._absent.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._absent.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
|
|
public readonly QueryEnumerable<T0, T1, T2, T3, T4, T5, T6, T7> WithDisabled<TComponent0, TComponent1, TComponent2>()
|
|
where TComponent0 : struct, IComponentData where TComponent1 : struct, IComponentData where TComponent2 : struct, IComponentData
|
|
{
|
|
_filters._disabled.Add(TypeHandle<TComponent0>.Value);
|
|
_filters._disabled.Add(TypeHandle<TComponent1>.Value);
|
|
_filters._disabled.Add(TypeHandle<TComponent2>.Value);
|
|
return this;
|
|
}
|
|
}
|
|
|