Refactor entity-component system and related classes

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.
This commit is contained in:
2025-05-28 15:21:43 +09:00
parent 0cf3104a6a
commit 67b6040b5e
31 changed files with 3670 additions and 811 deletions

View File

@@ -1,24 +0,0 @@
namespace Ghost.Engine;
public abstract class Component
{
public virtual void Start()
{
}
public virtual void Update()
{
}
public virtual void LateUpdate()
{
}
public virtual void FixedUpdate()
{
}
public virtual void OnDestroy()
{
}
}

View File

@@ -1,12 +1,14 @@
using Ghost.Engine.Helpers;
using Ghost.Entities;
using System.Numerics;
using System.Runtime.CompilerServices;
namespace Ghost.Engine.Components;
public class Transform : Component
public struct Transform : IComponentData
{
private Vector3 _position = Vector3.Zero;
public Vector3 position
public Vector3 Position
{
get => _position;
set
@@ -41,22 +43,35 @@ public class Transform : Component
}
}
public bool hasChanged = true;
public bool hasChanged;
private Matrix4x4 _localToWorldMatrix = Matrix4x4.Identity;
private Matrix4x4 _worldToLocalMatrix = Matrix4x4.Identity;
private Matrix4x4 _localToWorldMatrix;
private Matrix4x4 _worldToLocalMatrix;
public Matrix4x4 LocalToWorldMatrix => _localToWorldMatrix;
public Matrix4x4 WorldToLocalMatrix => _worldToLocalMatrix;
public readonly Matrix4x4 LocalToWorldMatrix => _localToWorldMatrix;
public readonly Matrix4x4 WorldToLocalMatrix => _worldToLocalMatrix;
public static Transform Default
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => new(Vector3.Zero, Quaternion.Identity, Vector3.One);
}
public Transform(Vector3 position, Quaternion rotation, Vector3 scale)
{
_position = position;
_rotation = rotation;
_scale = scale;
hasChanged = false;
_localToWorldMatrix = Matrix4x4.Identity;
_worldToLocalMatrix = Matrix4x4.Identity;
UpdateMatrices();
}
private void UpdateMatrices()
{
_localToWorldMatrix = MatrixHelpers.CreateTRS(_position, _rotation, _scale);
Matrix4x4.Invert(_localToWorldMatrix, out _worldToLocalMatrix);
}
public override void Start()
{
UpdateMatrices();
}
}

View File

@@ -1,96 +1,190 @@
using Ghost.Engine.Components;
using Ghost.Engine.Services;
using System.Collections.ObjectModel;
using Ghost.Engine.Models;
using Ghost.Entities;
using System.ComponentModel;
namespace Ghost.Engine;
public class GameObject
public unsafe class GameObject : INotifyPropertyChanged
{
private readonly ObservableCollection<Component> _components = new();
private readonly Dictionary<Type, ScriptComponent> _components = new();
private readonly List<GameObject> _children = new();
public string name = string.Empty;
public bool isActive = true;
public event PropertyChangedEventHandler? PropertyChanged;
public Transform Transform { get; } = new();
private GameObject()
public Entity Entity
{
AddComponent(Transform);
get;
}
public static GameObject Create(string name = "")
public Scene Scene
{
var gameObject = new GameObject
{
name = name
};
GameLoopService.RegisterGameObject(gameObject);
return gameObject;
get;
internal set;
}
public void AddComponent(Component component)
public GameObject? Parent
{
_components.Add(component);
get;
internal set;
}
public void RemoveComponent(Component component)
public string Name
{
_components.Remove(component);
get;
set;
}
public T? GetComponent<T>() where T : Component
public bool IsActive
{
foreach (var component in _components)
{
if (component is T t)
{
return t;
get;
set;
}
public IEnumerable<ScriptComponent> Components => _components.Values;
public IEnumerable<GameObject> Children => _children;
public GameObject(Scene scene, string name)
{
// TODO: Initialize Entity properly
//Entity =
Scene = scene;
Name = name;
IsActive = true;
}
public void AddComponent<T>(T component)
where T : ScriptComponent
{
_components.Add(typeof(T), component);
component.Owner = Entity;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Components)));
}
public void RemoveComponent<T>()
where T : ScriptComponent
{
var key = typeof(T);
if (_components.Remove(key, out var component))
{
component.OnDestroy();
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Components)));
}
}
public T? GetComponent<T>()
where T : ScriptComponent
{
if (_components.TryGetValue(typeof(T), out var component))
{
return (T)component;
}
return null;
}
public void AddChild(GameObject child)
{
if (child.Scene != Scene)
{
throw new InvalidOperationException("Child GameObject must belong to the same Scene.");
}
_children.Add(child);
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Children)));
}
public void RemoveChild(GameObject child)
{
if (_children.Remove(child))
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Children)));
}
}
internal void OnEnable()
{
foreach (var component in Components)
{
if (!component.Enable)
{
continue;
}
component.OnEnable();
}
foreach (var child in _children)
{
child.OnEnable();
}
}
internal void Start()
{
foreach (var component in _components)
foreach (var component in Components)
{
if (!component.Enable)
{
continue;
}
component.Start();
}
}
internal void Update()
{
foreach (var component in _components)
foreach (var component in Components)
{
if (!component.Enable)
{
continue;
}
component.Update();
}
}
internal void LateUpdate()
{
foreach (var component in _components)
foreach (var component in Components)
{
if (!component.Enable)
{
continue;
}
component.LateUpdate();
}
}
internal void FixedUpdate()
{
foreach (var component in _components)
foreach (var component in Components)
{
if (!component.Enable)
{
continue;
}
component.FixedUpdate();
}
}
public void Destroy()
{
foreach (var component in _components)
foreach (var component in Components)
{
if (!component.Enable)
{
continue;
}
component.OnDestroy();
}
GameLoopService.UnregisterGameObject(this);
foreach (var child in _children)
{
child.Destroy();
}
_children.Clear();
_components.Clear();
Parent?._children.Remove(this);
}
}

View File

@@ -4,6 +4,7 @@
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
@@ -14,4 +15,8 @@
<IsAotCompatible>True</IsAotCompatible>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Ghost.Entities\Ghost.Entities.csproj" />
</ItemGroup>
</Project>

View File

@@ -2,7 +2,29 @@
public class Scene
{
private readonly HashSet<GameObject> _rootObjects = new();
public IEnumerable<GameObject> RootObjects => _rootObjects;
internal Scene()
{
}
internal void Load()
{
foreach (var gameObject in _rootObjects)
{
gameObject.Start();
}
}
internal void Unload()
{
foreach (var gameObject in _rootObjects)
{
gameObject.Destroy();
}
_rootObjects.Clear();
}
}

View File

@@ -1,26 +1,13 @@

