Add component editors and UI controls
Added the `HierarchyEditor` and `LocalToWorldEditor` classes to implement custom component editing functionality. Added the `Vector3Field` control for 3D vector manipulation and its corresponding XAML definition. Added the `ComponentDataView` and `ComponentObject` classes to manage component data display and access. Added the `CustomEditorAttribute` to mark classes as custom editors for specific components. Changed the `IInspectable` interface to use properties for `Icon`, `HeaderContent`, and `InspectorContent`. Changed the `PropertyField` class to enhance UI control binding capabilities. Changed the `EditorWorldManager` to improve world data loading and deserialization processes. Changed the `EntityNode` and `WorldNode` classes to update entity construction and component querying. Changed the `StaticResource` class to include new binding flags for component properties. Changed the `InspectorService` to remove old contract references and adopt new interfaces. Changed the `QueryEnumerable` and related files to update generic constraints for improved type safety. Changed the `QueryItem` class to reflect new generic constraints and enhance deconstruction. Changed the `World.Query` methods to utilize the updated generic constraints. Updated the `SerializationTest` to align with new entity creation and management practices.
This commit is contained in:
@@ -2,11 +2,12 @@
|
||||
using Misaki.HighPerformance.Unsafe.Collections;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ghost.Entities.Components;
|
||||
|
||||
internal static class SingletonContainer<T>
|
||||
where T : struct, IComponentData
|
||||
where T : unmanaged, IComponentData
|
||||
{
|
||||
public static readonly Dictionary<int, T> container = new();
|
||||
}
|
||||
@@ -22,6 +23,7 @@ internal interface IComponentPool : IDisposable
|
||||
public bool Remove(Entity entity);
|
||||
public bool Has(Entity entity);
|
||||
public IComponentData Get(Entity entity);
|
||||
public IntPtr GetUnsafe(Entity entity);
|
||||
public void Set(Entity entity, in IComponentData component);
|
||||
|
||||
public IEnumerable<(Entity entity, IComponentData component)> Enumerate();
|
||||
@@ -35,7 +37,7 @@ internal interface IComponentPool<T> : IComponentPool
|
||||
}
|
||||
|
||||
internal class ComponentPool<T> : IComponentPool<T>
|
||||
where T : struct, IComponentData
|
||||
where T : unmanaged, IComponentData
|
||||
{
|
||||
private struct ComponentData
|
||||
{
|
||||
@@ -142,6 +144,11 @@ internal class ComponentPool<T> : IComponentPool<T>
|
||||
return GetRef(entity);
|
||||
}
|
||||
|
||||
public unsafe IntPtr GetUnsafe(Entity entity)
|
||||
{
|
||||
return (IntPtr)Unsafe.AsPointer(ref GetRef(entity));
|
||||
}
|
||||
|
||||
public ref T GetRef(Entity entity)
|
||||
{
|
||||
if (!entity.IsValid)
|
||||
@@ -341,7 +348,29 @@ internal class ScriptComponentPool : IComponentPool<ScriptComponent>
|
||||
[Obsolete("Use GetAll instead of Get for ScriptComponentPool.")]
|
||||
public IComponentData Get(Entity entity)
|
||||
{
|
||||
throw new NotSupportedException("Use GetAll instead of Get for ScriptComponentPool.");
|
||||
if (!Has(entity)
|
||||
|| !_scriptComponents!.TryGetValue(entity, out var scriptList)
|
||||
|| scriptList == null
|
||||
|| scriptList.Count == 0)
|
||||
{
|
||||
return null!;
|
||||
}
|
||||
|
||||
return scriptList[0];
|
||||
}
|
||||
|
||||
[Obsolete("Use GetAll instead of GetUnsafe for ScriptComponentPool.")]
|
||||
public unsafe IntPtr GetUnsafe(Entity entity)
|
||||
{
|
||||
if (!Has(entity)
|
||||
|| !_scriptComponents!.TryGetValue(entity, out var scriptList)
|
||||
|| scriptList == null
|
||||
|| scriptList.Count == 0)
|
||||
{
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
return (IntPtr)Unsafe.AsPointer(ref CollectionsMarshal.AsSpan(scriptList)[0]);
|
||||
}
|
||||
|
||||
public void Set(Entity entity, in IComponentData component)
|
||||
@@ -385,12 +414,12 @@ internal class ScriptComponentPool : IComponentPool<ScriptComponent>
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<IComponentData> GetAll(Entity entity)
|
||||
public IReadOnlyList<IComponentData>? GetAll(Entity entity)
|
||||
{
|
||||
if (_scriptComponents == null
|
||||
|| !_scriptComponents.TryGetValue(entity, out var scriptList))
|
||||
{
|
||||
return Enumerable.Empty<ScriptComponent>();
|
||||
return null;
|
||||
}
|
||||
|
||||
return scriptList;
|
||||
@@ -463,7 +492,7 @@ internal readonly struct ComponentStorage : IDisposable
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool TryGetPool<T>([MaybeNullWhen(false)] out ComponentPool<T> pool)
|
||||
where T : struct, IComponentData
|
||||
where T : unmanaged, IComponentData
|
||||
{
|
||||
var result = TryGetPool(TypeHandle.Get<T>(), out var obj);
|
||||
pool = (ComponentPool<T>?)obj ?? default;
|
||||
@@ -471,7 +500,7 @@ internal readonly struct ComponentStorage : IDisposable
|
||||
}
|
||||
|
||||
public ComponentPool<T> GetOrCreateComponentPool<T>()
|
||||
where T : struct, IComponentData
|
||||
where T : unmanaged, IComponentData
|
||||
{
|
||||
var key = TypeHandle.Get<T>();
|
||||
if (!_componentPools.TryGetValue(key, out var obj))
|
||||
@@ -498,7 +527,7 @@ internal readonly struct ComponentStorage : IDisposable
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool TryGetMask<T>([MaybeNullWhen(false)] out BitSet bitSet)
|
||||
where T : struct, IComponentData
|
||||
where T : unmanaged, IComponentData
|
||||
{
|
||||
return TryGetMask(TypeHandle.Get<T>(), out bitSet);
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ public readonly struct EntityManager : IDisposable
|
||||
/// <param name="component">The component value to add.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly void AddComponent<T>(Entity entity, T component)
|
||||
where T : struct, IComponentData
|
||||
where T : unmanaged, IComponentData
|
||||
{
|
||||
_world.ComponentStorage.GetOrCreateComponentPool<T>().Add(entity, component);
|
||||
_world.ComponentStorage.GetOrCreateMask(TypeHandle.Get<T>()).SetBit(entity.ID);
|
||||
@@ -121,7 +121,7 @@ public readonly struct EntityManager : IDisposable
|
||||
/// <param name="entity">The entity for which the component is to be remove.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly bool RemoveComponent<T>(Entity entity)
|
||||
where T : struct, IComponentData
|
||||
where T : unmanaged, IComponentData
|
||||
{
|
||||
if (!_world.ComponentStorage.TryGetPool<T>(out var pool) || !pool.Has(entity))
|
||||
{
|
||||
@@ -138,6 +138,29 @@ public readonly struct EntityManager : IDisposable
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a component of the specified type for the given <see cref="Entity"/>.
|
||||
/// </summary>
|
||||
/// <param name="entity">The entity for which the component is to be set.</param>
|
||||
/// <param name="component">The component value to set.</param>
|
||||
/// <param name="type">The type of the component to set.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly void SetComponent(Entity entity, IComponentData component, Type type)
|
||||
{
|
||||
var typeHandle = TypeHandle.Get(type);
|
||||
if (!_world.ComponentStorage.TryGetPool(typeHandle, out var pool))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!pool.Has(entity))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pool.Set(entity, component);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a component of type <typeparamref name="T"/> for the given <see cref="Entity"/>.
|
||||
/// </summary>
|
||||
@@ -146,7 +169,7 @@ public readonly struct EntityManager : IDisposable
|
||||
/// <param name="component">The component value to set.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly void SetComponent<T>(Entity entity, in T component)
|
||||
where T : struct, IComponentData
|
||||
where T : unmanaged, IComponentData
|
||||
{
|
||||
_world.ComponentStorage.GetOrCreateComponentPool<T>().Set(entity, in component);
|
||||
}
|
||||
@@ -171,7 +194,7 @@ public readonly struct EntityManager : IDisposable
|
||||
/// <returns>A <see cref="Ref{T}"/> to the component, or a null reference if the component does not exist.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly Ref<T> GetComponent<T>(Entity entity)
|
||||
where T : struct, IComponentData
|
||||
where T : unmanaged, IComponentData
|
||||
{
|
||||
if (_world.ComponentStorage.TryGetPool<T>(out var pool) && pool.Has(entity))
|
||||
{
|
||||
@@ -183,6 +206,49 @@ public readonly struct EntityManager : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves all components associated with the specified entity.
|
||||
/// </summary>
|
||||
/// <remarks>This method iterates through all available component pools to find components associated
|
||||
/// with the given entity. It is designed to lazily yield components, making it efficient for scenarios where only
|
||||
/// a subset of components may be needed.</remarks>
|
||||
/// <param name="entity">The entity for which components are to be retrieved.</param>
|
||||
/// <returns>An enumerable collection of components associated with the specified entity. If the entity has no components,
|
||||
/// the collection will be empty.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly IEnumerable<IComponentData> GetComponents(Entity entity)
|
||||
{
|
||||
foreach (var pool in _world.ComponentStorage.ComponentPools.Values)
|
||||
{
|
||||
if (pool.Has(entity))
|
||||
{
|
||||
yield return pool.Get(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves an enumerable collection of raw pointers to the components associated with the specified entity.
|
||||
/// </summary>
|
||||
/// <remarks>This method provides direct access to the memory locations of components, bypassing type
|
||||
/// safety. Use with caution, as improper handling of raw pointers can lead to undefined behavior or memory
|
||||
/// corruption. Ensure that the entity is valid and exists within the current world context before calling this
|
||||
/// method.</remarks>
|
||||
/// <param name="entity">The entity whose components are to be retrieved.</param>
|
||||
/// <returns>An enumerable collection of <see cref="IntPtr"/> representing the memory addresses of the components associated
|
||||
/// with the specified entity. The collection will be empty if the entity has no associated components.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public readonly IEnumerable<(IntPtr, IntPtr)> GetComponentsUnsafe(Entity entity)
|
||||
{
|
||||
foreach (var (typeHandle, pool) in _world.ComponentStorage.ComponentPools)
|
||||
{
|
||||
if (pool.Has(entity))
|
||||
{
|
||||
yield return (typeHandle, pool.GetUnsafe(entity));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a script of type <typeparamref name="T"/> to the given <see cref="Entity"/>.
|
||||
/// </summary>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -14,7 +14,7 @@ namespace Ghost.Entities;
|
||||
|
||||
<# for (int arity = 1; arity <= Amount; arity++) {
|
||||
var generics = AppendGenerics(arity);
|
||||
var restrictions = AppendGenericRestrictions(arity, "struct, IComponentData");
|
||||
var restrictions = AppendGenericRestrictions(arity, "unmanaged, IComponentData");
|
||||
var poolParams = Enumerable.Range(0, arity)
|
||||
.Select(i => $"ComponentPool<T{i}> pool{i}")
|
||||
.Aggregate((a, b) => a + ", " + b);
|
||||
@@ -105,7 +105,7 @@ public struct QueryEnumerable<<#= generics #>>
|
||||
}
|
||||
<# for (int i = 1; i <= ExtensionAmount; i++) {
|
||||
var compGenerics = AppendGenerics(i, "TComponent");
|
||||
var compRestrictions = AppendGenericRestrictions(i, "TComponent", "struct, IComponentData");
|
||||
var compRestrictions = AppendGenericRestrictions(i, "TComponent", "unmanaged, IComponentData");
|
||||
#>
|
||||
|
||||
public readonly QueryEnumerable<<#= generics #>> WithAll<<#= compGenerics #>>()
|
||||
|
||||
@@ -6,7 +6,7 @@ using Ghost.Entities.Query;
|
||||
namespace Ghost.Entities;
|
||||
|
||||
public readonly struct QueryItem<T0>
|
||||
where T0 : struct, IComponentData
|
||||
where T0 : unmanaged, IComponentData
|
||||
{
|
||||
private readonly Entity _entity;
|
||||
private readonly ComponentPool<T0> _pool0;
|
||||
@@ -25,12 +25,12 @@ public readonly struct QueryItem<T0>
|
||||
public void Deconstruct(out Entity entity, out Ref<T0> c0)
|
||||
{
|
||||
entity = _entity;
|
||||
c0 = new(ref _pool0.GetRef(_entity));
|
||||
c0 = new (ref _pool0.GetRef(_entity));
|
||||
}
|
||||
}
|
||||
|
||||
public readonly struct QueryItem<T0, T1>
|
||||
where T0 : struct, IComponentData where T1 : struct, IComponentData
|
||||
where T0 : unmanaged, IComponentData where T1 : unmanaged, IComponentData
|
||||
{
|
||||
private readonly Entity _entity;
|
||||
private readonly ComponentPool<T0> _pool0;
|
||||
@@ -52,13 +52,12 @@ public readonly struct QueryItem<T0, T1>
|
||||
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));
|
||||
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
|
||||
where T0 : unmanaged, IComponentData where T1 : unmanaged, IComponentData where T2 : unmanaged, IComponentData
|
||||
{
|
||||
private readonly Entity _entity;
|
||||
private readonly ComponentPool<T0> _pool0;
|
||||
@@ -83,14 +82,12 @@ public readonly struct QueryItem<T0, T1, T2>
|
||||
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));
|
||||
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
|
||||
where T0 : unmanaged, IComponentData where T1 : unmanaged, IComponentData where T2 : unmanaged, IComponentData where T3 : unmanaged, IComponentData
|
||||
{
|
||||
private readonly Entity _entity;
|
||||
private readonly ComponentPool<T0> _pool0;
|
||||
@@ -118,15 +115,12 @@ public readonly struct QueryItem<T0, T1, T2, T3>
|
||||
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));
|
||||
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
|
||||
where T0 : unmanaged, IComponentData where T1 : unmanaged, IComponentData where T2 : unmanaged, IComponentData where T3 : unmanaged, IComponentData where T4 : unmanaged, IComponentData
|
||||
{
|
||||
private readonly Entity _entity;
|
||||
private readonly ComponentPool<T0> _pool0;
|
||||
@@ -157,16 +151,12 @@ public readonly struct QueryItem<T0, T1, T2, T3, T4>
|
||||
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));
|
||||
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
|
||||
where T0 : unmanaged, IComponentData where T1 : unmanaged, IComponentData where T2 : unmanaged, IComponentData where T3 : unmanaged, IComponentData where T4 : unmanaged, IComponentData where T5 : unmanaged, IComponentData
|
||||
{
|
||||
private readonly Entity _entity;
|
||||
private readonly ComponentPool<T0> _pool0;
|
||||
@@ -200,17 +190,12 @@ public readonly struct QueryItem<T0, T1, T2, T3, T4, T5>
|
||||
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));
|
||||
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
|
||||
where T0 : unmanaged, IComponentData where T1 : unmanaged, IComponentData where T2 : unmanaged, IComponentData where T3 : unmanaged, IComponentData where T4 : unmanaged, IComponentData where T5 : unmanaged, IComponentData where T6 : unmanaged, IComponentData
|
||||
{
|
||||
private readonly Entity _entity;
|
||||
private readonly ComponentPool<T0> _pool0;
|
||||
@@ -247,18 +232,12 @@ public readonly struct QueryItem<T0, T1, T2, T3, T4, T5, T6>
|
||||
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));
|
||||
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
|
||||
where T0 : unmanaged, IComponentData where T1 : unmanaged, IComponentData where T2 : unmanaged, IComponentData where T3 : unmanaged, IComponentData where T4 : unmanaged, IComponentData where T5 : unmanaged, IComponentData where T6 : unmanaged, IComponentData where T7 : unmanaged, IComponentData
|
||||
{
|
||||
private readonly Entity _entity;
|
||||
private readonly ComponentPool<T0> _pool0;
|
||||
@@ -298,14 +277,7 @@ public readonly struct QueryItem<T0, T1, T2, T3, T4, T5, T6, T7>
|
||||
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));
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<#@ include file="Helpers.ttinclude" #>
|
||||
<#@ output extension=".cs" #>
|
||||
|
||||
using Ghost.Entities.Components;
|
||||
using Ghost.Entities.Query;
|
||||
|
||||
namespace Ghost.Entities;
|
||||
@@ -11,7 +12,7 @@ namespace Ghost.Entities;
|
||||
<# for (int arity = 1; arity <= Amount; arity++)
|
||||
{
|
||||
var generics = AppendGenerics(arity);
|
||||
var restrictions = AppendGenericRestrictions(arity, "struct, IComponentData");
|
||||
var restrictions = AppendGenericRestrictions(arity, "unmanaged, IComponentData");
|
||||
var constructorParams = Enumerable.Range(0, arity)
|
||||
.Select(i => $"ComponentPool<T{i}> pool{i}")
|
||||
.Aggregate((a, b) => a + ", " + b);
|
||||
|
||||
@@ -5,18 +5,18 @@ using Ghost.Entities.Components;
|
||||
namespace Ghost.Entities;
|
||||
|
||||
public delegate void QueryRefComponent<T0>(Entity entity, ref T0 t0Component)
|
||||
where T0 : struct, IComponentData;
|
||||
public delegate void QueryRefComponent<T0, T1>(Entity entity, ref T0 t0Component, ref T1 t1Component)
|
||||
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, 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, 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, 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, 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, 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, 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;
|
||||
where T0 : unmanaged, IComponentData;
|
||||
public delegate void QueryRefComponent<T0, T1>(Entity entity, ref T0 t0Component,ref T1 t1Component)
|
||||
where T0 : unmanaged, IComponentData where T1 : unmanaged, IComponentData;
|
||||
public delegate void QueryRefComponent<T0, T1, T2>(Entity entity, ref T0 t0Component,ref T1 t1Component,ref T2 t2Component)
|
||||
where T0 : unmanaged, IComponentData where T1 : unmanaged, IComponentData where T2 : unmanaged, 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 : unmanaged, IComponentData where T1 : unmanaged, IComponentData where T2 : unmanaged, IComponentData where T3 : unmanaged, 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 : unmanaged, IComponentData where T1 : unmanaged, IComponentData where T2 : unmanaged, IComponentData where T3 : unmanaged, IComponentData where T4 : unmanaged, 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 : unmanaged, IComponentData where T1 : unmanaged, IComponentData where T2 : unmanaged, IComponentData where T3 : unmanaged, IComponentData where T4 : unmanaged, IComponentData where T5 : unmanaged, 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 : unmanaged, IComponentData where T1 : unmanaged, IComponentData where T2 : unmanaged, IComponentData where T3 : unmanaged, IComponentData where T4 : unmanaged, IComponentData where T5 : unmanaged, IComponentData where T6 : unmanaged, 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 : unmanaged, IComponentData where T1 : unmanaged, IComponentData where T2 : unmanaged, IComponentData where T3 : unmanaged, IComponentData where T4 : unmanaged, IComponentData where T5 : unmanaged, IComponentData where T6 : unmanaged, IComponentData where T7 : unmanaged, IComponentData;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ include file="Helpers.ttinclude" #>
|
||||
|
||||
using Ghost.Entities.Components;
|
||||
|
||||
namespace Ghost.Entities;
|
||||
|
||||
<#
|
||||
@@ -10,7 +12,7 @@ for (var index = 1; index <= Amount; index++)
|
||||
{
|
||||
var generics = AppendGenerics(index);
|
||||
var parameters = AppendGenericRefParameters(index);
|
||||
var restrictions = AppendGenericRestrictions(index, "struct, IComponentData");
|
||||
var restrictions = AppendGenericRestrictions(index, "unmanaged, IComponentData");
|
||||
#>
|
||||
public delegate void QueryRefComponent<<#= generics #>>(Entity entity, <#= parameters.ToString() #>)
|
||||
<#= restrictions.ToString() #>;
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Ghost.Entities;
|
||||
public partial class World
|
||||
{
|
||||
public QueryEnumerable<T0> Query<T0>()
|
||||
where T0 : struct, IComponentData
|
||||
where T0 : unmanaged, IComponentData
|
||||
{
|
||||
if (!(_componentStorage.TryGetPool<T0>(out var pool0)))
|
||||
return default;
|
||||
@@ -19,7 +19,7 @@ public partial class World
|
||||
}
|
||||
|
||||
public QueryEnumerable<T0, T1> Query<T0, T1>()
|
||||
where T0 : struct, IComponentData where T1 : struct, IComponentData
|
||||
where T0 : unmanaged, IComponentData where T1 : unmanaged, IComponentData
|
||||
{
|
||||
if (!(_componentStorage.TryGetPool<T0>(out var pool0) && _componentStorage.TryGetPool<T1>(out var pool1)))
|
||||
return default;
|
||||
@@ -31,7 +31,7 @@ public partial class World
|
||||
}
|
||||
|
||||
public QueryEnumerable<T0, T1, T2> Query<T0, T1, T2>()
|
||||
where T0 : struct, IComponentData where T1 : struct, IComponentData where T2 : struct, IComponentData
|
||||
where T0 : unmanaged, IComponentData where T1 : unmanaged, IComponentData where T2 : unmanaged, IComponentData
|
||||
{
|
||||
if (!(_componentStorage.TryGetPool<T0>(out var pool0) && _componentStorage.TryGetPool<T1>(out var pool1) && _componentStorage.TryGetPool<T2>(out var pool2)))
|
||||
return default;
|
||||
@@ -43,7 +43,7 @@ public partial class World
|
||||
}
|
||||
|
||||
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
|
||||
where T0 : unmanaged, IComponentData where T1 : unmanaged, IComponentData where T2 : unmanaged, IComponentData where T3 : unmanaged, IComponentData
|
||||
{
|
||||
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;
|
||||
@@ -55,7 +55,7 @@ public partial class World
|
||||
}
|
||||
|
||||
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
|
||||
where T0 : unmanaged, IComponentData where T1 : unmanaged, IComponentData where T2 : unmanaged, IComponentData where T3 : unmanaged, IComponentData where T4 : unmanaged, IComponentData
|
||||
{
|
||||
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;
|
||||
@@ -67,7 +67,7 @@ public partial class World
|
||||
}
|
||||
|
||||
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
|
||||
where T0 : unmanaged, IComponentData where T1 : unmanaged, IComponentData where T2 : unmanaged, IComponentData where T3 : unmanaged, IComponentData where T4 : unmanaged, IComponentData where T5 : unmanaged, IComponentData
|
||||
{
|
||||
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;
|
||||
@@ -79,7 +79,7 @@ public partial class World
|
||||
}
|
||||
|
||||
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
|
||||
where T0 : unmanaged, IComponentData where T1 : unmanaged, IComponentData where T2 : unmanaged, IComponentData where T3 : unmanaged, IComponentData where T4 : unmanaged, IComponentData where T5 : unmanaged, IComponentData where T6 : unmanaged, IComponentData
|
||||
{
|
||||
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;
|
||||
@@ -91,7 +91,7 @@ public partial class World
|
||||
}
|
||||
|
||||
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
|
||||
where T0 : unmanaged, IComponentData where T1 : unmanaged, IComponentData where T2 : unmanaged, IComponentData where T3 : unmanaged, IComponentData where T4 : unmanaged, IComponentData where T5 : unmanaged, IComponentData where T6 : unmanaged, IComponentData where T7 : unmanaged, IComponentData
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -5,13 +5,15 @@
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ include file="Helpers.ttinclude" #>
|
||||
|
||||
using Ghost.Entities.Components;
|
||||
|
||||
namespace Ghost.Entities;
|
||||
|
||||
public partial class World
|
||||
{
|
||||
<# for (var index = 1; index <= Amount; index++) {
|
||||
var generics = AppendGenerics(index);
|
||||
var restrictions = AppendGenericRestrictions(index, "struct, IComponentData");
|
||||
var restrictions = AppendGenericRestrictions(index, "unmanaged, IComponentData");
|
||||
var tryGetPools = TryGetComponentPools(index);
|
||||
var poolParams = Enumerable.Range(0, index)
|
||||
.Select(i => $"pool{i}")
|
||||
|
||||
@@ -67,7 +67,7 @@ public partial class World : IDisposable, IEquatable<World>
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Ref<T> GetSingleton<T>()
|
||||
where T : struct, IComponentData
|
||||
where T : unmanaged, IComponentData
|
||||
{
|
||||
ref var component = ref CollectionsMarshal.GetValueRefOrAddDefault(SingletonContainer<T>.container, _id, out _);
|
||||
return new Ref<T>(ref component);
|
||||
@@ -113,6 +113,11 @@ public partial class World : IDisposable, IEquatable<World>
|
||||
return _id.GetHashCode();
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return obj is World other && Equals(other);
|
||||
}
|
||||
|
||||
public static bool operator ==(World? left, World? right)
|
||||
{
|
||||
return left?.Equals(right) ?? right is null;
|
||||
|
||||
Reference in New Issue
Block a user