namespace Ghost.Engine.Services;
namespace Ghost.Engine.Services;
internal static class GameLoopService
internal static class PlayerLoopService
{
private readonly static HashSet<GameObject> _gameObjects = new();
private static Timer? _timer;
private static bool _isRunning = false;
// TODO: Implement the actual time system
public static float fixedDeltaTime = 0.02f;
public static void RegisterGameObject(GameObject gameObject)
{
_gameObjects.Add(gameObject);
}
public static void UnregisterGameObject(GameObject gameObject)
{
_gameObjects.Remove(gameObject);
}
public static void Start()
{
if (_isRunning)
@@ -28,13 +15,8 @@ internal static class GameLoopService
return;
}
foreach (var gameObject in _gameObjects)
foreach (var gameObject in SceneManager.QueryRootGameObjects())
{
if (!gameObject.isActive)
{
continue;
}
gameObject.Start();
}
@@ -48,27 +30,21 @@ internal static class GameLoopService
private static void Update()
{
foreach (var gameObject in _gameObjects)
foreach (var gameObject in SceneManager.QueryRootGameObjects())
{
if (!gameObject.isActive)
{
continue;
gameObject.Update();
}
gameObject.Update();
foreach (var gameObject in SceneManager.QueryRootGameObjects())
{
gameObject.LateUpdate();
}
}
private static void FixedUpdate(object? state)
{
foreach (var gameObject in _gameObjects)
foreach (var gameObject in SceneManager.QueryRootGameObjects())
{
if (!gameObject.isActive)
{
continue;
}
gameObject.FixedUpdate();
}
}

View File

@@ -0,0 +1,50 @@
using Ghost.Engine.Models;
namespace Ghost.Engine.Services;
public enum SceneLoadMode
{
Single,
Additive
}
public static class SceneManager
{
private readonly static HashSet<Scene> _activeScenes = new();
internal static IEnumerable<GameObject> QueryRootGameObjects()
{
foreach (var scene in _activeScenes)
{
foreach (var gameObject in scene.RootObjects)
{
if (!gameObject.IsActive)
{
continue;
}
yield return gameObject;
}
}
}
public static void LoadScene(Scene scene, SceneLoadMode loadMode)
{
if (loadMode == SceneLoadMode.Single)
{
foreach (var activeScene in _activeScenes)
{
activeScene.Unload();
}
_activeScenes.Clear();
}
_activeScenes.Add(scene);
scene.Load();
}
public static Task LoadSceneAsync(Scene scene, SceneLoadMode loadMode)
{
return Task.Run(() => LoadScene(scene, loadMode));
}
}

View File

@@ -5,3 +5,4 @@ global using WorldID = System.UInt16;
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Ghost.Engine")]
[assembly: InternalsVisibleTo("Ghost.Test")]

View File

@@ -1,12 +1,39 @@
namespace Ghost.Entities;
using Ghost.Entities.Utilities;
using Misaki.HighPerformance.Unsafe.Collections;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
public interface IComponent
namespace Ghost.Entities;
public interface IComponentData
{
}
internal class ComponentPool<T> : IDisposable
where T : struct, IComponent
internal static class SingletonContainer<T>
where T : struct, IComponentData
{
public static readonly Dictionary<int, T> container = new();
}
internal interface IComponentPool : IDisposable
{
public EntityID Count
{
get;
}
public void Remove(Entity entity);
public bool Has(Entity entity);
}
internal interface IComponentPool<T> : IComponentPool
{
public void Add(Entity entity, T Component);
}
internal class ComponentPool<T> : IComponentPool<T>
where T : struct, IComponentData
{
private struct ComponentData
{
@@ -20,6 +47,8 @@ internal class ComponentPool<T> : IDisposable
private ComponentData[] _components;
private EntityID[] _lookup;
public EntityID Count => _nextId;
public ComponentPool(int initialSize = 16)
{
_nextId = 0;
@@ -31,26 +60,34 @@ internal class ComponentPool<T> : IDisposable
_lookup.AsSpan().Fill(Entity.INVALID_ID);
}
public EntityID Count => _nextId;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static EntityID GetLookupIndex(Entity entity)
{
return entity.ID;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private EntityID GetComponentIndex(Entity entity)
{
return _lookup[entity.ID];
return _lookup[GetLookupIndex(entity)];
}
public void Add(Entity entity, T component)
{
if (entity.ID >= _lookup.Length)
if (!entity.IsValid)
{
_lookup.AsSpan(_nextId, entity.ID - _lookup.Length + 1).Fill(Entity.INVALID_ID);
return;
}
if (_lookup[entity.ID] != Entity.INVALID_ID)
var lookupIndex = GetLookupIndex(entity);
var componentIndex = GetComponentIndex(entity);
if (componentIndex != Entity.INVALID_ID)
{
// Overwrite the old data if generation is larger
if (entity.Generation > _components[_lookup[entity.ID]].owner.Generation)
if (entity.Generation > _components[componentIndex].owner.Generation)
{
var index = _lookup[entity.ID];
var index = _lookup[lookupIndex];
_components[index].data = component;
_components[index].owner = entity;
}
@@ -68,19 +105,29 @@ internal class ComponentPool<T> : IDisposable
_capacity = newCapacity;
}
_lookup[lookupIndex] = _nextId;
_components[_nextId] = new ComponentData
{
data = component,
owner = entity
};
_lookup[entity.ID] = _nextId;
_nextId++;
}
public void Remove(Entity entity)
{
}
public ref T GetRef(Entity entity)
{
return ref _components[_lookup[entity.ID]].data;
if (!entity.IsValid)
{
return ref Unsafe.NullRef<T>();
}
var index = GetComponentIndex(entity);
return ref _components[index].data;
}
public bool Has(Entity entity)
@@ -96,17 +143,235 @@ internal class ComponentPool<T> : IDisposable
public void Set(Entity entity, T component)
{
if (entity.ID >= _lookup.Length || _lookup[entity.ID] == Entity.INVALID_ID)
if (!entity.IsValid || entity.ID >= _lookup.Length || GetComponentIndex(entity) == Entity.INVALID_ID)
{
return;
}
var index = _lookup[entity.ID];
var index = GetComponentIndex(entity);
_components[index].data = component;
_components[index].owner = entity;
}
public void Dispose()
{
_components = Array.Empty<ComponentData>();
_lookup = Array.Empty<EntityID>();
_nextId = 0;
_capacity = 0;
}
}
internal class ScriptComponentPool : IComponentPool<ScriptComponent>
{
private Dictionary<Entity, List<ScriptComponent>>? _scriptComponents;
private List<ScriptComponent>? _executionList;
internal Dictionary<Entity, List<ScriptComponent>>? ScriptComponents => _scriptComponents;
internal List<ScriptComponent>? ExecutionList => _executionList;
public bool IsInitialized => _scriptComponents != null;
public int Count => _scriptComponents?.Keys.Count ?? 0;
internal void Initialize(int capacity = 16)
{
_scriptComponents ??= new(capacity);
}
internal void RebuildExecutionList()
{
if (_scriptComponents == null)
{
return;
}
_executionList ??= new List<ScriptComponent>(_scriptComponents.Count);
_executionList.Clear();
foreach (var kvp in _scriptComponents)
{
_executionList.AddRange(kvp.Value);
}
_executionList.Sort((a, b) => a.ExecutionOrder.CompareTo(b.ExecutionOrder));
}
public void Add(Entity entity, ScriptComponent component)
{
if (!IsInitialized)
{
Initialize();
}
if (!_scriptComponents!.TryGetValue(entity, out var scriptList))
{
scriptList = new();
_scriptComponents[entity] = scriptList;
}
scriptList.Add(component);
component.Owner = entity;
}
public void Remove(Entity entity)
{
if (!Has(entity)
|| !_scriptComponents!.TryGetValue(entity, out var scriptList)
|| scriptList == null)
{
return;
}
foreach (var script in scriptList)
{
script.OnDestroy();
}
_scriptComponents.Remove(entity);
}
public bool Has(Entity entity)
{
return _scriptComponents?.ContainsKey(entity) ?? false;
}
public List<ScriptComponent>? Get(Entity entity)
{
if (_scriptComponents == null
|| !_scriptComponents.TryGetValue(entity, out var scriptList))
{
return null;
}
return scriptList;
}
public void Dispose()
{
if (_scriptComponents != null)
{
if (_executionList != null)
{
foreach (var script in _executionList)
{
script.OnDestroy();
}
_executionList.Clear();
}
else
{
foreach (var scriptList in _scriptComponents.Values)
{
if (scriptList == null)
{
continue;
}
foreach (var script in scriptList)
{
script.OnDestroy();
}
}
}
_scriptComponents.Clear();
}
}
}
internal class ComponentStorage : IDisposable
{
private readonly Dictionary<nint, IComponentPool> _componentPools = new();
private readonly Dictionary<nint, BitSet> _componentEntityMasks = new();
private readonly ScriptComponentPool _scriptComponentPool = new();
internal Dictionary<nint, IComponentPool> ComponentPools => _componentPools;
internal ScriptComponentPool ScriptComponentPool => _scriptComponentPool;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool TryGetPool(nint typeHandle, [MaybeNullWhen(false)] out IComponentPool pool)
{
return _componentPools.TryGetValue(typeHandle, out pool);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool TryGetPool(Type type, [MaybeNullWhen(false)] out IComponentPool pool)
{
return TryGetPool(type.TypeHandle.Value, out pool);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool TryGetPool<T>([MaybeNullWhen(false)] out ComponentPool<T> pool)
where T : struct, IComponentData
{
var result = TryGetPool(TypeHandle<T>.Value, out var obj);
pool = (ComponentPool<T>?)obj;
return result;
}
public ComponentPool<T> GetOrCreateComponentPool<T>()
where T : struct, IComponentData
{
var key = TypeHandle<T>.Value;
if (!_componentPools.TryGetValue(key, out var obj))
{
var pool = new ComponentPool<T>();
_componentPools[key] = pool;
return pool;
}
return (ComponentPool<T>)obj;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool TryGetMask(nint typeHandle, [MaybeNullWhen(false)] out BitSet bitSet)
{
return _componentEntityMasks.TryGetValue(typeHandle, out bitSet);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool TryGetMask(Type type, [MaybeNullWhen(false)] out BitSet bitSet)
{
return TryGetMask(type.TypeHandle.Value, out bitSet);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool TryGetMask<T>([MaybeNullWhen(false)] out BitSet bitSet)
where T : struct, IComponentData
{
return TryGetMask(TypeHandle<T>.Value, out bitSet);
}
public BitSet GetOrCreateMask(nint typeHandle)
{
if (!_componentEntityMasks.TryGetValue(typeHandle, out var mask))
{
mask = new BitSet();
_componentEntityMasks[typeHandle] = mask;
}
return mask;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void RebuildExecutionList()
{
_scriptComponentPool.RebuildExecutionList();
}
public void Remove(Entity entity)
{
_scriptComponentPool.Remove(entity);
}
public void Dispose()
{
foreach (var pool in _componentPools.Values)
{
pool.Dispose();
}
_componentPools.Clear();
_scriptComponentPool.Dispose();
}
}

View File

@@ -1,17 +1,20 @@
using System.Runtime.CompilerServices;
using Ghost.Entities.Query;
using Ghost.Entities.Utilities;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Ghost.Entities;
[SkipLocalsInit]
public struct Entity : IEquatable<Entity>, IComparable<Entity>
{
private const int _WORLD_INDEX_BITS = 4;
private const int _GENERATION_BITS = 8;
private const int _INDEX_BITS = sizeof(EntityID) * 8 - _WORLD_INDEX_BITS - _GENERATION_BITS;
public const int WORLD_INDEX_BITS = 4;
public const int GENERATION_BITS = 8;
public const int INDEX_BITS = sizeof(EntityID) * 8 - WORLD_INDEX_BITS - GENERATION_BITS;
private const int _WORLD_INDEX_MASK = (1 << _WORLD_INDEX_BITS) - 1;
private const int _GENERATION_MASK = (1 << _GENERATION_BITS) - 1;
private const int _INDEX_MASK = (1 << _INDEX_BITS) - 1;
private const int _WORLD_INDEX_MASK = (1 << WORLD_INDEX_BITS) - 1;
private const int _GENERATION_MASK = (1 << GENERATION_BITS) - 1;
private const int _INDEX_MASK = (1 << INDEX_BITS) - 1;
public const EntityID INVALID_ID = -1;
@@ -32,13 +35,24 @@ public struct Entity : IEquatable<Entity>, IComparable<Entity>
public readonly GenerationID Generation
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => (GenerationID)(_id >> _INDEX_BITS & _GENERATION_MASK);
get => (GenerationID)(_id >> INDEX_BITS & _GENERATION_MASK);
}
public readonly WorldID WorldIndex
public readonly WorldID WorldID
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => (WorldID)(_id >> (_INDEX_BITS + _GENERATION_BITS) & _WORLD_INDEX_MASK);
get => (WorldID)(_id >> (INDEX_BITS + GENERATION_BITS) & _WORLD_INDEX_MASK);
}
public static Entity Invalid
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => new(INVALID_ID, 0, 0);
}
internal Entity(EntityID id, GenerationID generation, WorldID worldID)
{
_id = worldID << (INDEX_BITS + GENERATION_BITS) | generation << INDEX_BITS | id;
}
public void IncrementGeneration()
@@ -49,12 +63,7 @@ public struct Entity : IEquatable<Entity>, IComparable<Entity>
throw new InvalidOperationException("Generation overflow");
}
_id = _id & ~(_GENERATION_MASK << _INDEX_BITS) | generation << _INDEX_BITS;
}
internal Entity(EntityID index, EntityID generation, EntityID worldIndex)
{
_id = worldIndex << (_INDEX_BITS + _GENERATION_BITS) | generation << _INDEX_BITS | index;
_id = _id & ~(_GENERATION_MASK << INDEX_BITS) | generation << INDEX_BITS;
}
public readonly bool Equals(Entity other)
@@ -89,6 +98,219 @@ public struct Entity : IEquatable<Entity>, IComparable<Entity>
public override readonly string ToString()
{
return $"Entity {{ Index: {ID}, Generation: {Generation}, WorldIndex: {WorldIndex} }}";
return $"Entity {{ Index: {ID}, Generation: {Generation}, WorldIndex: {WorldID} }}";
}
}
public class EntityManager : IDisposable
{
private readonly List<Entity> _entities;
private readonly Queue<EntityID> _freeEntitySlots;
private readonly World _world;
public int EntityCount => _entities.Count;
public ReadOnlySpan<Entity> Entities => CollectionsMarshal.AsSpan(_entities);
internal EntityManager(World world, int initialCapacity)
{
_entities = new(initialCapacity);
_freeEntitySlots = new(initialCapacity);
_world = world;
}
/// <summary>
/// Adds a new <see cref="Entity"/> to the world.
/// </summary>
/// <returns>The created <see cref="Entity"/>.</returns>
public Entity CreateEntity()
{
if (_freeEntitySlots.TryDequeue(out var id))
{
return _entities[id];
}
else
{
id = _entities.Count;
var entity = new Entity(id, 0, _world.ID);
_entities.Add(entity);
return entity;
}
}
/// <summary>
/// Removes the specified <see cref="Entity"/> from the world.
/// </summary>
/// <param name="entity"></param>
public void RemoveEntity(ref Entity entity)
{
if (entity.ID >= _entities.Count || _entities[entity.ID].Generation != entity.Generation)
{
return;
}
_world._componentStorage.Remove(entity);
var slot = _entities[entity.ID];
slot.IncrementGeneration();
_entities[entity.ID] = slot;
_freeEntitySlots.Enqueue(entity.ID);
entity = Entity.Invalid;
}
/// <summary>
/// Checks if the given <see cref="Entity"/> is valid and belongs to this <see cref="World"/>.
/// </summary>
/// <param name="entity">The entity to check.</param>
/// <returns>True if the entity is valid and belongs to this world; otherwise, false.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool HasEntity(Entity entity)
{
if (!entity.IsValid
|| entity.WorldID != _world.ID
|| entity.ID >= _entities.Count)
{
return false;
}
return _entities[entity.ID].Generation == entity.Generation;
}
/// <summary>
/// Adds a component of type <typeparamref name="T"/> to the given <see cref="Entity"/>.
/// </summary>
/// <typeparam name="T">The type of the component to set.</typeparam>
/// <param name="entity">The entity for which the component is to be add.</param>
/// <param name="component">The component value to add.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddComponent<T>(Entity entity, T component)
where T : struct, IComponentData
{
_world._componentStorage.GetOrCreateComponentPool<T>().Add(entity, component);
_world._componentStorage.GetOrCreateMask(TypeHandle<T>.Value).SetBit(entity.ID);
}
/// <summary>
/// Removes a component of type <typeparamref name="T"/> from the given <see cref="Entity"/>.
/// </summary>
/// <typeparam name="T">The type of the component to remove.</typeparam>
/// <param name="entity">The entity for which the component is to be remove.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void RemoveComponent<T>(Entity entity)
where T : struct, IComponentData
{
if (_world._componentStorage.TryGetPool<T>(out var pool) && pool.Has(entity))
{
pool.Remove(entity);
_world._componentStorage.GetOrCreateMask(TypeHandle<T>.Value).ClearBit(entity.ID);
}
}
/// <summary>
/// Sets a component of type <typeparamref name="T"/> for the given <see cref="Entity"/>.
/// </summary>
/// <typeparam name="T">The type of the component to set.</typeparam>
/// <param name="entity">The entity for which the component is to be set.</param>
/// <param name="component">The component value to set.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetComponent<T>(Entity entity, T component)
where T : struct, IComponentData
{
_world._componentStorage.GetOrCreateComponentPool<T>().Set(entity, component);
}
/// <summary>
/// Checks if the given <see cref="Entity"/> has a component of the specified type.
/// </summary>
/// <param name="entity">The entity to check.</param>
/// <param name="typeHandle">The handle of the component type.</param>
/// <returns>True if the entity has the component; otherwise, false.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool HasComponent(Entity entity, nint typeHandle)
{
return _world._componentStorage.TryGetMask(typeHandle, out var bitSet) && bitSet.IsSet(entity.ID);
}
/// <summary>
/// Retrieves a reference to a component of type <typeparamref name="T"/> associated with the given <see cref="Entity"/>.
/// </summary>
/// <typeparam name="T">The type of the component to retrieve.</typeparam>
/// <param name="entity">The entity whose component is to be retrieved.</param>
/// <returns>A <see cref="Ref{T}"/> to the component, or a null reference if the component does not exist.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Ref<T> GetComponent<T>(Entity entity)
where T : struct, IComponentData
{
if (_world._componentStorage.TryGetPool<T>(out var pool) && pool.Has(entity))
{
return new Ref<T>(ref pool.GetRef(entity));
}
else
{
return new Ref<T>(ref Unsafe.NullRef<T>(), false);
}
}
/// <summary>
/// Adds a script of type <typeparamref name="T"/> to the given <see cref="Entity"/>.
/// </summary>
/// <typeparam name="T">The type of the script to add.</typeparam>
/// <param name="entity">The entity to which the script is to be added.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddScript<T>(Entity entity)
where T : ScriptComponent, new()
{
_world._componentStorage.ScriptComponentPool.Add(entity, new T());
}
/// <summary>
/// Adds a script of the specified type to the given <see cref="Entity"/>.
/// </summary>
/// <param name="entity">The entity to which the script is to be added.</param>
/// <param name="type">The type of the script to add.</param>
/// <exception cref="ArgumentException">Thrown if the specified type does not inherit from <see cref="ScriptComponent"/>.</exception>
/// <exception cref="InvalidOperationException">Thrown if the script instance could not be created.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddScript(Entity entity, Type type)
{
if (!typeof(ScriptComponent).IsAssignableFrom(type))
{
throw new ArgumentException($"Type {type} must inherit from ScriptComponent.", nameof(type));
}
var instance = (ScriptComponent?)Activator.CreateInstance(type) ?? throw new InvalidOperationException($"Failed to create instance of {type}.");
_world._componentStorage.ScriptComponentPool.Add(entity, instance);
}
/// <summary>
/// Retrieves the first script of type <typeparamref name="T"/> associated with the given <see cref="Entity"/>.
/// </summary>
/// <typeparam name="T">The type of the script to retrieve.</typeparam>
/// <param name="entity">The entity whose script is to be retrieved.</param>
/// <returns>The script of type <typeparamref name="T"/>, or null if no such script exists.</returns>
public T? GetScript<T>(Entity entity)
where T : ScriptComponent
{
return (T?)_world._componentStorage.ScriptComponentPool.Get(entity)?
.FirstOrDefault(script => script is T tScript);
}
/// <summary>
/// Retrieves all scripts of type <typeparamref name="T"/> associated with the given <see cref="Entity"/>.
/// </summary>
/// <typeparam name="T">The type of the scripts to retrieve.</typeparam>
/// <param name="entity">The entity whose scripts are to be retrieved.</param>
/// <returns>An enumerable of scripts of type <typeparamref name="T"/>.</returns>
public IEnumerable<T> GetScripts<T>(Entity entity)
where T : ScriptComponent
{
return (IEnumerable<T>?)_world._componentStorage.ScriptComponentPool.Get(entity)?.Where(script => script is T tScript) ?? Enumerable.Empty<T>();
}
public void Dispose()
{
_entities.Clear();
_freeEntitySlots.Clear();
}
}

View File

@@ -8,6 +8,11 @@
</PropertyGroup>
<ItemGroup>
<None Include="Template\QueryItem.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>QueryItem.tt</DependentUpon>
</None>
<None Include="Template\QueryRefComponent.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
@@ -27,10 +32,18 @@
</ItemGroup>
<ItemGroup>
<None Update="Template\QueryEnumerable.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>QueryEnumerable.cs</LastGenOutput>
</None>
<None Update="Template\Helpers.tt">
<Generator>TextTemplatingFilePreprocessor</Generator>
<LastGenOutput>Helpers.cs</LastGenOutput>
</None>
<None Update="Template\QueryItem.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>QueryItem.cs</LastGenOutput>
</None>
<None Update="Template\QueryRefComponent.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>QueryRefComponent.cs</LastGenOutput>
@@ -51,6 +64,16 @@
<AutoGen>True</AutoGen>
<DependentUpon>Helpers.tt</DependentUpon>
</Compile>
<Compile Update="Template\QueryEnumerable.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>QueryEnumerable.tt</DependentUpon>
</Compile>
<Compile Update="Template\QueryItem.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>QueryItem.tt</DependentUpon>
</Compile>
<Compile Update="Template\QueryRefComponent.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
@@ -63,4 +86,8 @@
</Compile>
</ItemGroup>
<ItemGroup>
<Folder Include="Helpers\" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,147 @@
using Ghost.Entities.Query;
using System.Runtime.CompilerServices;
namespace Ghost.Entities.Helpers;
/// <summary>
/// Provides extension methods for working with entities in the Ghost framework.
/// </summary>
public static class EntityHelpers
{
public static World GetWorld(this Entity entity)
{
return World.GetWorld(entity.WorldID);
}
/// <summary>
/// Adds a component of type <typeparamref name="T"/> to the given <see cref="Entity"/>.
/// </summary>
/// <typeparam name="T">The type of the component to set.</typeparam>
/// <param name="entity">The entity for which the component is to be add.</param>
/// <param name="component">The component value to add.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AddComponent<T>(this Entity entity, T component)
where T : struct, IComponentData
{
var world = entity.GetWorld();
world.EntityManager.AddComponent<T>(entity, component);
}
/// <summary>
/// Removes a component of type <typeparamref name="T"/> from the given <see cref="Entity"/>.
/// </summary>
/// <typeparam name="T">The type of the component to remove.</typeparam>
/// <param name="entity">The entity for which the component is to be remove.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void RemoveComponent<T>(this Entity entity)
where T : struct, IComponentData
{
var world = entity.GetWorld();
world.EntityManager.RemoveComponent<T>(entity);
}
/// <summary>
/// Sets a component of type <typeparamref name="T"/> for the given <see cref="Entity"/>.
/// </summary>
/// <typeparam name="T">The type of the component to set.</typeparam>
/// <param name="entity">The entity for which the component is to be set.</param>
/// <param name="component">The component value to set.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SetComponent<T>(this Entity entity, T component)
where T : struct, IComponentData
{
var world = entity.GetWorld();
world.EntityManager.SetComponent<T>(entity, component);
}
/// <summary>
/// Checks if the given <see cref="Entity"/> has a component of the specified type.
/// </summary>
/// <param name="entity">The entity to check.</param>
/// <param name="typeHandle">The handle of the component type.</param>
/// <returns>True if the entity has the component; otherwise, false.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool HasComponent(this Entity entity, nint typeHandle)
{
var world = entity.GetWorld();
return world.EntityManager.HasComponent(entity, typeHandle);
}
/// <summary>
/// Retrieves a reference to a component of type <typeparamref name="T"/> associated with the given <see cref="Entity"/>.
/// </summary>
/// <typeparam name="T">The type of the component to retrieve.</typeparam>
/// <param name="entity">The entity whose component is to be retrieved.</param>
/// <returns>A <see cref="Ref{T}"/> to the component, or a null reference if the component does not exist.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Ref<T> GetComponent<T>(this Entity entity)
where T : struct, IComponentData
{
var world = entity.GetWorld();
return world.EntityManager.GetComponent<T>(entity);
}
/// <summary>
/// Adds a script of type <typeparamref name="T"/> to the given <see cref="Entity"/>.
/// </summary>
/// <typeparam name="T">The type of the script to add.</typeparam>
/// <param name="entity">The entity to which the script is to be added.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AddScript<T>(this Entity entity)
where T : ScriptComponent, new()
{
var world = entity.GetWorld();
world.EntityManager.AddScript<T>(entity);
}
/// <summary>
/// Adds a script of the specified type to the given <see cref="Entity"/>.
/// </summary>
/// <param name="entity">The entity to which the script is to be added.</param>
/// <param name="type">The type of the script to add.</param>
/// <exception cref="ArgumentException">Thrown if the specified type does not inherit from <see cref="ScriptComponent"/>.</exception>
/// <exception cref="InvalidOperationException">Thrown if the script instance could not be created.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AddScript(this Entity entity, Type type)
{
var world = entity.GetWorld();
world.EntityManager.AddScript(entity, type);
}
/// <summary>
/// Retrieves the first script of type <typeparamref name="T"/> associated with the given <see cref="Entity"/>.
/// </summary>
/// <typeparam name="T">The type of the script to retrieve.</typeparam>
/// <param name="entity">The entity whose script is to be retrieved.</param>
/// <returns>The script of type <typeparamref name="T"/>, or null if no such script exists.</returns>
public static T? GetScript<T>(this Entity entity)
where T : ScriptComponent
{
var world = entity.GetWorld();
return world.EntityManager.GetScript<T>(entity);
}
/// <summary>
/// Retrieves all scripts of type <typeparamref name="T"/> associated with the given <see cref="Entity"/>.
/// </summary>
/// <typeparam name="T">The type of the scripts to retrieve.</typeparam>
/// <param name="entity">The entity whose scripts are to be retrieved.</param>
/// <returns>An enumerable of scripts of type <typeparamref name="T"/>.</returns>
public static IEnumerable<T> GetScripts<T>(this Entity entity)
where T : ScriptComponent
{
var world = entity.GetWorld();
return world.EntityManager.GetScripts<T>(entity);
}
/// <summary>
/// Destroys the given <see cref="Entity"/> by removing it from its associated <see cref="World"/>.
/// </summary>
/// <param name="entity">The entity to destroy.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Destroy(this Entity entity)
{
var world = entity.GetWorld();
world.EntityManager.RemoveEntity(ref entity);
}
}

View File

@@ -0,0 +1,98 @@
using Misaki.HighPerformance.Unsafe.Collections;
namespace Ghost.Entities.Query;
[Flags]
internal enum FilterMode
{
All = 1 << 0,
Any = 1 << 1,
Absent = 1 << 2,
Disabled = 1 << 3,
}
internal readonly struct FilterEntry(nint id, FilterMode mode)
{
public readonly nint typeHandle = id;
public readonly FilterMode mode = mode;
}
internal struct QueryFilter()
{
internal List<nint> _all = new(6);
internal List<nint> _any = new(6);
internal List<nint> _absent = new(6);
internal List<nint> _disabled = new(6);
public readonly void ComputeFilterBitMask(World world, ref BitSet result)
{
BitSet allMask = default;
BitSet anyMask = default;
BitSet absentMask = default;
var hasAll = false;
var hasAny = false;
var hasAbsent = false;
// Compute All mask (intersection)
foreach (var typeHandle in _all)
{
var mask = world._componentStorage.GetOrCreateMask(typeHandle);
if (!hasAll)
{
allMask = new BitSet(mask.Length);
allMask.SetAll();
hasAll = true;
}
allMask &= mask;
}
// Compute Any mask (union)
foreach (var typeHandle in _any)
{
var mask = world._componentStorage.GetOrCreateMask(typeHandle);
if (!hasAny)
{
anyMask = new BitSet(mask.Length);
hasAny = true;
}
anyMask |= mask;
}
// Compute Absent mask (union for exclusion)
foreach (var typeHandle in _absent)
{
var mask = world._componentStorage.GetOrCreateMask(typeHandle);
if (!hasAbsent)
{
absentMask = new BitSet(mask.Length);
hasAbsent = true;
}
absentMask |= mask;
}
result = new BitSet(world.EntityManager.EntityCount);
result.SetAll();
if (hasAll)
{
result &= allMask;
}
if (hasAny)
{
result &= anyMask;
}
if (hasAbsent)
{
result &= ~absentMask;
}
}
}

View File

@@ -0,0 +1,41 @@
using System.Runtime.CompilerServices;
namespace Ghost.Entities.Query;
public interface IQueryTypeParameter
{
}
public ref struct Ref<T> : IQueryTypeParameter
where T : IComponentData
{
internal ref T _value;
public ref T ValueRW
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => ref _value;
}
public readonly ref T ValueRO
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => ref _value;
}
public readonly bool IsValid
{
get;
init;
}
public Ref(ref T value, bool isValid)
{
_value = ref value;
IsValid = isValid;
}
public Ref(ref T value) : this(ref value, true)
{
}
}

View File

@@ -0,0 +1,78 @@
namespace Ghost.Entities;
public abstract class ScriptComponent : IComponentData
{
/// <summary>
/// Gets or sets a value indicating whether this script component is enabled.
/// </summary>
public bool Enable
{
get;
set;
} = true;
/// <summary>
/// Gets the entity that owns this script component.
/// </summary>
public Entity Owner
{
get;
internal set;
}
/// <summary>
/// Gets or sets the priority of the script component.
/// Change this during runtime does not affect the execution order.
/// </summary>
public virtual int ExecutionOrder => 0;
/// <summary>
/// Called when the script component is enabled.
/// </summary>
public virtual void OnEnable()
{
}
/// <summary>
/// Called when the script component is disabled.
/// </summary>
public virtual void OnDisable()
{
}
/// <summary>
/// Called when the script component is started.
/// </summary>
public virtual void Start()
{
}
/// <summary>
/// Called every frame.
/// </summary>
public virtual void Update()
{
}
/// <summary>
/// Called every frame after all Update methods have been called.
/// </summary>
public virtual void LateUpdate()
{
}
/// <summary>
/// Called at a fixed interval.
/// This method is called at a fixed time step, independent of the frame rate.
/// </summary>
public virtual void FixedUpdate()
{
}
/// <summary>
/// Called when the script component is destroyed.
/// </summary>
public virtual void OnDestroy()
{
}
}

89
Ghost.Entities/System.cs Normal file
View File

@@ -0,0 +1,89 @@
namespace Ghost.Entities;
public abstract class SystemBase
{
public virtual int ExecutionOrder => 0;
public virtual bool Enable
{
get;
set;
} = true;
public World World
{
get;
init;
} = null!;
public virtual void OnCreate()
{
}
public virtual void OnUpdate()
{
}
public virtual void OnDestroy()
{
}
}
internal class SystemStorage : IDisposable
{
private readonly List<SystemBase> _systems = new();
private readonly List<SystemBase> _executionList = new();
public void AddSystem<T>(T system)
where T : SystemBase
{
_systems.Add(system);
if (system.Enable)
{
system.OnCreate();
}
}
public void RemoveSystem<T>(T system)
where T : SystemBase
{
_systems.Remove(system);
if (system.Enable)
{
system.OnDestroy();
}
}
public void RebuildExecutionList()
{
_executionList.Clear();
_executionList.AddRange(_systems.OrderBy(s => s.ExecutionOrder));
}
public void UpdateSystems()
{
foreach (var system in _systems)
{
if (!system.Enable)
{
continue;
}
system.OnUpdate();
}
}
public void Dispose()
{
foreach (var system in _systems)
{
if (!system.Enable)
{
continue;
}
system.OnDestroy();
}
_systems.Clear();
_executionList.Clear();
}
}

View File

@@ -2,8 +2,8 @@
<#@ import namespace="System.Collections.Generic" #>
<#+
public int Amount = 25;
public int Amount = 8;
public int ExtensionAmount = 3;
public string Indent(StringBuilder sb, int spaces)
{
@@ -11,17 +11,22 @@
return sb.ToString().Replace("\n", "\n" + indent);
}
string AppendGenerics(int amount)
string AppendGenerics(int amount, string template)
{
var sb = new StringBuilder();
for (var i = 0; i < amount; i++)
{
if (i > 0) sb.Append(", ");
sb.Append($"T{i}");
sb.Append($"{template}{i}");
}
return sb.ToString();
}
string AppendGenerics(int amount)
{
return AppendGenerics(amount, "T");
}
public StringBuilder AppendGenericRefParameters(int amount)
{
var sb = new StringBuilder();
@@ -46,12 +51,12 @@
return sb;
}
public StringBuilder AppendGenericRestrictions(int amount, string template)
public StringBuilder AppendGenericRestrictions(int amount, string Ttemplate, string template)
{
var sb = new StringBuilder();
for (var localIndex = 0; localIndex < amount; localIndex++)
{
sb.Append($"where T{localIndex} : {template}");
sb.Append($"where {Ttemplate}{localIndex} : {template}");
if (localIndex < amount - 1)
{
sb.Append(' ');
@@ -60,12 +65,17 @@
return sb;
}
public StringBuilder AppendGenericRestrictions(int amount, string template)
{
return AppendGenericRestrictions(amount, "T", template);
}
public StringBuilder TryGetComponentPools(int amount)
{
var sb = new StringBuilder();
for (var localIndex = 0; localIndex < amount; localIndex++)
{
sb.Append($"TryGetPool<T{localIndex}>(out var pool{localIndex})");
sb.Append($"_componentStorage.TryGetPool<T{localIndex}>(out var pool{localIndex})");
if (localIndex < amount - 1)
{
sb.Append(" && ");

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,147 @@
<#@ template language="C#" #>
<#@ output extension=".cs" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Linq" #>
<#@ include file="Helpers.ttinclude" #>
using Ghost.Entities.Query;
using Ghost.Entities.Utilities;
using Misaki.HighPerformance.Unsafe.Collections;
namespace Ghost.Entities;
<# for (int arity = 1; arity <= Amount; arity++) {
var generics = AppendGenerics(arity);
var restrictions = AppendGenericRestrictions(arity, "struct, IComponentData");
var poolParams = Enumerable.Range(0, arity)
.Select(i => $"ComponentPool<T{i}> pool{i}")
.Aggregate((a, b) => a + ", " + b);
var constructorParams = Enumerable.Range(0, arity)
.Select(i => $"_pool{i}")
.Aggregate((a, b) => a + ", " + b);
#>
public struct QueryEnumerable<<#= generics #>>
<#= restrictions #>
{
private readonly World _world;
<# for (int i = 0; i < arity; i++){ #>
private readonly ComponentPool<T<#= i #>> _pool<#= i #>;
<# } #>
private readonly int _count;
private QueryFilter _filters;
internal readonly QueryFilter Filters => _filters;
internal QueryEnumerable(World world, <#= poolParams #>, int count)
{
_world = world;
<# for (int i = 0; i < arity; i++) { #>
_pool<#= i #> = pool<#= i #>;
<# } #>
_count = count;
_filters = new();
<# for (int i = 0; i < arity; i++) {#>
_filters._all.Add(TypeHandle<T<#= i #>>.Value);
<# } #>
}
public Enumerator GetEnumerator() => new Enumerator(_world, <#= constructorParams #>, _count, _filters);
public ref struct Enumerator
{
private readonly World _world;
private readonly ReadOnlySpan<Entity> _entities;
<# for (int i = 0; i < arity; i++){ #>
private readonly ComponentPool<T<#= i #>> _pool<#= i #>;
<# } #>
private int _index;
private readonly int _count;
private BitSet _filterMask;
public QueryItem<<#= generics #>> Current
{
get;
private set;
}
internal Enumerator(World world, <#= poolParams #>, int count, QueryFilter filters)
{
_world = world;
_entities = _world.EntityManager.Entities;
<# for (int i = 0; i < arity; i++){ #>
_pool<#= i #> = pool<#= i #>;
<# } #>
_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<<#= generics #>>(_entities[_index], <#= constructorParams #>);
return true;
}
}
<# for (int i = 1; i <= ExtensionAmount; i++) {
var compGenerics = AppendGenerics(i, "TComponent");
var compRestrictions = AppendGenericRestrictions(i, "TComponent", "struct, IComponentData");
#>
public readonly QueryEnumerable<<#= generics #>> WithAll<<#= compGenerics #>>()
<#= compRestrictions #>
{
<# for (int j = 0; j < i; j++) {#>
_filters._all.Add(TypeHandle<TComponent<#= j #>>.Value);
<# } #>
return this;
}
public readonly QueryEnumerable<<#= generics #>> WithAny<<#= compGenerics #>>()
<#= compRestrictions #>
{
<# for (int j = 0; j < i; j++) {#>
_filters._any.Add(TypeHandle<TComponent<#= j #>>.Value);
<# } #>
return this;
}
public readonly QueryEnumerable<<#= generics #>> WithAbsent<<#= compGenerics #>>()
<#= compRestrictions #>
{
<# for (int j = 0; j < i; j++) {#>
_filters._absent.Add(TypeHandle<TComponent<#= j #>>.Value);
<# } #>
return this;
}
public readonly QueryEnumerable<<#= generics #>> WithDisabled<<#= compGenerics #>>()
<#= compRestrictions #>
{
<# for (int j = 0; j < i; j++) {#>
_filters._disabled.Add(TypeHandle<TComponent<#= j #>>.Value);
<# } #>
return this;
}
<# } #>
}
<# } #>

View File

@@ -0,0 +1,282 @@
using Ghost.Entities.Query;
namespace Ghost.Entities;
public readonly struct QueryItem<T0>
where T0 : struct, IComponentData
{
private readonly Entity _entity;
private readonly ComponentPool<T0> _pool0;
internal QueryItem(Entity entity, ComponentPool<T0> pool0)
{
_entity = entity;
_pool0 = pool0;
}
public Entity Entity => _entity;
public ref T0 Component0 => ref _pool0.GetRef(_entity);
// Deconstruct into tuple-like values
public void Deconstruct(out Entity entity, out Ref<T0> c0)
{
entity = _entity;
c0 = new (ref _pool0.GetRef(_entity));
}
}
public readonly struct QueryItem<T0, T1>
where T0 : struct, IComponentData where T1 : struct, IComponentData
{
private readonly Entity _entity;
private readonly ComponentPool<T0> _pool0;
private readonly ComponentPool<T1> _pool1;
internal QueryItem(Entity entity, ComponentPool<T0> pool0, ComponentPool<T1> pool1)
{
_entity = entity;
_pool0 = pool0;
_pool1 = pool1;
}
public Entity Entity => _entity;
public ref T0 Component0 => ref _pool0.GetRef(_entity);
public ref T1 Component1 => ref _pool1.GetRef(_entity);
// Deconstruct into tuple-like values
public void Deconstruct(out Entity entity, out Ref<T0> c0, out Ref<T1> c1)
{
entity = _entity;
c0 = new (ref _pool0.GetRef(_entity));c1 = new (ref _pool1.GetRef(_entity));
}
}
public readonly struct QueryItem<T0, T1, T2>
where T0 : struct, IComponentData where T1 : struct, IComponentData where T2 : struct, IComponentData
{
private readonly Entity _entity;
private readonly ComponentPool<T0> _pool0;
private readonly ComponentPool<T1> _pool1;
private readonly ComponentPool<T2> _pool2;
internal QueryItem(Entity entity, ComponentPool<T0> pool0, ComponentPool<T1> pool1, ComponentPool<T2> pool2)
{
_entity = entity;
_pool0 = pool0;
_pool1 = pool1;
_pool2 = pool2;
}
public Entity Entity => _entity;
public ref T0 Component0 => ref _pool0.GetRef(_entity);
public ref T1 Component1 => ref _pool1.GetRef(_entity);
public ref T2 Component2 => ref _pool2.GetRef(_entity);
// Deconstruct into tuple-like values
public void Deconstruct(out Entity entity, out Ref<T0> c0, out Ref<T1> c1, out Ref<T2> c2)
{
entity = _entity;
c0 = new (ref _pool0.GetRef(_entity));c1 = new (ref _pool1.GetRef(_entity));c2 = new (ref _pool2.GetRef(_entity));
}
}
public readonly struct QueryItem<T0, T1, T2, T3>
where T0 : struct, IComponentData where T1 : struct, IComponentData where T2 : struct, IComponentData where T3 : struct, IComponentData
{
private readonly Entity _entity;
private readonly ComponentPool<T0> _pool0;
private readonly ComponentPool<T1> _pool1;
private readonly ComponentPool<T2> _pool2;
private readonly ComponentPool<T3> _pool3;
internal QueryItem(Entity entity, ComponentPool<T0> pool0, ComponentPool<T1> pool1, ComponentPool<T2> pool2, ComponentPool<T3> pool3)
{
_entity = entity;
_pool0 = pool0;
_pool1 = pool1;
_pool2 = pool2;
_pool3 = pool3;
}
public Entity Entity => _entity;
public ref T0 Component0 => ref _pool0.GetRef(_entity);
public ref T1 Component1 => ref _pool1.GetRef(_entity);
public ref T2 Component2 => ref _pool2.GetRef(_entity);
public ref T3 Component3 => ref _pool3.GetRef(_entity);
// Deconstruct into tuple-like values
public void Deconstruct(out Entity entity, out Ref<T0> c0, out Ref<T1> c1, out Ref<T2> c2, out Ref<T3> c3)
{
entity = _entity;
c0 = new (ref _pool0.GetRef(_entity));c1 = new (ref _pool1.GetRef(_entity));c2 = new (ref _pool2.GetRef(_entity));c3 = new (ref _pool3.GetRef(_entity));
}
}
public readonly struct QueryItem<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 Entity _entity;
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;
internal QueryItem(Entity entity, ComponentPool<T0> pool0, ComponentPool<T1> pool1, ComponentPool<T2> pool2, ComponentPool<T3> pool3, ComponentPool<T4> pool4)
{
_entity = entity;
_pool0 = pool0;
_pool1 = pool1;
_pool2 = pool2;
_pool3 = pool3;
_pool4 = pool4;
}
public Entity Entity => _entity;
public ref T0 Component0 => ref _pool0.GetRef(_entity);
public ref T1 Component1 => ref _pool1.GetRef(_entity);
public ref T2 Component2 => ref _pool2.GetRef(_entity);
public ref T3 Component3 => ref _pool3.GetRef(_entity);
public ref T4 Component4 => ref _pool4.GetRef(_entity);
// Deconstruct into tuple-like values
public void Deconstruct(out Entity entity, out Ref<T0> c0, out Ref<T1> c1, out Ref<T2> c2, out Ref<T3> c3, out Ref<T4> c4)
{
entity = _entity;
c0 = new (ref _pool0.GetRef(_entity));c1 = new (ref _pool1.GetRef(_entity));c2 = new (ref _pool2.GetRef(_entity));c3 = new (ref _pool3.GetRef(_entity));c4 = new (ref _pool4.GetRef(_entity));
}
}
public readonly struct QueryItem<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 Entity _entity;
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;
internal QueryItem(Entity entity, ComponentPool<T0> pool0, ComponentPool<T1> pool1, ComponentPool<T2> pool2, ComponentPool<T3> pool3, ComponentPool<T4> pool4, ComponentPool<T5> pool5)
{
_entity = entity;
_pool0 = pool0;
_pool1 = pool1;
_pool2 = pool2;
_pool3 = pool3;
_pool4 = pool4;
_pool5 = pool5;
}
public Entity Entity => _entity;
public ref T0 Component0 => ref _pool0.GetRef(_entity);
public ref T1 Component1 => ref _pool1.GetRef(_entity);
public ref T2 Component2 => ref _pool2.GetRef(_entity);
public ref T3 Component3 => ref _pool3.GetRef(_entity);
public ref T4 Component4 => ref _pool4.GetRef(_entity);
public ref T5 Component5 => ref _pool5.GetRef(_entity);
// Deconstruct into tuple-like values
public void Deconstruct(out Entity entity, out Ref<T0> c0, out Ref<T1> c1, out Ref<T2> c2, out Ref<T3> c3, out Ref<T4> c4, out Ref<T5> c5)
{
entity = _entity;
c0 = new (ref _pool0.GetRef(_entity));c1 = new (ref _pool1.GetRef(_entity));c2 = new (ref _pool2.GetRef(_entity));c3 = new (ref _pool3.GetRef(_entity));c4 = new (ref _pool4.GetRef(_entity));c5 = new (ref _pool5.GetRef(_entity));
}
}
public readonly struct QueryItem<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 Entity _entity;
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;
internal QueryItem(Entity entity, ComponentPool<T0> pool0, ComponentPool<T1> pool1, ComponentPool<T2> pool2, ComponentPool<T3> pool3, ComponentPool<T4> pool4, ComponentPool<T5> pool5, ComponentPool<T6> pool6)
{
_entity = entity;
_pool0 = pool0;
_pool1 = pool1;
_pool2 = pool2;
_pool3 = pool3;
_pool4 = pool4;
_pool5 = pool5;
_pool6 = pool6;
}
public Entity Entity => _entity;
public ref T0 Component0 => ref _pool0.GetRef(_entity);
public ref T1 Component1 => ref _pool1.GetRef(_entity);
public ref T2 Component2 => ref _pool2.GetRef(_entity);
public ref T3 Component3 => ref _pool3.GetRef(_entity);
public ref T4 Component4 => ref _pool4.GetRef(_entity);
public ref T5 Component5 => ref _pool5.GetRef(_entity);
public ref T6 Component6 => ref _pool6.GetRef(_entity);
// Deconstruct into tuple-like values
public void Deconstruct(out Entity entity, out Ref<T0> c0, out Ref<T1> c1, out Ref<T2> c2, out Ref<T3> c3, out Ref<T4> c4, out Ref<T5> c5, out Ref<T6> c6)
{
entity = _entity;
c0 = new (ref _pool0.GetRef(_entity));c1 = new (ref _pool1.GetRef(_entity));c2 = new (ref _pool2.GetRef(_entity));c3 = new (ref _pool3.GetRef(_entity));c4 = new (ref _pool4.GetRef(_entity));c5 = new (ref _pool5.GetRef(_entity));c6 = new (ref _pool6.GetRef(_entity));
}
}
public readonly struct QueryItem<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 Entity _entity;
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;
internal QueryItem(Entity entity, ComponentPool<T0> pool0, ComponentPool<T1> pool1, ComponentPool<T2> pool2, ComponentPool<T3> pool3, ComponentPool<T4> pool4, ComponentPool<T5> pool5, ComponentPool<T6> pool6, ComponentPool<T7> pool7)
{
_entity = entity;
_pool0 = pool0;
_pool1 = pool1;
_pool2 = pool2;
_pool3 = pool3;
_pool4 = pool4;
_pool5 = pool5;
_pool6 = pool6;
_pool7 = pool7;
}
public Entity Entity => _entity;
public ref T0 Component0 => ref _pool0.GetRef(_entity);
public ref T1 Component1 => ref _pool1.GetRef(_entity);
public ref T2 Component2 => ref _pool2.GetRef(_entity);
public ref T3 Component3 => ref _pool3.GetRef(_entity);
public ref T4 Component4 => ref _pool4.GetRef(_entity);
public ref T5 Component5 => ref _pool5.GetRef(_entity);
public ref T6 Component6 => ref _pool6.GetRef(_entity);
public ref T7 Component7 => ref _pool7.GetRef(_entity);
// Deconstruct into tuple-like values
public void Deconstruct(out Entity entity, out Ref<T0> c0, out Ref<T1> c1, out Ref<T2> c2, out Ref<T3> c3, out Ref<T4> c4, out Ref<T5> c5, out Ref<T6> c6, out Ref<T7> c7)
{
entity = _entity;
c0 = new (ref _pool0.GetRef(_entity));c1 = new (ref _pool1.GetRef(_entity));c2 = new (ref _pool2.GetRef(_entity));c3 = new (ref _pool3.GetRef(_entity));c4 = new (ref _pool4.GetRef(_entity));c5 = new (ref _pool5.GetRef(_entity));c6 = new (ref _pool6.GetRef(_entity));c7 = new (ref _pool7.GetRef(_entity));
}
}

View File

@@ -0,0 +1,63 @@
<#@ template language="C#" debug="false" hostspecific="true" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ include file="Helpers.ttinclude" #>
<#@ output extension=".cs" #>
using Ghost.Entities.Query;
namespace Ghost.Entities;
<# for (int arity = 1; arity <= Amount; arity++)
{
var generics = AppendGenerics(arity);
var restrictions = AppendGenericRestrictions(arity, "struct, IComponentData");
var constructorParams = Enumerable.Range(0, arity)
.Select(i => $"ComponentPool<T{i}> pool{i}")
.Aggregate((a, b) => a + ", " + b);
var deconstructParams = Enumerable.Range(0, arity)
.Select(i => {
var name = $"c{i}";
return arity == 1
? $"out Ref<T0> {name}"
: $"out Ref<T{i}> {name}";
})
.Aggregate((a, b) => a + ", " + b);
var deconstructAssigns = Enumerable.Range(0, arity)
.Select(i => {
var name = $"c{i}";
return $"{name} = new (ref _pool{i}.GetRef(_entity));";
})
.Aggregate((a, b) => a + b);
#>
public readonly struct QueryItem<<#= generics #>>
<#= restrictions #>
{
private readonly Entity _entity;
<# for (int i = 0; i < arity; i++){ #>
private readonly ComponentPool<T<#= i #>> _pool<#= i #>;
<# } #>
internal QueryItem(Entity entity, <#= constructorParams #>)
{
_entity = entity;
<# for (int i = 0; i < arity; i++){ #>
_pool<#= i #> = pool<#= i #>;
<# } #>
}
public Entity Entity => _entity;
<# for (int i = 0; i < arity; i++){ #>
public ref T<#= i #> Component<#= i #> => ref _pool<#= i #>.GetRef(_entity);
<# } #>
// Deconstruct into tuple-like values
public void Deconstruct(out Entity entity, <#= deconstructParams #>)
{
entity = _entity;
<#= deconstructAssigns #>
}
}
<# } #>

View File

@@ -3,52 +3,18 @@
namespace Ghost.Entities;
public delegate void QueryRefComponent<T0>(Entity entity, ref T0 t0Component)
where T0 : struct, IComponent;
where T0 : struct, IComponentData;
public delegate void QueryRefComponent<T0, T1>(Entity entity, ref T0 t0Component,ref T1 t1Component)
where T0 : struct, IComponent where T1 : struct, IComponent;
where T0 : struct, IComponentData where T1 : struct, IComponentData;
public delegate void QueryRefComponent<T0, T1, T2>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent;
where T0 : struct, IComponentData where T1 : struct, IComponentData where T2 : struct, IComponentData;
public delegate void QueryRefComponent<T0, T1, T2, T3>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent;
where T0 : struct, IComponentData where T1 : struct, IComponentData where T2 : struct, IComponentData where T3 : struct, IComponentData;
public delegate void QueryRefComponent<T0, T1, T2, T3, T4>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent;
where T0 : struct, IComponentData where T1 : struct, IComponentData where T2 : struct, IComponentData where T3 : struct, IComponentData where T4 : struct, IComponentData;
public delegate void QueryRefComponent<T0, T1, T2, T3, T4, T5>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component,ref T5 t5Component)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent;
where T0 : struct, IComponentData where T1 : struct, IComponentData where T2 : struct, IComponentData where T3 : struct, IComponentData where T4 : struct, IComponentData where T5 : struct, IComponentData;
public delegate void QueryRefComponent<T0, T1, T2, T3, T4, T5, T6>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component,ref T5 t5Component,ref T6 t6Component)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent;
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;
public delegate void QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component,ref T5 t5Component,ref T6 t6Component,ref T7 t7Component)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent;
public delegate void QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component,ref T5 t5Component,ref T6 t6Component,ref T7 t7Component,ref T8 t8Component)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent;
public delegate void QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component,ref T5 t5Component,ref T6 t6Component,ref T7 t7Component,ref T8 t8Component,ref T9 t9Component)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent;
public delegate void QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component,ref T5 t5Component,ref T6 t6Component,ref T7 t7Component,ref T8 t8Component,ref T9 t9Component,ref T10 t10Component)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent;
public delegate void QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component,ref T5 t5Component,ref T6 t6Component,ref T7 t7Component,ref T8 t8Component,ref T9 t9Component,ref T10 t10Component,ref T11 t11Component)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent;
public delegate void QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component,ref T5 t5Component,ref T6 t6Component,ref T7 t7Component,ref T8 t8Component,ref T9 t9Component,ref T10 t10Component,ref T11 t11Component,ref T12 t12Component)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent where T12 : struct, IComponent;
public delegate void QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component,ref T5 t5Component,ref T6 t6Component,ref T7 t7Component,ref T8 t8Component,ref T9 t9Component,ref T10 t10Component,ref T11 t11Component,ref T12 t12Component,ref T13 t13Component)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent where T12 : struct, IComponent where T13 : struct, IComponent;
public delegate void QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component,ref T5 t5Component,ref T6 t6Component,ref T7 t7Component,ref T8 t8Component,ref T9 t9Component,ref T10 t10Component,ref T11 t11Component,ref T12 t12Component,ref T13 t13Component,ref T14 t14Component)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent where T12 : struct, IComponent where T13 : struct, IComponent where T14 : struct, IComponent;
public delegate void QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component,ref T5 t5Component,ref T6 t6Component,ref T7 t7Component,ref T8 t8Component,ref T9 t9Component,ref T10 t10Component,ref T11 t11Component,ref T12 t12Component,ref T13 t13Component,ref T14 t14Component,ref T15 t15Component)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent where T12 : struct, IComponent where T13 : struct, IComponent where T14 : struct, IComponent where T15 : struct, IComponent;
public delegate void QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component,ref T5 t5Component,ref T6 t6Component,ref T7 t7Component,ref T8 t8Component,ref T9 t9Component,ref T10 t10Component,ref T11 t11Component,ref T12 t12Component,ref T13 t13Component,ref T14 t14Component,ref T15 t15Component,ref T16 t16Component)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent where T12 : struct, IComponent where T13 : struct, IComponent where T14 : struct, IComponent where T15 : struct, IComponent where T16 : struct, IComponent;
public delegate void QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component,ref T5 t5Component,ref T6 t6Component,ref T7 t7Component,ref T8 t8Component,ref T9 t9Component,ref T10 t10Component,ref T11 t11Component,ref T12 t12Component,ref T13 t13Component,ref T14 t14Component,ref T15 t15Component,ref T16 t16Component,ref T17 t17Component)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent where T12 : struct, IComponent where T13 : struct, IComponent where T14 : struct, IComponent where T15 : struct, IComponent where T16 : struct, IComponent where T17 : struct, IComponent;
public delegate void QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component,ref T5 t5Component,ref T6 t6Component,ref T7 t7Component,ref T8 t8Component,ref T9 t9Component,ref T10 t10Component,ref T11 t11Component,ref T12 t12Component,ref T13 t13Component,ref T14 t14Component,ref T15 t15Component,ref T16 t16Component,ref T17 t17Component,ref T18 t18Component)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent where T12 : struct, IComponent where T13 : struct, IComponent where T14 : struct, IComponent where T15 : struct, IComponent where T16 : struct, IComponent where T17 : struct, IComponent where T18 : struct, IComponent;
public delegate void QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component,ref T5 t5Component,ref T6 t6Component,ref T7 t7Component,ref T8 t8Component,ref T9 t9Component,ref T10 t10Component,ref T11 t11Component,ref T12 t12Component,ref T13 t13Component,ref T14 t14Component,ref T15 t15Component,ref T16 t16Component,ref T17 t17Component,ref T18 t18Component,ref T19 t19Component)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent where T12 : struct, IComponent where T13 : struct, IComponent where T14 : struct, IComponent where T15 : struct, IComponent where T16 : struct, IComponent where T17 : struct, IComponent where T18 : struct, IComponent where T19 : struct, IComponent;
public delegate void QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component,ref T5 t5Component,ref T6 t6Component,ref T7 t7Component,ref T8 t8Component,ref T9 t9Component,ref T10 t10Component,ref T11 t11Component,ref T12 t12Component,ref T13 t13Component,ref T14 t14Component,ref T15 t15Component,ref T16 t16Component,ref T17 t17Component,ref T18 t18Component,ref T19 t19Component,ref T20 t20Component)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent where T12 : struct, IComponent where T13 : struct, IComponent where T14 : struct, IComponent where T15 : struct, IComponent where T16 : struct, IComponent where T17 : struct, IComponent where T18 : struct, IComponent where T19 : struct, IComponent where T20 : struct, IComponent;
public delegate void QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component,ref T5 t5Component,ref T6 t6Component,ref T7 t7Component,ref T8 t8Component,ref T9 t9Component,ref T10 t10Component,ref T11 t11Component,ref T12 t12Component,ref T13 t13Component,ref T14 t14Component,ref T15 t15Component,ref T16 t16Component,ref T17 t17Component,ref T18 t18Component,ref T19 t19Component,ref T20 t20Component,ref T21 t21Component)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent where T12 : struct, IComponent where T13 : struct, IComponent where T14 : struct, IComponent where T15 : struct, IComponent where T16 : struct, IComponent where T17 : struct, IComponent where T18 : struct, IComponent where T19 : struct, IComponent where T20 : struct, IComponent where T21 : struct, IComponent;
public delegate void QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component,ref T5 t5Component,ref T6 t6Component,ref T7 t7Component,ref T8 t8Component,ref T9 t9Component,ref T10 t10Component,ref T11 t11Component,ref T12 t12Component,ref T13 t13Component,ref T14 t14Component,ref T15 t15Component,ref T16 t16Component,ref T17 t17Component,ref T18 t18Component,ref T19 t19Component,ref T20 t20Component,ref T21 t21Component,ref T22 t22Component)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent where T12 : struct, IComponent where T13 : struct, IComponent where T14 : struct, IComponent where T15 : struct, IComponent where T16 : struct, IComponent where T17 : struct, IComponent where T18 : struct, IComponent where T19 : struct, IComponent where T20 : struct, IComponent where T21 : struct, IComponent where T22 : struct, IComponent;
public delegate void QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component,ref T5 t5Component,ref T6 t6Component,ref T7 t7Component,ref T8 t8Component,ref T9 t9Component,ref T10 t10Component,ref T11 t11Component,ref T12 t12Component,ref T13 t13Component,ref T14 t14Component,ref T15 t15Component,ref T16 t16Component,ref T17 t17Component,ref T18 t18Component,ref T19 t19Component,ref T20 t20Component,ref T21 t21Component,ref T22 t22Component,ref T23 t23Component)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent where T12 : struct, IComponent where T13 : struct, IComponent where T14 : struct, IComponent where T15 : struct, IComponent where T16 : struct, IComponent where T17 : struct, IComponent where T18 : struct, IComponent where T19 : struct, IComponent where T20 : struct, IComponent where T21 : struct, IComponent where T22 : struct, IComponent where T23 : struct, IComponent;
public delegate void QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component,ref T3 t3Component,ref T4 t4Component,ref T5 t5Component,ref T6 t6Component,ref T7 t7Component,ref T8 t8Component,ref T9 t9Component,ref T10 t10Component,ref T11 t11Component,ref T12 t12Component,ref T13 t13Component,ref T14 t14Component,ref T15 t15Component,ref T16 t16Component,ref T17 t17Component,ref T18 t18Component,ref T19 t19Component,ref T20 t20Component,ref T21 t21Component,ref T22 t22Component,ref T23 t23Component,ref T24 t24Component)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent where T12 : struct, IComponent where T13 : struct, IComponent where T14 : struct, IComponent where T15 : struct, IComponent where T16 : struct, IComponent where T17 : struct, IComponent where T18 : struct, IComponent where T19 : struct, IComponent where T20 : struct, IComponent where T21 : struct, IComponent where T22 : struct, IComponent where T23 : struct, IComponent where T24 : struct, IComponent;
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;

View File

@@ -10,7 +10,7 @@ for (var index = 1; index <= Amount; index++)
{
var generics = AppendGenerics(index);
var parameters = AppendGenericRefParameters(index);
var restrictions = AppendGenericRestrictions(index, "struct, IComponent");
var restrictions = AppendGenericRestrictions(index, "struct, IComponentData");
#>
public delegate void QueryRefComponent<<#= generics #>>(Entity entity, <#= parameters.ToString() #>)
<#= restrictions.ToString() #>;

View File

@@ -2,501 +2,102 @@
namespace Ghost.Entities;
public partial struct World
public partial class World
{
public readonly void Query<T0>(QueryRefComponent<T0> callback)
where T0 : struct, IComponent
public QueryEnumerable<T0> Query<T0>()
where T0 : struct, IComponentData
{
if (!(TryGetPool<T0>(out var pool0)))
{
return;
}
for (var i = 0; i < pool0.Count; i++)
{
var entity = _entities[i];
callback(entity, ref pool0.GetRef(entity));
}
}
public readonly void Query<T0, T1>(QueryRefComponent<T0, T1> callback)
where T0 : struct, IComponent where T1 : struct, IComponent
{
if (!(TryGetPool<T0>(out var pool0) && TryGetPool<T1>(out var pool1)))
{
return;
}
for (var i = 0; i < pool0.Count; i++)
{
var entity = _entities[i];
if (!(pool1.Has(entity)))
{
continue;
}
callback(entity, ref pool0.GetRef(entity), ref pool1.GetRef(entity));
}
}
public readonly void Query<T0, T1, T2>(QueryRefComponent<T0, T1, T2> callback)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent
{
if (!(TryGetPool<T0>(out var pool0) && TryGetPool<T1>(out var pool1) && TryGetPool<T2>(out var pool2)))
{
return;
}
for (var i = 0; i < pool0.Count; i++)
{
var entity = _entities[i];
if (!(pool1.Has(entity) && pool2.Has(entity)))
{
continue;
}
callback(entity, ref pool0.GetRef(entity), ref pool1.GetRef(entity), ref pool2.GetRef(entity));
}
}
public readonly void Query<T0, T1, T2, T3>(QueryRefComponent<T0, T1, T2, T3> callback)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent
{
if (!(TryGetPool<T0>(out var pool0) && TryGetPool<T1>(out var pool1) && TryGetPool<T2>(out var pool2) && TryGetPool<T3>(out var pool3)))
{
return;
}
for (var i = 0; i < pool0.Count; i++)
{
var entity = _entities[i];
if (!(pool1.Has(entity) && pool2.Has(entity) && pool3.Has(entity)))
{
continue;
}
callback(entity, ref pool0.GetRef(entity), ref pool1.GetRef(entity), ref pool2.GetRef(entity), ref pool3.GetRef(entity));
}
}
public readonly void Query<T0, T1, T2, T3, T4>(QueryRefComponent<T0, T1, T2, T3, T4> callback)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent
{
if (!(TryGetPool<T0>(out var pool0) && TryGetPool<T1>(out var pool1) && TryGetPool<T2>(out var pool2) && TryGetPool<T3>(out var pool3) && TryGetPool<T4>(out var pool4)))
{
return;
}
for (var i = 0; i < pool0.Count; i++)
{
var entity = _entities[i];
if (!(pool1.Has(entity) && pool2.Has(entity) && pool3.Has(entity) && pool4.Has(entity)))
{
continue;
}
callback(entity, ref pool0.GetRef(entity), ref pool1.GetRef(entity), ref pool2.GetRef(entity), ref pool3.GetRef(entity), ref pool4.GetRef(entity));
}
}
public readonly void Query<T0, T1, T2, T3, T4, T5>(QueryRefComponent<T0, T1, T2, T3, T4, T5> callback)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent
{
if (!(TryGetPool<T0>(out var pool0) && TryGetPool<T1>(out var pool1) && TryGetPool<T2>(out var pool2) && TryGetPool<T3>(out var pool3) && TryGetPool<T4>(out var pool4) && TryGetPool<T5>(out var pool5)))
{
return;
}
for (var i = 0; i < pool0.Count; i++)
{
var entity = _entities[i];
if (!(pool1.Has(entity) && pool2.Has(entity) && pool3.Has(entity) && pool4.Has(entity) && pool5.Has(entity)))
{
continue;
}
callback(entity, ref pool0.GetRef(entity), ref pool1.GetRef(entity), ref pool2.GetRef(entity), ref pool3.GetRef(entity), ref pool4.GetRef(entity), ref pool5.GetRef(entity));
}
}
public readonly void Query<T0, T1, T2, T3, T4, T5, T6>(QueryRefComponent<T0, T1, T2, T3, T4, T5, T6> callback)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent
{
if (!(TryGetPool<T0>(out var pool0) && TryGetPool<T1>(out var pool1) && TryGetPool<T2>(out var pool2) && TryGetPool<T3>(out var pool3) && TryGetPool<T4>(out var pool4) && TryGetPool<T5>(out var pool5) && TryGetPool<T6>(out var pool6)))
{
return;
}
for (var i = 0; i < pool0.Count; i++)
{
var entity = _entities[i];
if (!(pool1.Has(entity) && pool2.Has(entity) && pool3.Has(entity) && pool4.Has(entity) && pool5.Has(entity) && pool6.Has(entity)))
{
continue;
}
callback(entity, ref pool0.GetRef(entity), ref pool1.GetRef(entity), ref pool2.GetRef(entity), ref pool3.GetRef(entity), ref pool4.GetRef(entity), ref pool5.GetRef(entity), ref pool6.GetRef(entity));
}
}
public readonly void Query<T0, T1, T2, T3, T4, T5, T6, T7>(QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7> callback)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent
{
if (!(TryGetPool<T0>(out var pool0) && TryGetPool<T1>(out var pool1) && TryGetPool<T2>(out var pool2) && TryGetPool<T3>(out var pool3) && TryGetPool<T4>(out var pool4) && TryGetPool<T5>(out var pool5) && TryGetPool<T6>(out var pool6) && TryGetPool<T7>(out var pool7)))
{
return;
}
for (var i = 0; i < pool0.Count; i++)
{
var entity = _entities[i];
if (!(pool1.Has(entity) && pool2.Has(entity) && pool3.Has(entity) && pool4.Has(entity) && pool5.Has(entity) && pool6.Has(entity) && pool7.Has(entity)))
{
continue;
}
callback(entity, ref pool0.GetRef(entity), ref pool1.GetRef(entity), ref pool2.GetRef(entity), ref pool3.GetRef(entity), ref pool4.GetRef(entity), ref pool5.GetRef(entity), ref pool6.GetRef(entity), ref pool7.GetRef(entity));
}
}
public readonly void Query<T0, T1, T2, T3, T4, T5, T6, T7, T8>(QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8> callback)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent
{
if (!(TryGetPool<T0>(out var pool0) && TryGetPool<T1>(out var pool1) && TryGetPool<T2>(out var pool2) && TryGetPool<T3>(out var pool3) && TryGetPool<T4>(out var pool4) && TryGetPool<T5>(out var pool5) && TryGetPool<T6>(out var pool6) && TryGetPool<T7>(out var pool7) && TryGetPool<T8>(out var pool8)))
{
return;
}
for (var i = 0; i < pool0.Count; i++)
{
var entity = _entities[i];
if (!(pool1.Has(entity) && pool2.Has(entity) && pool3.Has(entity) && pool4.Has(entity) && pool5.Has(entity) && pool6.Has(entity) && pool7.Has(entity) && pool8.Has(entity)))
{
continue;
}
callback(entity, ref pool0.GetRef(entity), ref pool1.GetRef(entity), ref pool2.GetRef(entity), ref pool3.GetRef(entity), ref pool4.GetRef(entity), ref pool5.GetRef(entity), ref pool6.GetRef(entity), ref pool7.GetRef(entity), ref pool8.GetRef(entity));
}
}
public readonly void Query<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>(QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> callback)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent
{
if (!(TryGetPool<T0>(out var pool0) && TryGetPool<T1>(out var pool1) && TryGetPool<T2>(out var pool2) && TryGetPool<T3>(out var pool3) && TryGetPool<T4>(out var pool4) && TryGetPool<T5>(out var pool5) && TryGetPool<T6>(out var pool6) && TryGetPool<T7>(out var pool7) && TryGetPool<T8>(out var pool8) && TryGetPool<T9>(out var pool9)))
{
return;
}
for (var i = 0; i < pool0.Count; i++)
{
var entity = _entities[i];
if (!(pool1.Has(entity) && pool2.Has(entity) && pool3.Has(entity) && pool4.Has(entity) && pool5.Has(entity) && pool6.Has(entity) && pool7.Has(entity) && pool8.Has(entity) && pool9.Has(entity)))
{
continue;
}
callback(entity, ref pool0.GetRef(entity), ref pool1.GetRef(entity), ref pool2.GetRef(entity), ref pool3.GetRef(entity), ref pool4.GetRef(entity), ref pool5.GetRef(entity), ref pool6.GetRef(entity), ref pool7.GetRef(entity), ref pool8.GetRef(entity), ref pool9.GetRef(entity));
}
}
public readonly void Query<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>(QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> callback)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent
{
if (!(TryGetPool<T0>(out var pool0) && TryGetPool<T1>(out var pool1) && TryGetPool<T2>(out var pool2) && TryGetPool<T3>(out var pool3) && TryGetPool<T4>(out var pool4) && TryGetPool<T5>(out var pool5) && TryGetPool<T6>(out var pool6) && TryGetPool<T7>(out var pool7) && TryGetPool<T8>(out var pool8) && TryGetPool<T9>(out var pool9) && TryGetPool<T10>(out var pool10)))
{
return;
}
for (var i = 0; i < pool0.Count; i++)
{
var entity = _entities[i];
if (!(pool1.Has(entity) && pool2.Has(entity) && pool3.Has(entity) && pool4.Has(entity) && pool5.Has(entity) && pool6.Has(entity) && pool7.Has(entity) && pool8.Has(entity) && pool9.Has(entity) && pool10.Has(entity)))
{
continue;
}
callback(entity, ref pool0.GetRef(entity), ref pool1.GetRef(entity), ref pool2.GetRef(entity), ref pool3.GetRef(entity), ref pool4.GetRef(entity), ref pool5.GetRef(entity), ref pool6.GetRef(entity), ref pool7.GetRef(entity), ref pool8.GetRef(entity), ref pool9.GetRef(entity), ref pool10.GetRef(entity));
}
}
public readonly void Query<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>(QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> callback)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent
{
if (!(TryGetPool<T0>(out var pool0) && TryGetPool<T1>(out var pool1) && TryGetPool<T2>(out var pool2) && TryGetPool<T3>(out var pool3) && TryGetPool<T4>(out var pool4) && TryGetPool<T5>(out var pool5) && TryGetPool<T6>(out var pool6) && TryGetPool<T7>(out var pool7) && TryGetPool<T8>(out var pool8) && TryGetPool<T9>(out var pool9) && TryGetPool<T10>(out var pool10) && TryGetPool<T11>(out var pool11)))
{
return;
}
if (!(_componentStorage.TryGetPool<T0>(out var pool0)))
return default;
for (var i = 0; i < pool0.Count; i++)
{
var entity = _entities[i];
if (!(pool1.Has(entity) && pool2.Has(entity) && pool3.Has(entity) && pool4.Has(entity) && pool5.Has(entity) && pool6.Has(entity) && pool7.Has(entity) && pool8.Has(entity) && pool9.Has(entity) && pool10.Has(entity) && pool11.Has(entity)))
{
continue;
}
callback(entity, ref pool0.GetRef(entity), ref pool1.GetRef(entity), ref pool2.GetRef(entity), ref pool3.GetRef(entity), ref pool4.GetRef(entity), ref pool5.GetRef(entity), ref pool6.GetRef(entity), ref pool7.GetRef(entity), ref pool8.GetRef(entity), ref pool9.GetRef(entity), ref pool10.GetRef(entity), ref pool11.GetRef(entity));
}
}
public readonly void Query<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>(QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> callback)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent where T12 : struct, IComponent
{
if (!(TryGetPool<T0>(out var pool0) && TryGetPool<T1>(out var pool1) && TryGetPool<T2>(out var pool2) && TryGetPool<T3>(out var pool3) && TryGetPool<T4>(out var pool4) && TryGetPool<T5>(out var pool5) && TryGetPool<T6>(out var pool6) && TryGetPool<T7>(out var pool7) && TryGetPool<T8>(out var pool8) && TryGetPool<T9>(out var pool9) && TryGetPool<T10>(out var pool10) && TryGetPool<T11>(out var pool11) && TryGetPool<T12>(out var pool12)))
{
return;
}
for (var i = 0; i < pool0.Count; i++)
{
var entity = _entities[i];
if (!(pool1.Has(entity) && pool2.Has(entity) && pool3.Has(entity) && pool4.Has(entity) && pool5.Has(entity) && pool6.Has(entity) && pool7.Has(entity) && pool8.Has(entity) && pool9.Has(entity) && pool10.Has(entity) && pool11.Has(entity) && pool12.Has(entity)))
{
continue;
}
callback(entity, ref pool0.GetRef(entity), ref pool1.GetRef(entity), ref pool2.GetRef(entity), ref pool3.GetRef(entity), ref pool4.GetRef(entity), ref pool5.GetRef(entity), ref pool6.GetRef(entity), ref pool7.GetRef(entity), ref pool8.GetRef(entity), ref pool9.GetRef(entity), ref pool10.GetRef(entity), ref pool11.GetRef(entity), ref pool12.GetRef(entity));
}
}
public readonly void Query<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> callback)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent where T12 : struct, IComponent where T13 : struct, IComponent
{
if (!(TryGetPool<T0>(out var pool0) && TryGetPool<T1>(out var pool1) && TryGetPool<T2>(out var pool2) && TryGetPool<T3>(out var pool3) && TryGetPool<T4>(out var pool4) && TryGetPool<T5>(out var pool5) && TryGetPool<T6>(out var pool6) && TryGetPool<T7>(out var pool7) && TryGetPool<T8>(out var pool8) && TryGetPool<T9>(out var pool9) && TryGetPool<T10>(out var pool10) && TryGetPool<T11>(out var pool11) && TryGetPool<T12>(out var pool12) && TryGetPool<T13>(out var pool13)))
{
return;
}
for (var i = 0; i < pool0.Count; i++)
{
var entity = _entities[i];
if (!(pool1.Has(entity) && pool2.Has(entity) && pool3.Has(entity) && pool4.Has(entity) && pool5.Has(entity) && pool6.Has(entity) && pool7.Has(entity) && pool8.Has(entity) && pool9.Has(entity) && pool10.Has(entity) && pool11.Has(entity) && pool12.Has(entity) && pool13.Has(entity)))
{
continue;
}
callback(entity, ref pool0.GetRef(entity), ref pool1.GetRef(entity), ref pool2.GetRef(entity), ref pool3.GetRef(entity), ref pool4.GetRef(entity), ref pool5.GetRef(entity), ref pool6.GetRef(entity), ref pool7.GetRef(entity), ref pool8.GetRef(entity), ref pool9.GetRef(entity), ref pool10.GetRef(entity), ref pool11.GetRef(entity), ref pool12.GetRef(entity), ref pool13.GetRef(entity));
}
}
public readonly void Query<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>(QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> callback)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent where T12 : struct, IComponent where T13 : struct, IComponent where T14 : struct, IComponent
{
if (!(TryGetPool<T0>(out var pool0) && TryGetPool<T1>(out var pool1) && TryGetPool<T2>(out var pool2) && TryGetPool<T3>(out var pool3) && TryGetPool<T4>(out var pool4) && TryGetPool<T5>(out var pool5) && TryGetPool<T6>(out var pool6) && TryGetPool<T7>(out var pool7) && TryGetPool<T8>(out var pool8) && TryGetPool<T9>(out var pool9) && TryGetPool<T10>(out var pool10) && TryGetPool<T11>(out var pool11) && TryGetPool<T12>(out var pool12) && TryGetPool<T13>(out var pool13) && TryGetPool<T14>(out var pool14)))
{
return;
}
for (var i = 0; i < pool0.Count; i++)
{
var entity = _entities[i];
if (!(pool1.Has(entity) && pool2.Has(entity) && pool3.Has(entity) && pool4.Has(entity) && pool5.Has(entity) && pool6.Has(entity) && pool7.Has(entity) && pool8.Has(entity) && pool9.Has(entity) && pool10.Has(entity) && pool11.Has(entity) && pool12.Has(entity) && pool13.Has(entity) && pool14.Has(entity)))
{
continue;
}
callback(entity, ref pool0.GetRef(entity), ref pool1.GetRef(entity), ref pool2.GetRef(entity), ref pool3.GetRef(entity), ref pool4.GetRef(entity), ref pool5.GetRef(entity), ref pool6.GetRef(entity), ref pool7.GetRef(entity), ref pool8.GetRef(entity), ref pool9.GetRef(entity), ref pool10.GetRef(entity), ref pool11.GetRef(entity), ref pool12.GetRef(entity), ref pool13.GetRef(entity), ref pool14.GetRef(entity));
}
}
public readonly void Query<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>(QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> callback)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent where T12 : struct, IComponent where T13 : struct, IComponent where T14 : struct, IComponent where T15 : struct, IComponent
{
if (!(TryGetPool<T0>(out var pool0) && TryGetPool<T1>(out var pool1) && TryGetPool<T2>(out var pool2) && TryGetPool<T3>(out var pool3) && TryGetPool<T4>(out var pool4) && TryGetPool<T5>(out var pool5) && TryGetPool<T6>(out var pool6) && TryGetPool<T7>(out var pool7) && TryGetPool<T8>(out var pool8) && TryGetPool<T9>(out var pool9) && TryGetPool<T10>(out var pool10) && TryGetPool<T11>(out var pool11) && TryGetPool<T12>(out var pool12) && TryGetPool<T13>(out var pool13) && TryGetPool<T14>(out var pool14) && TryGetPool<T15>(out var pool15)))
{
return;
}
for (var i = 0; i < pool0.Count; i++)
{
var entity = _entities[i];
if (!(pool1.Has(entity) && pool2.Has(entity) && pool3.Has(entity) && pool4.Has(entity) && pool5.Has(entity) && pool6.Has(entity) && pool7.Has(entity) && pool8.Has(entity) && pool9.Has(entity) && pool10.Has(entity) && pool11.Has(entity) && pool12.Has(entity) && pool13.Has(entity) && pool14.Has(entity) && pool15.Has(entity)))
{
continue;
}
callback(entity, ref pool0.GetRef(entity), ref pool1.GetRef(entity), ref pool2.GetRef(entity), ref pool3.GetRef(entity), ref pool4.GetRef(entity), ref pool5.GetRef(entity), ref pool6.GetRef(entity), ref pool7.GetRef(entity), ref pool8.GetRef(entity), ref pool9.GetRef(entity), ref pool10.GetRef(entity), ref pool11.GetRef(entity), ref pool12.GetRef(entity), ref pool13.GetRef(entity), ref pool14.GetRef(entity), ref pool15.GetRef(entity));
}
}
public readonly void Query<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> callback)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent where T12 : struct, IComponent where T13 : struct, IComponent where T14 : struct, IComponent where T15 : struct, IComponent where T16 : struct, IComponent
{
if (!(TryGetPool<T0>(out var pool0) && TryGetPool<T1>(out var pool1) && TryGetPool<T2>(out var pool2) && TryGetPool<T3>(out var pool3) && TryGetPool<T4>(out var pool4) && TryGetPool<T5>(out var pool5) && TryGetPool<T6>(out var pool6) && TryGetPool<T7>(out var pool7) && TryGetPool<T8>(out var pool8) && TryGetPool<T9>(out var pool9) && TryGetPool<T10>(out var pool10) && TryGetPool<T11>(out var pool11) && TryGetPool<T12>(out var pool12) && TryGetPool<T13>(out var pool13) && TryGetPool<T14>(out var pool14) && TryGetPool<T15>(out var pool15) && TryGetPool<T16>(out var pool16)))
{
return;
}
for (var i = 0; i < pool0.Count; i++)
{
var entity = _entities[i];
if (!(pool1.Has(entity) && pool2.Has(entity) && pool3.Has(entity) && pool4.Has(entity) && pool5.Has(entity) && pool6.Has(entity) && pool7.Has(entity) && pool8.Has(entity) && pool9.Has(entity) && pool10.Has(entity) && pool11.Has(entity) && pool12.Has(entity) && pool13.Has(entity) && pool14.Has(entity) && pool15.Has(entity) && pool16.Has(entity)))
{
continue;
}
callback(entity, ref pool0.GetRef(entity), ref pool1.GetRef(entity), ref pool2.GetRef(entity), ref pool3.GetRef(entity), ref pool4.GetRef(entity), ref pool5.GetRef(entity), ref pool6.GetRef(entity), ref pool7.GetRef(entity), ref pool8.GetRef(entity), ref pool9.GetRef(entity), ref pool10.GetRef(entity), ref pool11.GetRef(entity), ref pool12.GetRef(entity), ref pool13.GetRef(entity), ref pool14.GetRef(entity), ref pool15.GetRef(entity), ref pool16.GetRef(entity));
}
return new QueryEnumerable<T0>(
this,
pool0,
pool0.Count);
}
public readonly void Query<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17>(QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17> callback)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent where T12 : struct, IComponent where T13 : struct, IComponent where T14 : struct, IComponent where T15 : struct, IComponent where T16 : struct, IComponent where T17 : struct, IComponent
public QueryEnumerable<T0, T1> Query<T0, T1>()
where T0 : struct, IComponentData where T1 : struct, IComponentData
{
if (!(TryGetPool<T0>(out var pool0) && TryGetPool<T1>(out var pool1) && TryGetPool<T2>(out var pool2) && TryGetPool<T3>(out var pool3) && TryGetPool<T4>(out var pool4) && TryGetPool<T5>(out var pool5) && TryGetPool<T6>(out var pool6) && TryGetPool<T7>(out var pool7) && TryGetPool<T8>(out var pool8) && TryGetPool<T9>(out var pool9) && TryGetPool<T10>(out var pool10) && TryGetPool<T11>(out var pool11) && TryGetPool<T12>(out var pool12) && TryGetPool<T13>(out var pool13) && TryGetPool<T14>(out var pool14) && TryGetPool<T15>(out var pool15) && TryGetPool<T16>(out var pool16) && TryGetPool<T17>(out var pool17)))
{
return;
}
for (var i = 0; i < pool0.Count; i++)
{
var entity = _entities[i];
if (!(pool1.Has(entity) && pool2.Has(entity) && pool3.Has(entity) && pool4.Has(entity) && pool5.Has(entity) && pool6.Has(entity) && pool7.Has(entity) && pool8.Has(entity) && pool9.Has(entity) && pool10.Has(entity) && pool11.Has(entity) && pool12.Has(entity) && pool13.Has(entity) && pool14.Has(entity) && pool15.Has(entity) && pool16.Has(entity) && pool17.Has(entity)))
{
continue;
}
callback(entity, ref pool0.GetRef(entity), ref pool1.GetRef(entity), ref pool2.GetRef(entity), ref pool3.GetRef(entity), ref pool4.GetRef(entity), ref pool5.GetRef(entity), ref pool6.GetRef(entity), ref pool7.GetRef(entity), ref pool8.GetRef(entity), ref pool9.GetRef(entity), ref pool10.GetRef(entity), ref pool11.GetRef(entity), ref pool12.GetRef(entity), ref pool13.GetRef(entity), ref pool14.GetRef(entity), ref pool15.GetRef(entity), ref pool16.GetRef(entity), ref pool17.GetRef(entity));
}
}
public readonly void Query<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18>(QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18> callback)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent where T12 : struct, IComponent where T13 : struct, IComponent where T14 : struct, IComponent where T15 : struct, IComponent where T16 : struct, IComponent where T17 : struct, IComponent where T18 : struct, IComponent
{
if (!(TryGetPool<T0>(out var pool0) && TryGetPool<T1>(out var pool1) && TryGetPool<T2>(out var pool2) && TryGetPool<T3>(out var pool3) && TryGetPool<T4>(out var pool4) && TryGetPool<T5>(out var pool5) && TryGetPool<T6>(out var pool6) && TryGetPool<T7>(out var pool7) && TryGetPool<T8>(out var pool8) && TryGetPool<T9>(out var pool9) && TryGetPool<T10>(out var pool10) && TryGetPool<T11>(out var pool11) && TryGetPool<T12>(out var pool12) && TryGetPool<T13>(out var pool13) && TryGetPool<T14>(out var pool14) && TryGetPool<T15>(out var pool15) && TryGetPool<T16>(out var pool16) && TryGetPool<T17>(out var pool17) && TryGetPool<T18>(out var pool18)))
{
return;
}
for (var i = 0; i < pool0.Count; i++)
{
var entity = _entities[i];
if (!(pool1.Has(entity) && pool2.Has(entity) && pool3.Has(entity) && pool4.Has(entity) && pool5.Has(entity) && pool6.Has(entity) && pool7.Has(entity) && pool8.Has(entity) && pool9.Has(entity) && pool10.Has(entity) && pool11.Has(entity) && pool12.Has(entity) && pool13.Has(entity) && pool14.Has(entity) && pool15.Has(entity) && pool16.Has(entity) && pool17.Has(entity) && pool18.Has(entity)))
{
continue;
}
if (!(_componentStorage.TryGetPool<T0>(out var pool0) && _componentStorage.TryGetPool<T1>(out var pool1)))
return default;
callback(entity, ref pool0.GetRef(entity), ref pool1.GetRef(entity), ref pool2.GetRef(entity), ref pool3.GetRef(entity), ref pool4.GetRef(entity), ref pool5.GetRef(entity), ref pool6.GetRef(entity), ref pool7.GetRef(entity), ref pool8.GetRef(entity), ref pool9.GetRef(entity), ref pool10.GetRef(entity), ref pool11.GetRef(entity), ref pool12.GetRef(entity), ref pool13.GetRef(entity), ref pool14.GetRef(entity), ref pool15.GetRef(entity), ref pool16.GetRef(entity), ref pool17.GetRef(entity), ref pool18.GetRef(entity));
}
return new QueryEnumerable<T0, T1>(
this,
pool0, pool1,
pool0.Count);
}
public readonly void Query<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19>(QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19> callback)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent where T12 : struct, IComponent where T13 : struct, IComponent where T14 : struct, IComponent where T15 : struct, IComponent where T16 : struct, IComponent where T17 : struct, IComponent where T18 : struct, IComponent where T19 : struct, IComponent
{
if (!(TryGetPool<T0>(out var pool0) && TryGetPool<T1>(out var pool1) && TryGetPool<T2>(out var pool2) && TryGetPool<T3>(out var pool3) && TryGetPool<T4>(out var pool4) && TryGetPool<T5>(out var pool5) && TryGetPool<T6>(out var pool6) && TryGetPool<T7>(out var pool7) && TryGetPool<T8>(out var pool8) && TryGetPool<T9>(out var pool9) && TryGetPool<T10>(out var pool10) && TryGetPool<T11>(out var pool11) && TryGetPool<T12>(out var pool12) && TryGetPool<T13>(out var pool13) && TryGetPool<T14>(out var pool14) && TryGetPool<T15>(out var pool15) && TryGetPool<T16>(out var pool16) && TryGetPool<T17>(out var pool17) && TryGetPool<T18>(out var pool18) && TryGetPool<T19>(out var pool19)))
public QueryEnumerable<T0, T1, T2> Query<T0, T1, T2>()
where T0 : struct, IComponentData where T1 : struct, IComponentData where T2 : struct, IComponentData
{
return;
}
if (!(_componentStorage.TryGetPool<T0>(out var pool0) && _componentStorage.TryGetPool<T1>(out var pool1) && _componentStorage.TryGetPool<T2>(out var pool2)))
return default;
for (var i = 0; i < pool0.Count; i++)
{
var entity = _entities[i];
if (!(pool1.Has(entity) && pool2.Has(entity) && pool3.Has(entity) && pool4.Has(entity) && pool5.Has(entity) && pool6.Has(entity) && pool7.Has(entity) && pool8.Has(entity) && pool9.Has(entity) && pool10.Has(entity) && pool11.Has(entity) && pool12.Has(entity) && pool13.Has(entity) && pool14.Has(entity) && pool15.Has(entity) && pool16.Has(entity) && pool17.Has(entity) && pool18.Has(entity) && pool19.Has(entity)))
{
continue;
return new QueryEnumerable<T0, T1, T2>(
this,
pool0, pool1, pool2,
pool0.Count);
}
callback(entity, ref pool0.GetRef(entity), ref pool1.GetRef(entity), ref pool2.GetRef(entity), ref pool3.GetRef(entity), ref pool4.GetRef(entity), ref pool5.GetRef(entity), ref pool6.GetRef(entity), ref pool7.GetRef(entity), ref pool8.GetRef(entity), ref pool9.GetRef(entity), ref pool10.GetRef(entity), ref pool11.GetRef(entity), ref pool12.GetRef(entity), ref pool13.GetRef(entity), ref pool14.GetRef(entity), ref pool15.GetRef(entity), ref pool16.GetRef(entity), ref pool17.GetRef(entity), ref pool18.GetRef(entity), ref pool19.GetRef(entity));
}
}
public readonly void Query<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20>(QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20> callback)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent where T12 : struct, IComponent where T13 : struct, IComponent where T14 : struct, IComponent where T15 : struct, IComponent where T16 : struct, IComponent where T17 : struct, IComponent where T18 : struct, IComponent where T19 : struct, IComponent where T20 : struct, IComponent
{
if (!(TryGetPool<T0>(out var pool0) && TryGetPool<T1>(out var pool1) && TryGetPool<T2>(out var pool2) && TryGetPool<T3>(out var pool3) && TryGetPool<T4>(out var pool4) && TryGetPool<T5>(out var pool5) && TryGetPool<T6>(out var pool6) && TryGetPool<T7>(out var pool7) && TryGetPool<T8>(out var pool8) && TryGetPool<T9>(out var pool9) && TryGetPool<T10>(out var pool10) && TryGetPool<T11>(out var pool11) && TryGetPool<T12>(out var pool12) && TryGetPool<T13>(out var pool13) && TryGetPool<T14>(out var pool14) && TryGetPool<T15>(out var pool15) && TryGetPool<T16>(out var pool16) && TryGetPool<T17>(out var pool17) && TryGetPool<T18>(out var pool18) && TryGetPool<T19>(out var pool19) && TryGetPool<T20>(out var pool20)))
{
return;
}
for (var i = 0; i < pool0.Count; i++)
{
var entity = _entities[i];
if (!(pool1.Has(entity) && pool2.Has(entity) && pool3.Has(entity) && pool4.Has(entity) && pool5.Has(entity) && pool6.Has(entity) && pool7.Has(entity) && pool8.Has(entity) && pool9.Has(entity) && pool10.Has(entity) && pool11.Has(entity) && pool12.Has(entity) && pool13.Has(entity) && pool14.Has(entity) && pool15.Has(entity) && pool16.Has(entity) && pool17.Has(entity) && pool18.Has(entity) && pool19.Has(entity) && pool20.Has(entity)))
public QueryEnumerable<T0, T1, T2, T3> Query<T0, T1, T2, T3>()
where T0 : struct, IComponentData where T1 : struct, IComponentData where T2 : struct, IComponentData where T3 : struct, IComponentData
{
continue;
}
if (!(_componentStorage.TryGetPool<T0>(out var pool0) && _componentStorage.TryGetPool<T1>(out var pool1) && _componentStorage.TryGetPool<T2>(out var pool2) && _componentStorage.TryGetPool<T3>(out var pool3)))
return default;
callback(entity, ref pool0.GetRef(entity), ref pool1.GetRef(entity), ref pool2.GetRef(entity), ref pool3.GetRef(entity), ref pool4.GetRef(entity), ref pool5.GetRef(entity), ref pool6.GetRef(entity), ref pool7.GetRef(entity), ref pool8.GetRef(entity), ref pool9.GetRef(entity), ref pool10.GetRef(entity), ref pool11.GetRef(entity), ref pool12.GetRef(entity), ref pool13.GetRef(entity), ref pool14.GetRef(entity), ref pool15.GetRef(entity), ref pool16.GetRef(entity), ref pool17.GetRef(entity), ref pool18.GetRef(entity), ref pool19.GetRef(entity), ref pool20.GetRef(entity));
}
return new QueryEnumerable<T0, T1, T2, T3>(
this,
pool0, pool1, pool2, pool3,
pool0.Count);
}
public readonly void Query<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21>(QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21> callback)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent where T12 : struct, IComponent where T13 : struct, IComponent where T14 : struct, IComponent where T15 : struct, IComponent where T16 : struct, IComponent where T17 : struct, IComponent where T18 : struct, IComponent where T19 : struct, IComponent where T20 : struct, IComponent where T21 : struct, IComponent
public QueryEnumerable<T0, T1, T2, T3, T4> Query<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
{
if (!(TryGetPool<T0>(out var pool0) && TryGetPool<T1>(out var pool1) && TryGetPool<T2>(out var pool2) && TryGetPool<T3>(out var pool3) && TryGetPool<T4>(out var pool4) && TryGetPool<T5>(out var pool5) && TryGetPool<T6>(out var pool6) && TryGetPool<T7>(out var pool7) && TryGetPool<T8>(out var pool8) && TryGetPool<T9>(out var pool9) && TryGetPool<T10>(out var pool10) && TryGetPool<T11>(out var pool11) && TryGetPool<T12>(out var pool12) && TryGetPool<T13>(out var pool13) && TryGetPool<T14>(out var pool14) && TryGetPool<T15>(out var pool15) && TryGetPool<T16>(out var pool16) && TryGetPool<T17>(out var pool17) && TryGetPool<T18>(out var pool18) && TryGetPool<T19>(out var pool19) && TryGetPool<T20>(out var pool20) && TryGetPool<T21>(out var pool21)))
{
return;
}
if (!(_componentStorage.TryGetPool<T0>(out var pool0) && _componentStorage.TryGetPool<T1>(out var pool1) && _componentStorage.TryGetPool<T2>(out var pool2) && _componentStorage.TryGetPool<T3>(out var pool3) && _componentStorage.TryGetPool<T4>(out var pool4)))
return default;
for (var i = 0; i < pool0.Count; i++)
{
var entity = _entities[i];
if (!(pool1.Has(entity) && pool2.Has(entity) && pool3.Has(entity) && pool4.Has(entity) && pool5.Has(entity) && pool6.Has(entity) && pool7.Has(entity) && pool8.Has(entity) && pool9.Has(entity) && pool10.Has(entity) && pool11.Has(entity) && pool12.Has(entity) && pool13.Has(entity) && pool14.Has(entity) && pool15.Has(entity) && pool16.Has(entity) && pool17.Has(entity) && pool18.Has(entity) && pool19.Has(entity) && pool20.Has(entity) && pool21.Has(entity)))
{
continue;
return new QueryEnumerable<T0, T1, T2, T3, T4>(
this,
pool0, pool1, pool2, pool3, pool4,
pool0.Count);
}
callback(entity, ref pool0.GetRef(entity), ref pool1.GetRef(entity), ref pool2.GetRef(entity), ref pool3.GetRef(entity), ref pool4.GetRef(entity), ref pool5.GetRef(entity), ref pool6.GetRef(entity), ref pool7.GetRef(entity), ref pool8.GetRef(entity), ref pool9.GetRef(entity), ref pool10.GetRef(entity), ref pool11.GetRef(entity), ref pool12.GetRef(entity), ref pool13.GetRef(entity), ref pool14.GetRef(entity), ref pool15.GetRef(entity), ref pool16.GetRef(entity), ref pool17.GetRef(entity), ref pool18.GetRef(entity), ref pool19.GetRef(entity), ref pool20.GetRef(entity), ref pool21.GetRef(entity));
}
}
public readonly void Query<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22>(QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22> callback)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent where T12 : struct, IComponent where T13 : struct, IComponent where T14 : struct, IComponent where T15 : struct, IComponent where T16 : struct, IComponent where T17 : struct, IComponent where T18 : struct, IComponent where T19 : struct, IComponent where T20 : struct, IComponent where T21 : struct, IComponent where T22 : struct, IComponent
{
if (!(TryGetPool<T0>(out var pool0) && TryGetPool<T1>(out var pool1) && TryGetPool<T2>(out var pool2) && TryGetPool<T3>(out var pool3) && TryGetPool<T4>(out var pool4) && TryGetPool<T5>(out var pool5) && TryGetPool<T6>(out var pool6) && TryGetPool<T7>(out var pool7) && TryGetPool<T8>(out var pool8) && TryGetPool<T9>(out var pool9) && TryGetPool<T10>(out var pool10) && TryGetPool<T11>(out var pool11) && TryGetPool<T12>(out var pool12) && TryGetPool<T13>(out var pool13) && TryGetPool<T14>(out var pool14) && TryGetPool<T15>(out var pool15) && TryGetPool<T16>(out var pool16) && TryGetPool<T17>(out var pool17) && TryGetPool<T18>(out var pool18) && TryGetPool<T19>(out var pool19) && TryGetPool<T20>(out var pool20) && TryGetPool<T21>(out var pool21) && TryGetPool<T22>(out var pool22)))
public QueryEnumerable<T0, T1, T2, T3, T4, T5> Query<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
{
return;
}
for (var i = 0; i < pool0.Count; i++)
{
var entity = _entities[i];
if (!(pool1.Has(entity) && pool2.Has(entity) && pool3.Has(entity) && pool4.Has(entity) && pool5.Has(entity) && pool6.Has(entity) && pool7.Has(entity) && pool8.Has(entity) && pool9.Has(entity) && pool10.Has(entity) && pool11.Has(entity) && pool12.Has(entity) && pool13.Has(entity) && pool14.Has(entity) && pool15.Has(entity) && pool16.Has(entity) && pool17.Has(entity) && pool18.Has(entity) && pool19.Has(entity) && pool20.Has(entity) && pool21.Has(entity) && pool22.Has(entity)))
{
continue;
}
if (!(_componentStorage.TryGetPool<T0>(out var pool0) && _componentStorage.TryGetPool<T1>(out var pool1) && _componentStorage.TryGetPool<T2>(out var pool2) && _componentStorage.TryGetPool<T3>(out var pool3) && _componentStorage.TryGetPool<T4>(out var pool4) && _componentStorage.TryGetPool<T5>(out var pool5)))
return default;
callback(entity, ref pool0.GetRef(entity), ref pool1.GetRef(entity), ref pool2.GetRef(entity), ref pool3.GetRef(entity), ref pool4.GetRef(entity), ref pool5.GetRef(entity), ref pool6.GetRef(entity), ref pool7.GetRef(entity), ref pool8.GetRef(entity), ref pool9.GetRef(entity), ref pool10.GetRef(entity), ref pool11.GetRef(entity), ref pool12.GetRef(entity), ref pool13.GetRef(entity), ref pool14.GetRef(entity), ref pool15.GetRef(entity), ref pool16.GetRef(entity), ref pool17.GetRef(entity), ref pool18.GetRef(entity), ref pool19.GetRef(entity), ref pool20.GetRef(entity), ref pool21.GetRef(entity), ref pool22.GetRef(entity));
}
}
public readonly void Query<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23>(QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23> callback)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent where T12 : struct, IComponent where T13 : struct, IComponent where T14 : struct, IComponent where T15 : struct, IComponent where T16 : struct, IComponent where T17 : struct, IComponent where T18 : struct, IComponent where T19 : struct, IComponent where T20 : struct, IComponent where T21 : struct, IComponent where T22 : struct, IComponent where T23 : struct, IComponent
{
if (!(TryGetPool<T0>(out var pool0) && TryGetPool<T1>(out var pool1) && TryGetPool<T2>(out var pool2) && TryGetPool<T3>(out var pool3) && TryGetPool<T4>(out var pool4) && TryGetPool<T5>(out var pool5) && TryGetPool<T6>(out var pool6) && TryGetPool<T7>(out var pool7) && TryGetPool<T8>(out var pool8) && TryGetPool<T9>(out var pool9) && TryGetPool<T10>(out var pool10) && TryGetPool<T11>(out var pool11) && TryGetPool<T12>(out var pool12) && TryGetPool<T13>(out var pool13) && TryGetPool<T14>(out var pool14) && TryGetPool<T15>(out var pool15) && TryGetPool<T16>(out var pool16) && TryGetPool<T17>(out var pool17) && TryGetPool<T18>(out var pool18) && TryGetPool<T19>(out var pool19) && TryGetPool<T20>(out var pool20) && TryGetPool<T21>(out var pool21) && TryGetPool<T22>(out var pool22) && TryGetPool<T23>(out var pool23)))
{
return;
return new QueryEnumerable<T0, T1, T2, T3, T4, T5>(
this,
pool0, pool1, pool2, pool3, pool4, pool5,
pool0.Count);
}
for (var i = 0; i < pool0.Count; i++)
{
var entity = _entities[i];
if (!(pool1.Has(entity) && pool2.Has(entity) && pool3.Has(entity) && pool4.Has(entity) && pool5.Has(entity) && pool6.Has(entity) && pool7.Has(entity) && pool8.Has(entity) && pool9.Has(entity) && pool10.Has(entity) && pool11.Has(entity) && pool12.Has(entity) && pool13.Has(entity) && pool14.Has(entity) && pool15.Has(entity) && pool16.Has(entity) && pool17.Has(entity) && pool18.Has(entity) && pool19.Has(entity) && pool20.Has(entity) && pool21.Has(entity) && pool22.Has(entity) && pool23.Has(entity)))
public QueryEnumerable<T0, T1, T2, T3, T4, T5, T6> Query<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
{
continue;
}
if (!(_componentStorage.TryGetPool<T0>(out var pool0) && _componentStorage.TryGetPool<T1>(out var pool1) && _componentStorage.TryGetPool<T2>(out var pool2) && _componentStorage.TryGetPool<T3>(out var pool3) && _componentStorage.TryGetPool<T4>(out var pool4) && _componentStorage.TryGetPool<T5>(out var pool5) && _componentStorage.TryGetPool<T6>(out var pool6)))
return default;
callback(entity, ref pool0.GetRef(entity), ref pool1.GetRef(entity), ref pool2.GetRef(entity), ref pool3.GetRef(entity), ref pool4.GetRef(entity), ref pool5.GetRef(entity), ref pool6.GetRef(entity), ref pool7.GetRef(entity), ref pool8.GetRef(entity), ref pool9.GetRef(entity), ref pool10.GetRef(entity), ref pool11.GetRef(entity), ref pool12.GetRef(entity), ref pool13.GetRef(entity), ref pool14.GetRef(entity), ref pool15.GetRef(entity), ref pool16.GetRef(entity), ref pool17.GetRef(entity), ref pool18.GetRef(entity), ref pool19.GetRef(entity), ref pool20.GetRef(entity), ref pool21.GetRef(entity), ref pool22.GetRef(entity), ref pool23.GetRef(entity));
}
return new QueryEnumerable<T0, T1, T2, T3, T4, T5, T6>(
this,
pool0, pool1, pool2, pool3, pool4, pool5, pool6,
pool0.Count);
}
public readonly void Query<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24>(QueryRefComponent<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24> callback)
where T0 : struct, IComponent where T1 : struct, IComponent where T2 : struct, IComponent where T3 : struct, IComponent where T4 : struct, IComponent where T5 : struct, IComponent where T6 : struct, IComponent where T7 : struct, IComponent where T8 : struct, IComponent where T9 : struct, IComponent where T10 : struct, IComponent where T11 : struct, IComponent where T12 : struct, IComponent where T13 : struct, IComponent where T14 : struct, IComponent where T15 : struct, IComponent where T16 : struct, IComponent where T17 : struct, IComponent where T18 : struct, IComponent where T19 : struct, IComponent where T20 : struct, IComponent where T21 : struct, IComponent where T22 : struct, IComponent where T23 : struct, IComponent where T24 : struct, IComponent
public QueryEnumerable<T0, T1, T2, T3, T4, T5, T6, T7> Query<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
{
if (!(TryGetPool<T0>(out var pool0) && TryGetPool<T1>(out var pool1) && TryGetPool<T2>(out var pool2) && TryGetPool<T3>(out var pool3) && TryGetPool<T4>(out var pool4) && TryGetPool<T5>(out var pool5) && TryGetPool<T6>(out var pool6) && TryGetPool<T7>(out var pool7) && TryGetPool<T8>(out var pool8) && TryGetPool<T9>(out var pool9) && TryGetPool<T10>(out var pool10) && TryGetPool<T11>(out var pool11) && TryGetPool<T12>(out var pool12) && TryGetPool<T13>(out var pool13) && TryGetPool<T14>(out var pool14) && TryGetPool<T15>(out var pool15) && TryGetPool<T16>(out var pool16) && TryGetPool<T17>(out var pool17) && TryGetPool<T18>(out var pool18) && TryGetPool<T19>(out var pool19) && TryGetPool<T20>(out var pool20) && TryGetPool<T21>(out var pool21) && TryGetPool<T22>(out var pool22) && TryGetPool<T23>(out var pool23) && TryGetPool<T24>(out var pool24)))
{
return;
}
if (!(_componentStorage.TryGetPool<T0>(out var pool0) && _componentStorage.TryGetPool<T1>(out var pool1) && _componentStorage.TryGetPool<T2>(out var pool2) && _componentStorage.TryGetPool<T3>(out var pool3) && _componentStorage.TryGetPool<T4>(out var pool4) && _componentStorage.TryGetPool<T5>(out var pool5) && _componentStorage.TryGetPool<T6>(out var pool6) && _componentStorage.TryGetPool<T7>(out var pool7)))
return default;
for (var i = 0; i < pool0.Count; i++)
{
var entity = _entities[i];
if (!(pool1.Has(entity) && pool2.Has(entity) && pool3.Has(entity) && pool4.Has(entity) && pool5.Has(entity) && pool6.Has(entity) && pool7.Has(entity) && pool8.Has(entity) && pool9.Has(entity) && pool10.Has(entity) && pool11.Has(entity) && pool12.Has(entity) && pool13.Has(entity) && pool14.Has(entity) && pool15.Has(entity) && pool16.Has(entity) && pool17.Has(entity) && pool18.Has(entity) && pool19.Has(entity) && pool20.Has(entity) && pool21.Has(entity) && pool22.Has(entity) && pool23.Has(entity) && pool24.Has(entity)))
{
continue;
}
callback(entity, ref pool0.GetRef(entity), ref pool1.GetRef(entity), ref pool2.GetRef(entity), ref pool3.GetRef(entity), ref pool4.GetRef(entity), ref pool5.GetRef(entity), ref pool6.GetRef(entity), ref pool7.GetRef(entity), ref pool8.GetRef(entity), ref pool9.GetRef(entity), ref pool10.GetRef(entity), ref pool11.GetRef(entity), ref pool12.GetRef(entity), ref pool13.GetRef(entity), ref pool14.GetRef(entity), ref pool15.GetRef(entity), ref pool16.GetRef(entity), ref pool17.GetRef(entity), ref pool18.GetRef(entity), ref pool19.GetRef(entity), ref pool20.GetRef(entity), ref pool21.GetRef(entity), ref pool22.GetRef(entity), ref pool23.GetRef(entity), ref pool24.GetRef(entity));
}
return new QueryEnumerable<T0, T1, T2, T3, T4, T5, T6, T7>(
this,
pool0, pool1, pool2, pool3, pool4, pool5, pool6, pool7,
pool0.Count);
}
}

View File

@@ -1,48 +1,34 @@
<#@ template language="C#" #>
<#@ output extension=".cs" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ include file="Helpers.ttinclude" #>
namespace Ghost.Entities;
public partial struct World
public partial class World
{
<#
for (var index = 1; index <= Amount; index++)
{
<# for (var index = 1; index <= Amount; index++) {
var generics = AppendGenerics(index);
var restrictions = AppendGenericRestrictions(index, "struct, IComponent");
var getPools = TryGetComponentPools(index);
var hasEntity = HasEntity(index);
var restrictions = AppendGenericRestrictions(index, "struct, IComponentData");
var tryGetPools = TryGetComponentPools(index);
var poolParams = Enumerable.Range(0, index)
.Select(i => $"pool{i}")
.Aggregate((a,b)=> a + ", " + b);
var countSource = "pool0.Count";
#>
public readonly void Query<<#= generics #>>(QueryRefComponent<<#= generics #>> callback)
<#= restrictions.ToString() #>
public QueryEnumerable<<#= generics #>> Query<<#= generics #>>()
<#= restrictions #>
{
if (!(<#=getPools.ToString()#>))
{
return;
if (!(<#= tryGetPools #>))
return default;
return new QueryEnumerable<<#= generics #>>(
this,
<#= poolParams #>,
<#= countSource #>);
}
for (var i = 0; i < pool0.Count; i++)
{
var entity = _entities[i];
<#
if (index > 1)
{
#>
if (!(<#=hasEntity.ToString()#>))
{
continue;
}
<#
}
#>
callback(entity, <#= GetComponentRef(index).ToString() #>);
}
}
<#
}
#>
<# } #>
}

View File

@@ -0,0 +1,19 @@
namespace Ghost.Entities.Utilities;
internal class Box<T>
where T : struct
{
public T Value
{
get;
set;
}
public Box(T value)
{
Value = value;
}
public static implicit operator T(Box<T> box) => box.Value;
public static implicit operator Box<T>(T value) => new(value);
}

View File

@@ -0,0 +1,64 @@
using System.Numerics;
namespace Ghost.Entities.Utilities;
internal readonly struct ComponentMask
{
private readonly ulong[] _words;
public ComponentMask(int entityCapacity)
{
_words = new ulong[(entityCapacity + 63) / 64];
}
public void Set(int entityIndex)
=> _words[entityIndex >> 6] |= 1UL << (entityIndex & 63);
public void Clear(int entityIndex)
=> _words[entityIndex >> 6] &= ~(1UL << (entityIndex & 63));
public bool Get(int entityIndex)
=> ((_words[entityIndex >> 6] >> (entityIndex & 63)) & 1) != 0;
// Bitwise AND
public ComponentMask And(in ComponentMask other)
{
var result = new ComponentMask(_words.Length * 64);
for (var i = 0; i < _words.Length; i++)
result._words[i] = _words[i] & other._words[i];
return result;
}
// Bitwise OR
public ComponentMask Or(in ComponentMask other)
{
var result = new ComponentMask(_words.Length * 64);
for (var i = 0; i < _words.Length; i++)
result._words[i] = _words[i] | other._words[i];
return result;
}
// Bitwise NOT
public ComponentMask Not()
{
var result = new ComponentMask(_words.Length * 64);
for (var i = 0; i < _words.Length; i++)
result._words[i] = ~_words[i];
return result;
}
// Iterate set bits (fast scan)
public IEnumerable<int> GetEntityIndices()
{
for (var word = 0; word < _words.Length; word++)
{
var bits = _words[word];
while (bits != 0)
{
var lowBit = BitOperations.TrailingZeroCount(bits);
yield return (word << 6) + lowBit;
bits &= bits - 1; // clear lowest set bit
}
}
}
}

View File

@@ -0,0 +1,6 @@
namespace Ghost.Entities.Utilities;
internal static class TypeHandle<T>
{
public static nint Value => typeof(T).TypeHandle.Value;
}

View File

@@ -1,103 +1,103 @@
using System.Diagnostics.CodeAnalysis;
using Ghost.Entities.Query;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Ghost.Entities;
public partial struct World : IDisposable
// TODO: Archetype system for better performance
public partial class World
{
private static int _nextWorldIndex = 0;
private static List<World> s_worlds = new(2);
private static Queue<WorldID> s_freeWorldSlots = new();
private readonly int _worldIndex;
private static int s_maxWorldCount = (int)MathF.Pow(2, Entity.WORLD_INDEX_BITS);
private List<Entity> _entities;
private readonly Stack<EntityID> _freeSlots;
private readonly Dictionary<Type, object> _pools;
public World()
public static World Create(int entityCapacity = 16)
{
_worldIndex = _nextWorldIndex++;
_entities = new List<Entity>();
_freeSlots = new Stack<int>();
_pools = new();
}
public readonly Entity CreateEntity()
lock (s_worlds)
{
if (_freeSlots.Count > 0)
if (s_freeWorldSlots.TryDequeue(out var index))
{
var index = _freeSlots.Pop();
return _entities[index];
s_worlds[index] = new World(index, entityCapacity);
}
else
{
var index = _entities.Count;
var entity = new Entity(index, 0, _worldIndex);
_entities.Add(entity);
return entity;
}
}
public readonly void RemoveEntity(Entity e)
if (s_worlds.Count >= s_maxWorldCount)
{
if (e.ID >= _entities.Count || _entities[e.ID].Generation != e.Generation)
{
return;
throw new InvalidOperationException("Maximum number of worlds reached");
}
var entity = _entities[e.ID];
entity.IncrementGeneration();
_entities[e.ID] = entity;
_freeSlots.Push(e.ID);
index = (WorldID)s_worlds.Count;
s_worlds.Add(new World(index, entityCapacity));
}
public void AddComponent<T>(Entity entity, T component) where T : struct, IComponent
=> GetOrCreatePool<T>().Add(entity, component);
public void SetComponent<T>(Entity entity, T component) where T : struct, IComponent
=> GetOrCreatePool<T>().Set(entity, component);
public bool HasComponent<T>(Entity entity) where T : struct, IComponent
=> GetOrCreatePool<T>().Has(entity);
private readonly bool TryGetPool<T>([MaybeNullWhen(false)] out ComponentPool<T> pool)
where T : struct, IComponent
{
var type = typeof(T);
if (_pools.TryGetValue(type, out var obj))
{
pool = (ComponentPool<T>)obj;
return true;
}
pool = null;
return false;
}
private readonly ComponentPool<T> GetOrCreatePool<T>()
where T : struct, IComponent
{
var type = typeof(T);
if (!_pools.TryGetValue(type, out var obj))
{
var pool = new ComponentPool<T>();
_pools[type] = pool;
return pool;
}
return (ComponentPool<T>)obj;
}
public readonly void Dispose()
{
foreach (var pool in _pools.Values)
{
if (pool is IDisposable disposablePool)
{
disposablePool.Dispose();
return s_worlds[index];
}
}
_pools.Clear();
_freeSlots.Clear();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static World GetWorld(int index)
{
return s_worlds[index];
}
}
public partial class World : IDisposable
{
private readonly WorldID _id;
private readonly EntityManager _entityManager;
internal readonly ComponentStorage _componentStorage;
internal readonly SystemStorage _systemStorage;
public WorldID ID => _id;
public EntityManager EntityManager => _entityManager;
private World(WorldID id, int entityCapacity)
{
_id = id;
_entityManager = new EntityManager(this, entityCapacity);
_componentStorage = new ComponentStorage();
_systemStorage = new SystemStorage();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddSystem<T>()
where T : SystemBase, new()
{
var instance = new T
{
World = this
};
_systemStorage.AddSystem(instance);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Ref<T> GetSingleton<T>()
where T : struct, IComponentData
{
ref var component = ref CollectionsMarshal.GetValueRefOrAddDefault(SingletonContainer<T>.container, _id, out _);
return new Ref<T>(ref component);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IEnumerable<ScriptComponent> QueryScript()
{
if (_componentStorage.ScriptComponentPool.IsInitialized)
{
return _componentStorage.ScriptComponentPool.ExecutionList!;
}
return Enumerable.Empty<ScriptComponent>();
}
public void Dispose()
{
_entityManager.Dispose();
_componentStorage.Dispose();
_systemStorage.Dispose();
s_freeWorldSlots.Enqueue(_id);
}
}

View File

@@ -13,4 +13,10 @@
<ProjectReference Include="..\Ghost.Entities\Ghost.Entities.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="Misaki.HighPerformance.Unsafe">
<HintPath>..\..\Class\Misaki.HighPerformance\Misaki.HighPerformance.Unsafe\bin\Release\net9.0\Misaki.HighPerformance.Unsafe.dll</HintPath>
</Reference>
</ItemGroup>
</Project>

View File

@@ -1,48 +1,167 @@
using Ghost.Entities;
using Ghost.Entities.Helpers;
using System.Numerics;
var world = new World();
var t = new Test();
t.Run();
var entity1 = world.CreateEntity();
var entity2 = world.CreateEntity();
var entity3 = world.CreateEntity();
world.AddComponent(entity1, new Transform { position = new Vector3(1, 2, 3) });
world.AddComponent(entity1, new Mesh { index = 42 });
world.AddComponent(entity2, new Transform { position = new Vector3(4, 5, 6) });
world.AddComponent(entity2, new Mesh { index = 43 });
world.AddComponent(entity3, new Transform { position = new Vector3(7, 8, 9) });
world.Query<Transform>((Entity entity, ref Transform transform) =>
public partial class Test
{
transform.position += new Vector3(1, 1, 1);
});
public void Run()
{
var world = World.Create();
world.Query<Mesh>((Entity entity, ref Mesh mesh) =>
var entity1 = world.EntityManager.CreateEntity();
var entity2 = world.EntityManager.CreateEntity();
var entity3 = world.EntityManager.CreateEntity();
entity1.AddComponent(new Transform { position = new Vector3(1, 2, 3) });
entity1.AddComponent(new Mesh { index = 42 });
entity1.AddScript<UIManager>();
entity1.AddScript<EventManager>();
entity2.AddComponent(new Transform { position = new Vector3(4, 5, 6) });
entity2.AddComponent(new Mesh { index = 43 });
entity2.AddScript<UserScript>();
entity3.AddComponent(new Transform { position = new Vector3(7, 8, 9) });
entity3.AddScript<EventManager>();
foreach (var (_, transform) in world.Query<Transform>())
{
transform.ValueRW.position += new Vector3(1, 1, 1);
}
foreach (var (_, mesh) in world.Query<Mesh>())
{
mesh.ValueRW.index += 1;
}
world.EntityManager.RemoveEntity(ref entity2);
var entity4 = world.EntityManager.CreateEntity();
entity4.AddComponent(new Transform { position = new Vector3(10, 11, 12) });
entity4.AddComponent(new Mesh { index = 44 });
entity4.AddScript<UserScript>();
world.AddSystem<TestSystem>();
world._systemStorage.UpdateSystems();
//world.SystemStorage.RebuildExecutionList();
//world.ComponentStorage.RebuildExecutionList();
//Console.WriteLine();
//Console.WriteLine("Starting scripts...");
//foreach (var component in world.QueryScript())
//{
// if (!component.Enable)
// {
// continue;
// }
// component.Start();
//}
//Console.WriteLine();
//Console.WriteLine("Updating scripts...");
//foreach (var component in world.QueryScript())
//{
// if (!component.Enable)
// {
// continue;
// }
// component.Update();
//}
//Console.WriteLine();
//Console.WriteLine("LateUpdating scripts...");
//foreach (var component in world.QueryScript())
//{
// if (!component.Enable)
// {
// continue;
// }
// component.LateUpdate();
//}
world.Dispose();
}
}
public class TestSystem : SystemBase
{
mesh.index += 1;
});
public override void OnUpdate()
{
foreach (var (entity, transform) in World.Query<Transform>().WithAny<Mesh>())
{
Console.WriteLine($"Entity {entity.ID}: Transform Position = {transform.ValueRO.position}");
}
}
}
world.RemoveEntity(entity2);
var entity4 = world.CreateEntity();
world.AddComponent(entity4, new Transform { position = new Vector3(10, 11, 12) });
world.AddComponent(entity4, new Mesh { index = 44 });
world.Query<Transform, Mesh>((Entity entity, ref Transform transform, ref Mesh mesh) =>
{
Console.WriteLine($"Entity {entity.ID}: Transform Position = {transform.position}, Mesh Index = {mesh.index}");
});
world.Dispose();
public struct Transform : IComponent
public struct Transform : IComponentData
{
public Vector3 position;
public Quaternion rotation;
public Vector3 scale;
}
public struct Mesh : IComponent
public struct Mesh : IComponentData
{
public uint index;
}
public class UserScript : ScriptComponent
{
public override int ExecutionOrder => -1;
public override void Start()
{
Console.WriteLine("UserScript started for entity: " + Owner.ID);
}
public override void Update()
{
Console.WriteLine("UserScript updating for entity: " + Owner.ID);
}
public override void OnDestroy()
{
Console.WriteLine("UserScript destroyed for entity: " + Owner.ID);
}
}
public class UIManager : ScriptComponent
{
public override void Start()
{
Console.WriteLine("UIManager started for entity: " + Owner.ID);
}
public override void Update()
{
Console.WriteLine("UIManager updating for entity: " + Owner.ID);
}
public override void OnDestroy()
{
Console.WriteLine("UIManager destroyed for entity: " + Owner.ID);
}
}
public class EventManager : ScriptComponent
{
public override void Start()
{
Console.WriteLine("EventManager started for entity: " + Owner.ID);
}
public override void Update()
{
Console.WriteLine("EventManager updating for entity: " + Owner.ID);
}
public override void OnDestroy()
{
Console.WriteLine("EventManager destroyed for entity: " + Owner.ID);
}
}