mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 01:44:35 +08:00
Merge branch 'dev'
This commit is contained in:
commit
c830f3a4cc
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
|
#region Interfaces
|
||||||
public interface IEcsPreInitProcess : IEcsSystem
|
public interface IEcsPreInitProcess : IEcsSystem
|
||||||
{
|
{
|
||||||
void PreInit(EcsPipeline pipeline);
|
void PreInit(EcsPipeline pipeline);
|
||||||
@ -18,7 +19,8 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
void Destroy(EcsPipeline pipeline);
|
void Destroy(EcsPipeline pipeline);
|
||||||
}
|
}
|
||||||
public interface IEcsBaseSystem : IEcsInitProcess, IEcsRunProcess, IEcsDestroyProcess { }
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
namespace Internal
|
namespace Internal
|
||||||
{
|
{
|
||||||
@ -40,7 +42,6 @@ namespace DCFApixels.DragonECS
|
|||||||
foreach (var item in targets) item.PreInit(pipeline);
|
foreach (var item in targets) item.PreInit(pipeline);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG && !DISABLE_DEBUG
|
#if DEBUG && !DISABLE_DEBUG
|
||||||
protected override void OnSetup()
|
protected override void OnSetup()
|
||||||
{
|
{
|
||||||
@ -70,7 +71,6 @@ namespace DCFApixels.DragonECS
|
|||||||
foreach (var item in targets) item.Init(pipeline);
|
foreach (var item in targets) item.Init(pipeline);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG && !DISABLE_DEBUG
|
#if DEBUG && !DISABLE_DEBUG
|
||||||
protected override void OnSetup()
|
protected override void OnSetup()
|
||||||
{
|
{
|
||||||
@ -101,7 +101,6 @@ namespace DCFApixels.DragonECS
|
|||||||
foreach (var item in targets) item.Run(pipeline);
|
foreach (var item in targets) item.Run(pipeline);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG && !DISABLE_DEBUG
|
#if DEBUG && !DISABLE_DEBUG
|
||||||
protected override void OnSetup()
|
protected override void OnSetup()
|
||||||
{
|
{
|
||||||
@ -131,7 +130,6 @@ namespace DCFApixels.DragonECS
|
|||||||
foreach (var item in targets) item.Destroy(pipeline);
|
foreach (var item in targets) item.Destroy(pipeline);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG && !DISABLE_DEBUG
|
#if DEBUG && !DISABLE_DEBUG
|
||||||
protected override void OnSetup()
|
protected override void OnSetup()
|
||||||
{
|
{
|
||||||
|
@ -4,9 +4,6 @@ using System.Linq;
|
|||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
//TODO развить идею инжектов
|
|
||||||
//добавить контейнер, который автоматически создается, собирает в себя все пре-инжекты и авто-инжектится во все системы.
|
|
||||||
//но это спорная идея
|
|
||||||
public interface IEcsPreInject : IEcsSystem
|
public interface IEcsPreInject : IEcsSystem
|
||||||
{
|
{
|
||||||
void PreInject(object obj);
|
void PreInject(object obj);
|
||||||
|
@ -6,10 +6,10 @@ namespace DCFApixels.DragonECS
|
|||||||
namespace Internal
|
namespace Internal
|
||||||
{
|
{
|
||||||
[DebugHide, DebugColor(DebugColor.Black)]
|
[DebugHide, DebugColor(DebugColor.Black)]
|
||||||
public class SystemsBlockMarkerSystem : IEcsSystem
|
public class SystemsLayerMarkerSystem : IEcsSystem
|
||||||
{
|
{
|
||||||
public readonly string name;
|
public readonly string name;
|
||||||
public SystemsBlockMarkerSystem(string name) => this.name = name;
|
public SystemsLayerMarkerSystem(string name) => this.name = name;
|
||||||
}
|
}
|
||||||
[DebugHide, DebugColor(DebugColor.Grey)]
|
[DebugHide, DebugColor(DebugColor.Grey)]
|
||||||
public class DeleteEmptyEntitesSystem : IEcsRunProcess, IEcsPreInject
|
public class DeleteEmptyEntitesSystem : IEcsRunProcess, IEcsPreInject
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
internal sealed class EcsNullWorld : EcsWorld<EcsNullWorld>
|
|
||||||
{
|
|
||||||
public EcsNullWorld() : base(false) { }
|
|
||||||
}
|
|
||||||
public sealed class EcsDefaultWorld : EcsWorld<EcsDefaultWorld> { }
|
public sealed class EcsDefaultWorld : EcsWorld<EcsDefaultWorld> { }
|
||||||
public sealed class EcsEventWorld : EcsWorld<EcsEventWorld> { }
|
public sealed class EcsEventWorld : EcsWorld<EcsEventWorld> { }
|
||||||
}
|
}
|
||||||
|
@ -10,45 +10,31 @@ namespace DCFApixels.DragonECS
|
|||||||
public byte r => color.r;
|
public byte r => color.r;
|
||||||
public byte g => color.g;
|
public byte g => color.g;
|
||||||
public byte b => color.b;
|
public byte b => color.b;
|
||||||
|
/// <summary>normalized R channel </summary>
|
||||||
public float rn => color.r / 255f;
|
public float rn => color.r / 255f;
|
||||||
|
/// <summary>normalized G channel </summary>
|
||||||
public float gn => color.g / 255f;
|
public float gn => color.g / 255f;
|
||||||
|
/// <summary>normalized B channel </summary>
|
||||||
public float bn => color.b / 255f;
|
public float bn => color.b / 255f;
|
||||||
|
public DebugColorAttribute(byte r, byte g, byte b) => color = new ColorRecord(r, g, b);
|
||||||
public DebugColorAttribute(byte r, byte g, byte b)
|
public DebugColorAttribute(DebugColor color) => this.color = new ColorRecord((int)color);
|
||||||
{
|
|
||||||
color = new ColorRecord(r, g, b);
|
|
||||||
}
|
|
||||||
public DebugColorAttribute(DebugColor color)
|
|
||||||
{
|
|
||||||
this.color = new ColorRecord((int)color);
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Explicit, Pack = 1, Size = 4)]
|
[StructLayout(LayoutKind.Explicit, Pack = 1, Size = 4)]
|
||||||
private readonly struct ColorRecord // Union
|
private readonly struct ColorRecord // Union
|
||||||
{
|
{
|
||||||
[FieldOffset(0)]
|
[FieldOffset(0)] public readonly int full;
|
||||||
public readonly int full;
|
[FieldOffset(3)] public readonly byte r;
|
||||||
[FieldOffset(3)]
|
[FieldOffset(2)] public readonly byte g;
|
||||||
public readonly byte r;
|
[FieldOffset(1)] public readonly byte b;
|
||||||
[FieldOffset(2)]
|
|
||||||
public readonly byte g;
|
|
||||||
[FieldOffset(1)]
|
|
||||||
public readonly byte b;
|
|
||||||
|
|
||||||
public ColorRecord(byte r, byte g, byte b) : this()
|
public ColorRecord(byte r, byte g, byte b) : this()
|
||||||
{
|
{
|
||||||
this.r = r;
|
this.r = r;
|
||||||
this.g = g;
|
this.g = g;
|
||||||
this.b = b;
|
this.b = b;
|
||||||
}
|
}
|
||||||
public ColorRecord(int full) : this()
|
public ColorRecord(int full) : this() => this.full = full;
|
||||||
{
|
|
||||||
this.full = full;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum DebugColor
|
public enum DebugColor
|
||||||
{
|
{
|
||||||
/// <summary> Red. RGB is (255, 0, 0)</summary>
|
/// <summary> Red. RGB is (255, 0, 0)</summary>
|
||||||
|
@ -6,9 +6,6 @@ namespace DCFApixels.DragonECS
|
|||||||
public sealed class DebugDescriptionAttribute : Attribute
|
public sealed class DebugDescriptionAttribute : Attribute
|
||||||
{
|
{
|
||||||
public readonly string description;
|
public readonly string description;
|
||||||
public DebugDescriptionAttribute(string description)
|
public DebugDescriptionAttribute(string description) => this.description = description;
|
||||||
{
|
|
||||||
this.description = description;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,6 @@ namespace DCFApixels.DragonECS
|
|||||||
public sealed class DebugNameAttribute : Attribute
|
public sealed class DebugNameAttribute : Attribute
|
||||||
{
|
{
|
||||||
public readonly string name;
|
public readonly string name;
|
||||||
public DebugNameAttribute(string name)
|
public DebugNameAttribute(string name) => this.name = name;
|
||||||
{
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ namespace DCFApixels.DragonECS
|
|||||||
public void End() => EcsDebug.ProfileMarkEnd(id);
|
public void End() => EcsDebug.ProfileMarkEnd(id);
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public AutoScope Auto() => new AutoScope(id);
|
public AutoScope Auto() => new AutoScope(id);
|
||||||
|
|
||||||
public readonly ref struct AutoScope
|
public readonly ref struct AutoScope
|
||||||
{
|
{
|
||||||
private readonly int _id;
|
private readonly int _id;
|
||||||
@ -36,7 +35,14 @@ namespace DCFApixels.DragonECS
|
|||||||
public static void Set(DebugService service) => DebugService.Set(service);
|
public static void Set(DebugService service) => DebugService.Set(service);
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void Print(object v) => DebugService.Instance.Print(v);
|
public static void PrintWarning(object v) => Print(EcsConsts.DEBUG_WARNING_TAG, v);
|
||||||
|
public static void PrintError(object v) => Print(EcsConsts.DEBUG_ERROR_TAG, v);
|
||||||
|
public static void Print(object v)
|
||||||
|
{
|
||||||
|
#if !DISABLE_DRAGONECS_DEBUGGER
|
||||||
|
DebugService.Instance.Print(v);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static void Print(string tag, object v)
|
public static void Print(string tag, object v)
|
||||||
{
|
{
|
||||||
@ -139,7 +145,6 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
private Stopwatch[] _stopwatchs;
|
private Stopwatch[] _stopwatchs;
|
||||||
private string[] _stopwatchsNames;
|
private string[] _stopwatchsNames;
|
||||||
|
|
||||||
public DefaultDebugService()
|
public DefaultDebugService()
|
||||||
{
|
{
|
||||||
#if !DISABLE_DRAGONECS_DEBUGGER
|
#if !DISABLE_DRAGONECS_DEBUGGER
|
||||||
@ -147,17 +152,14 @@ namespace DCFApixels.DragonECS
|
|||||||
_stopwatchsNames= new string[64];
|
_stopwatchsNames= new string[64];
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Print(string tag, object v)
|
public override void Print(string tag, object v)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"[{tag}] {v}");
|
Console.WriteLine($"[{tag}] {v}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ProfileMarkBegin(int id)
|
public override void ProfileMarkBegin(int id)
|
||||||
{
|
{
|
||||||
_stopwatchs[id].Start();
|
_stopwatchs[id].Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ProfileMarkEnd(int id)
|
public override void ProfileMarkEnd(int id)
|
||||||
{
|
{
|
||||||
_stopwatchs[id].Stop();
|
_stopwatchs[id].Stop();
|
||||||
@ -165,12 +167,10 @@ namespace DCFApixels.DragonECS
|
|||||||
_stopwatchs[id].Reset();
|
_stopwatchs[id].Reset();
|
||||||
Print(_stopwatchsNames[id] + " s:" + time.TotalSeconds);
|
Print(_stopwatchsNames[id] + " s:" + time.TotalSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnDelMark(int id)
|
protected override void OnDelMark(int id)
|
||||||
{
|
{
|
||||||
_stopwatchs[id] = null;
|
_stopwatchs[id] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnNewMark(int id, string name)
|
protected override void OnNewMark(int id, string name)
|
||||||
{
|
{
|
||||||
if (id >= _stopwatchs.Length)
|
if (id >= _stopwatchs.Length)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS
|
#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS
|
||||||
@ -8,6 +9,7 @@ using static DCFApixels.DragonECS.EcsGroup.ThrowHalper;
|
|||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
[StructLayout(LayoutKind.Sequential, Pack = 0, Size = 8)]
|
[StructLayout(LayoutKind.Sequential, Pack = 0, Size = 8)]
|
||||||
|
[DebuggerTypeProxy(typeof(DebuggerProxy))]
|
||||||
public readonly ref struct EcsReadonlyGroup
|
public readonly ref struct EcsReadonlyGroup
|
||||||
{
|
{
|
||||||
private readonly EcsGroup _source;
|
private readonly EcsGroup _source;
|
||||||
@ -65,12 +67,7 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Object
|
#region Object
|
||||||
public override string ToString()
|
public override string ToString() => _source != null ? _source.ToString() : "NULL";
|
||||||
{
|
|
||||||
if (_source != null)
|
|
||||||
return _source.ToString();
|
|
||||||
return "NULL";
|
|
||||||
}
|
|
||||||
public override int GetHashCode() => _source.GetHashCode();
|
public override int GetHashCode() => _source.GetHashCode();
|
||||||
public override bool Equals(object obj) => obj is EcsGroup group && group == this;
|
public override bool Equals(object obj) => obj is EcsGroup group && group == this;
|
||||||
public bool Equals(EcsReadonlyGroup other) => _source == other._source;
|
public bool Equals(EcsReadonlyGroup other) => _source == other._source;
|
||||||
@ -88,15 +85,23 @@ namespace DCFApixels.DragonECS
|
|||||||
public static bool operator !=(EcsReadonlyGroup a, EcsReadonlyGroup b) => !a.Equals(b);
|
public static bool operator !=(EcsReadonlyGroup a, EcsReadonlyGroup b) => !a.Equals(b);
|
||||||
public static bool operator !=(EcsReadonlyGroup a, EcsGroup b) => !a.Equals(b);
|
public static bool operator !=(EcsReadonlyGroup a, EcsGroup b) => !a.Equals(b);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region DebuggerProxy
|
||||||
|
internal class DebuggerProxy : EcsGroup.DebuggerProxy
|
||||||
|
{
|
||||||
|
public DebuggerProxy(EcsReadonlyGroup group) : base(group._source) { }
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[DebuggerTypeProxy(typeof(DebuggerProxy))]
|
||||||
public unsafe class EcsGroup : IDisposable, IEquatable<EcsGroup>
|
public unsafe class EcsGroup : IDisposable, IEquatable<EcsGroup>
|
||||||
{
|
{
|
||||||
private EcsWorld _source;
|
private EcsWorld _source;
|
||||||
private int[] _dense;
|
private int[] _dense;
|
||||||
private int[] _sparse;
|
private int[] _sparse;
|
||||||
private int _count;
|
private int _count;
|
||||||
private bool _isReleased = true;
|
internal bool _isReleased = true;
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
public EcsWorld World => _source;
|
public EcsWorld World => _source;
|
||||||
@ -219,12 +224,11 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Sort/Clear
|
#region Clear
|
||||||
//public void Sort() { } //TODO прошлай реализация сортировки не удачная, так как в dense могут храниться занчения больше чем dense.Length
|
|
||||||
public void Clear()
|
public void Clear()
|
||||||
{
|
{
|
||||||
_count = 0;
|
_count = 0;
|
||||||
//массив _dense нет смысла очищать, испольщуется только область от 1 до _count
|
//массив _dense нет смысла очищать
|
||||||
for (int i = 0; i < _sparse.Length; i++)
|
for (int i = 0; i < _sparse.Length; i++)
|
||||||
_sparse[i] = 0;
|
_sparse[i] = 0;
|
||||||
}
|
}
|
||||||
@ -392,10 +396,7 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Object
|
#region Object
|
||||||
public override string ToString()
|
public override string ToString() => string.Join(", ", _dense.AsSpan(1, _count).ToArray());
|
||||||
{
|
|
||||||
return string.Join(", ", _dense.AsSpan(1, _count).ToArray());
|
|
||||||
}
|
|
||||||
public override bool Equals(object obj) => obj is EcsGroup group && Equals(group);
|
public override bool Equals(object obj) => obj is EcsGroup group && Equals(group);
|
||||||
public bool Equals(EcsReadonlyGroup other) => Equals(other.GetGroupInternal());
|
public bool Equals(EcsReadonlyGroup other) => Equals(other.GetGroupInternal());
|
||||||
public bool Equals(EcsGroup other)
|
public bool Equals(EcsGroup other)
|
||||||
@ -449,13 +450,9 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region IDisposable/Release
|
#region IDisposable/Release
|
||||||
public void Dispose()
|
public void Dispose() => Release();
|
||||||
{
|
|
||||||
Release();
|
|
||||||
}
|
|
||||||
public void Release()
|
public void Release()
|
||||||
{
|
{
|
||||||
_isReleased = true;
|
|
||||||
_source.ReleaseGroup(this);
|
_source.ReleaseGroup(this);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@ -473,21 +470,30 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endregion
|
#endregion
|
||||||
}
|
|
||||||
|
|
||||||
#region Extensions
|
#region DebuggerProxy
|
||||||
public static class EcsGroupExtensions
|
internal class DebuggerProxy
|
||||||
{
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static void Normalize<T>(this EcsGroup self, ref T[] array)
|
|
||||||
{
|
{
|
||||||
if (array.Length < self.CapacityDense) Array.Resize(ref array, self.CapacityDense);
|
private EcsGroup _group;
|
||||||
}
|
public EcsWorld World => _group.World;
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
public bool IsReleased => _group.IsReleased;
|
||||||
public static void Normalize<T>(this EcsReadonlyGroup self, ref T[] array)
|
public entlong[] Entities
|
||||||
{
|
{
|
||||||
if (array.Length < self.CapacityDense) Array.Resize(ref array, self.CapacityDense);
|
get
|
||||||
|
{
|
||||||
|
entlong[] result = new entlong[_group.Count];
|
||||||
|
int i = 0;
|
||||||
|
foreach (var e in _group)
|
||||||
|
result[i++] = _group.World.GetEntityLong(e);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int Count => _group.Count;
|
||||||
|
public int CapacityDense => _group.CapacityDense;
|
||||||
|
public int CapacitySparce => _group.CapacitySparce;
|
||||||
|
|
||||||
|
public DebuggerProxy(EcsGroup group) => _group = group;
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
#endregion
|
|
||||||
}
|
}
|
@ -20,7 +20,6 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
private bool _isInit;
|
private bool _isInit;
|
||||||
private bool _isDestoryed;
|
private bool _isDestoryed;
|
||||||
private bool _isEmptyDummy;
|
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
public ReadOnlyCollection<IEcsSystem> AllSystems => _allSystemsSealed;
|
public ReadOnlyCollection<IEcsSystem> AllSystems => _allSystemsSealed;
|
||||||
@ -39,7 +38,6 @@ namespace DCFApixels.DragonECS
|
|||||||
_allRunnersSealed = new ReadOnlyDictionary<Type, IEcsRunner>(_runners);
|
_allRunnersSealed = new ReadOnlyDictionary<Type, IEcsRunner>(_runners);
|
||||||
|
|
||||||
_isInit = false;
|
_isInit = false;
|
||||||
_isEmptyDummy = false;
|
|
||||||
_isDestoryed = false;
|
_isDestoryed = false;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@ -64,9 +62,6 @@ namespace DCFApixels.DragonECS
|
|||||||
#region LifeCycle
|
#region LifeCycle
|
||||||
public void Init()
|
public void Init()
|
||||||
{
|
{
|
||||||
if (_isEmptyDummy)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (_isInit == true)
|
if (_isInit == true)
|
||||||
{
|
{
|
||||||
EcsDebug.Print("[Warning]", $"This {nameof(EcsPipeline)} has already been initialized");
|
EcsDebug.Print("[Warning]", $"This {nameof(EcsPipeline)} has already been initialized");
|
||||||
@ -98,9 +93,6 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
public void Destroy()
|
public void Destroy()
|
||||||
{
|
{
|
||||||
if (_isEmptyDummy)
|
|
||||||
return;
|
|
||||||
|
|
||||||
#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS
|
#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS
|
||||||
CheckBeforeInitForMethod(nameof(Run));
|
CheckBeforeInitForMethod(nameof(Run));
|
||||||
#endif
|
#endif
|
||||||
@ -135,10 +127,7 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Builder
|
#region Builder
|
||||||
public static Builder New()
|
public static Builder New() => new Builder();
|
||||||
{
|
|
||||||
return new Builder();
|
|
||||||
}
|
|
||||||
public class Builder
|
public class Builder
|
||||||
{
|
{
|
||||||
private const int KEYS_CAPACITY = 4;
|
private const int KEYS_CAPACITY = 4;
|
||||||
@ -149,16 +138,12 @@ namespace DCFApixels.DragonECS
|
|||||||
public Builder()
|
public Builder()
|
||||||
{
|
{
|
||||||
_basicLayer = EcsConsts.BASIC_LAYER;
|
_basicLayer = EcsConsts.BASIC_LAYER;
|
||||||
|
|
||||||
Layers = new LayerList(this, _basicLayer);
|
Layers = new LayerList(this, _basicLayer);
|
||||||
|
|
||||||
Layers.Insert(EcsConsts.BASIC_LAYER, EcsConsts.PRE_BEGIN_LAYER, EcsConsts.BEGIN_LAYER);
|
Layers.Insert(EcsConsts.BASIC_LAYER, EcsConsts.PRE_BEGIN_LAYER, EcsConsts.BEGIN_LAYER);
|
||||||
Layers.InsertAfter(EcsConsts.BASIC_LAYER, EcsConsts.END_LAYER, EcsConsts.POST_END_LAYER);
|
Layers.InsertAfter(EcsConsts.BASIC_LAYER, EcsConsts.END_LAYER, EcsConsts.POST_END_LAYER);
|
||||||
|
|
||||||
_uniqueTypes = new HashSet<Type>();
|
_uniqueTypes = new HashSet<Type>();
|
||||||
_systems = new Dictionary<string, List<IEcsSystem>>(KEYS_CAPACITY);
|
_systems = new Dictionary<string, List<IEcsSystem>>(KEYS_CAPACITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder Add(IEcsSystem system, string layerName = null)
|
public Builder Add(IEcsSystem system, string layerName = null)
|
||||||
{
|
{
|
||||||
AddInternal(system, layerName, false);
|
AddInternal(system, layerName, false);
|
||||||
@ -182,7 +167,7 @@ namespace DCFApixels.DragonECS
|
|||||||
List<IEcsSystem> list;
|
List<IEcsSystem> list;
|
||||||
if (!_systems.TryGetValue(layerName, out list))
|
if (!_systems.TryGetValue(layerName, out list))
|
||||||
{
|
{
|
||||||
list = new List<IEcsSystem> { new SystemsBlockMarkerSystem(layerName.ToString()) };
|
list = new List<IEcsSystem> { new SystemsLayerMarkerSystem(layerName.ToString()) };
|
||||||
_systems.Add(layerName, list);
|
_systems.Add(layerName, list);
|
||||||
}
|
}
|
||||||
if ((_uniqueTypes.Add(system.GetType()) == false && isUnique))
|
if ((_uniqueTypes.Add(system.GetType()) == false && isUnique))
|
||||||
@ -192,20 +177,16 @@ namespace DCFApixels.DragonECS
|
|||||||
if (system is IEcsModule module)//если система одновременно явялется и системой и модулем то за один Add будет вызван Add и AddModule
|
if (system is IEcsModule module)//если система одновременно явялется и системой и модулем то за один Add будет вызван Add и AddModule
|
||||||
AddModule(module);
|
AddModule(module);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder AddModule(IEcsModule module)
|
public Builder AddModule(IEcsModule module)
|
||||||
{
|
{
|
||||||
module.ImportSystems(this);
|
module.ImportSystems(this);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EcsPipeline Build()
|
public EcsPipeline Build()
|
||||||
{
|
{
|
||||||
Add(new DeleteEmptyEntitesSystem(), EcsConsts.POST_END_LAYER);
|
Add(new DeleteEmptyEntitesSystem(), EcsConsts.POST_END_LAYER);
|
||||||
|
|
||||||
List<IEcsSystem> result = new List<IEcsSystem>(32);
|
List<IEcsSystem> result = new List<IEcsSystem>(32);
|
||||||
List<IEcsSystem> basicBlockList = _systems[_basicLayer];
|
List<IEcsSystem> basicBlockList = _systems[_basicLayer];
|
||||||
|
|
||||||
foreach (var item in _systems)
|
foreach (var item in _systems)
|
||||||
{
|
{
|
||||||
if (!Layers.Has(item.Key))
|
if (!Layers.Has(item.Key))
|
||||||
@ -216,17 +197,14 @@ namespace DCFApixels.DragonECS
|
|||||||
if(_systems.TryGetValue(item, out var list))
|
if(_systems.TryGetValue(item, out var list))
|
||||||
result.AddRange(list);
|
result.AddRange(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new EcsPipeline(result.ToArray());
|
return new EcsPipeline(result.ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LayerList : IEnumerable<string>
|
public class LayerList : IEnumerable<string>
|
||||||
{
|
{
|
||||||
private const string ADD_LAYER = nameof(ADD_LAYER); // автоматический слой нужный только для метода Add
|
private const string ADD_LAYER = nameof(ADD_LAYER); // автоматический слой нужный только для метода Add
|
||||||
|
|
||||||
private Builder _source;
|
private Builder _source;
|
||||||
private List<string> _layers;
|
private List<string> _layers;
|
||||||
|
|
||||||
private string _basicLayerName;
|
private string _basicLayerName;
|
||||||
|
|
||||||
public LayerList(Builder source, string basicLayerName)
|
public LayerList(Builder source, string basicLayerName)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using DCFApixels.DragonECS.RunnersCore;
|
||||||
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
@ -9,9 +10,6 @@ using static DCFApixels.DragonECS.EcsDebugUtility;
|
|||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
using RunnersCore;
|
|
||||||
using System.ComponentModel;
|
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)]
|
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)]
|
||||||
sealed class EcsRunnerFilterAttribute : Attribute
|
sealed class EcsRunnerFilterAttribute : Attribute
|
||||||
{
|
{
|
||||||
@ -29,7 +27,6 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
namespace RunnersCore
|
namespace RunnersCore
|
||||||
{
|
{
|
||||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
||||||
public interface IEcsRunner
|
public interface IEcsRunner
|
||||||
{
|
{
|
||||||
EcsPipeline Source { get; }
|
EcsPipeline Source { get; }
|
||||||
@ -122,7 +119,9 @@ namespace DCFApixels.DragonECS
|
|||||||
EcsRunner<TInterface>.Register(runnerType);
|
EcsRunner<TInterface>.Register(runnerType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
#if UNITY_2020_3_OR_NEWER
|
||||||
|
[UnityEngine.Scripting.RequireDerived, UnityEngine.Scripting.Preserve]
|
||||||
|
#endif
|
||||||
public abstract class EcsRunner<TInterface> : IEcsSystem, IEcsRunner
|
public abstract class EcsRunner<TInterface> : IEcsSystem, IEcsRunner
|
||||||
where TInterface : IEcsSystem
|
where TInterface : IEcsSystem
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -65,6 +67,7 @@ namespace DCFApixels.DragonECS
|
|||||||
return (TSubject)newSubject;
|
return (TSubject)newSubject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Include/Exclude/Optional
|
||||||
public sealed override TPool Include<TComponent, TPool>()
|
public sealed override TPool Include<TComponent, TPool>()
|
||||||
{
|
{
|
||||||
IncludeImplicit<TComponent>();
|
IncludeImplicit<TComponent>();
|
||||||
@ -79,7 +82,6 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return _world.GetPool<TComponent, TPool>();
|
return _world.GetPool<TComponent, TPool>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void IncludeImplicit<TComponent>()
|
public void IncludeImplicit<TComponent>()
|
||||||
{
|
{
|
||||||
int id = _world.GetComponentID<TComponent>();
|
int id = _world.GetComponentID<TComponent>();
|
||||||
@ -96,6 +98,7 @@ namespace DCFApixels.DragonECS
|
|||||||
#endif
|
#endif
|
||||||
_exc.Add(_world.GetComponentID<TComponent>());
|
_exc.Add(_world.GetComponentID<TComponent>());
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
private void End(out EcsMask mask)
|
private void End(out EcsMask mask)
|
||||||
{
|
{
|
||||||
@ -106,6 +109,20 @@ namespace DCFApixels.DragonECS
|
|||||||
_inc = null;
|
_inc = null;
|
||||||
_exc = null;
|
_exc = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region SupportReflectionHack
|
||||||
|
#if UNITY_2020_3_OR_NEWER
|
||||||
|
[UnityEngine.Scripting.Preserve]
|
||||||
|
#endif
|
||||||
|
private void SupportReflectionHack<TComponent, TPool>() where TPool : IEcsPoolImplementation<TComponent>, new()
|
||||||
|
{
|
||||||
|
Include<TComponent, TPool>();
|
||||||
|
Exclude<TComponent, TPool>();
|
||||||
|
Optional<TComponent, TPool>();
|
||||||
|
IncludeImplicit<TComponent>();
|
||||||
|
ExcludeImplicit<TComponent>();
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
@ -127,13 +144,14 @@ namespace DCFApixels.DragonECS
|
|||||||
#region BuilderBase
|
#region BuilderBase
|
||||||
public abstract class EcsSubjectBuilderBase
|
public abstract class EcsSubjectBuilderBase
|
||||||
{
|
{
|
||||||
public abstract TPool Include<TComponent, TPool>() where TComponent : struct where TPool : IEcsPoolImplementation<TComponent>, new();
|
public abstract TPool Include<TComponent, TPool>() where TPool : IEcsPoolImplementation<TComponent>, new();
|
||||||
public abstract TPool Exclude<TComponent, TPool>() where TComponent : struct where TPool : IEcsPoolImplementation<TComponent>, new();
|
public abstract TPool Exclude<TComponent, TPool>() where TPool : IEcsPoolImplementation<TComponent>, new();
|
||||||
public abstract TPool Optional<TComponent, TPool>() where TComponent : struct where TPool : IEcsPoolImplementation<TComponent>, new();
|
public abstract TPool Optional<TComponent, TPool>() where TPool : IEcsPoolImplementation<TComponent>, new();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Mask
|
#region Mask
|
||||||
|
[DebuggerTypeProxy(typeof(DebuggerProxy))]
|
||||||
public sealed class EcsMask
|
public sealed class EcsMask
|
||||||
{
|
{
|
||||||
internal readonly Type _worldType;
|
internal readonly Type _worldType;
|
||||||
@ -145,10 +163,40 @@ namespace DCFApixels.DragonECS
|
|||||||
_inc = inc;
|
_inc = inc;
|
||||||
_exc = exc;
|
_exc = exc;
|
||||||
}
|
}
|
||||||
public override string ToString()
|
|
||||||
|
public override string ToString() => CreateLogString(_worldType, _inc, _exc);
|
||||||
|
|
||||||
|
#region Debug utils
|
||||||
|
private static string CreateLogString(Type worldType, int[] inc, int[] exc)
|
||||||
{
|
{
|
||||||
return $"Inc({string.Join(", ", _inc)}) Exc({string.Join(", ", _exc)})";
|
#if DEBUG
|
||||||
|
int worldID = WorldMetaStorage.GetWorldID(worldType);
|
||||||
|
string converter(int o) => EcsDebugUtility.GetGenericTypeName(WorldMetaStorage.GetComponentType(worldID, o), 1);
|
||||||
|
return $"Inc({string.Join(", ", inc.Select(converter))}) Exc({string.Join(", ", exc.Select(converter))})";
|
||||||
|
#else
|
||||||
|
return $"Inc({string.Join(", ", inc)}) Exc({string.Join(", ", exc)})"; // Release optimization
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
internal class DebuggerProxy
|
||||||
|
{
|
||||||
|
public readonly Type worldType;
|
||||||
|
public readonly int[] inc;
|
||||||
|
public readonly int[] exc;
|
||||||
|
public readonly Type[] incTypes;
|
||||||
|
public readonly Type[] excTypes;
|
||||||
|
public DebuggerProxy(EcsMask mask)
|
||||||
|
{
|
||||||
|
worldType = mask._worldType;
|
||||||
|
int worldID = WorldMetaStorage.GetWorldID(worldType);
|
||||||
|
inc = mask._inc;
|
||||||
|
exc = mask._exc;
|
||||||
|
Type converter(int o) => WorldMetaStorage.GetComponentType(worldID, o);
|
||||||
|
incTypes = inc.Select(converter).ToArray();
|
||||||
|
excTypes = exc.Select(converter).ToArray();
|
||||||
|
}
|
||||||
|
public override string ToString() => CreateLogString(worldType, inc, exc);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -156,25 +204,25 @@ namespace DCFApixels.DragonECS
|
|||||||
public ref struct EcsSubjectIterator<TSubject> where TSubject : EcsSubject
|
public ref struct EcsSubjectIterator<TSubject> where TSubject : EcsSubject
|
||||||
{
|
{
|
||||||
public readonly TSubject s;
|
public readonly TSubject s;
|
||||||
private EcsReadonlyGroup sourceGroup;
|
private EcsReadonlyGroup _sourceGroup;
|
||||||
private Enumerator enumerator;
|
private Enumerator _enumerator;
|
||||||
|
|
||||||
public EcsSubjectIterator(TSubject s, EcsReadonlyGroup sourceGroup)
|
public EcsSubjectIterator(TSubject s, EcsReadonlyGroup sourceGroup)
|
||||||
{
|
{
|
||||||
this.s = s;
|
this.s = s;
|
||||||
this.sourceGroup = sourceGroup;
|
_sourceGroup = sourceGroup;
|
||||||
enumerator = default;
|
_enumerator = default;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Entity
|
public int Entity
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
get => enumerator.Current;
|
get => _enumerator.Current;
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public void Begin() => enumerator = GetEnumerator();
|
public void Begin() => _enumerator = GetEnumerator();
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public bool Next() => enumerator.MoveNext();
|
public bool Next() => _enumerator.MoveNext();
|
||||||
public void CopyTo(EcsGroup group)
|
public void CopyTo(EcsGroup group)
|
||||||
{
|
{
|
||||||
group.Clear();
|
group.Clear();
|
||||||
@ -183,7 +231,7 @@ namespace DCFApixels.DragonECS
|
|||||||
group.AddInternal(enumerator.Current);
|
group.AddInternal(enumerator.Current);
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public Enumerator GetEnumerator() => new Enumerator(sourceGroup, s);
|
public Enumerator GetEnumerator() => new Enumerator(_sourceGroup, s);
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
|
156
src/EcsWorld.cs
156
src/EcsWorld.cs
@ -26,9 +26,6 @@ namespace DCFApixels.DragonECS
|
|||||||
private short[] _componentCounts;
|
private short[] _componentCounts;
|
||||||
private EcsGroup _allEntites;
|
private EcsGroup _allEntites;
|
||||||
|
|
||||||
//буфер удаления откладывает освобождение андишников сущностей.
|
|
||||||
//Нужен для того чтобы запускать некоторые процесыы связанные с удалением сущности не по одному при каждом удалении, а пачкой
|
|
||||||
//В теории такой подход частично улучшает ситуацию с переполнением поколений
|
|
||||||
private int[] _delEntBuffer;
|
private int[] _delEntBuffer;
|
||||||
private int _delEntBufferCount;
|
private int _delEntBufferCount;
|
||||||
|
|
||||||
@ -75,7 +72,7 @@ namespace DCFApixels.DragonECS
|
|||||||
Worlds[uniqueID] = this;
|
Worlds[uniqueID] = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
_worldTypeID = WorldMetaStorage.GetWorldId(Archetype);
|
_worldTypeID = WorldMetaStorage.GetWorldID(Archetype);
|
||||||
|
|
||||||
_entityDispenser = new IntDispenser(0);
|
_entityDispenser = new IntDispenser(0);
|
||||||
_nullPool = EcsNullPool.instance;
|
_nullPool = EcsNullPool.instance;
|
||||||
@ -95,7 +92,6 @@ namespace DCFApixels.DragonECS
|
|||||||
_subjects = new EcsSubject[128];
|
_subjects = new EcsSubject[128];
|
||||||
_executors = new EcsQueryExecutor[128];
|
_executors = new EcsQueryExecutor[128];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Destroy()
|
public void Destroy()
|
||||||
{
|
{
|
||||||
_entityDispenser = null;
|
_entityDispenser = null;
|
||||||
@ -109,10 +105,6 @@ namespace DCFApixels.DragonECS
|
|||||||
Worlds[uniqueID] = null;
|
Worlds[uniqueID] = null;
|
||||||
_worldIdDispenser.Release(uniqueID);
|
_worldIdDispenser.Release(uniqueID);
|
||||||
}
|
}
|
||||||
public void DestryWithPipeline()
|
|
||||||
{
|
|
||||||
Destroy();
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GetComponentID
|
#region GetComponentID
|
||||||
@ -121,26 +113,25 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GetPool
|
#region GetPool
|
||||||
public TPool GetPool<TComponent, TPool>() where TComponent : struct where TPool : IEcsPoolImplementation<TComponent>, new()
|
#if UNITY_2020_3_OR_NEWER
|
||||||
|
[UnityEngine.Scripting.Preserve]
|
||||||
|
#endif
|
||||||
|
public TPool GetPool<TComponent, TPool>() where TPool : IEcsPoolImplementation<TComponent>, new()
|
||||||
{
|
{
|
||||||
int uniqueID = WorldMetaStorage.GetComponentId<TComponent>(_worldTypeID);
|
int uniqueID = WorldMetaStorage.GetComponentId<TComponent>(_worldTypeID);
|
||||||
|
|
||||||
if (uniqueID >= _pools.Length)
|
if (uniqueID >= _pools.Length)
|
||||||
{
|
{
|
||||||
int oldCapacity = _pools.Length;
|
int oldCapacity = _pools.Length;
|
||||||
Array.Resize(ref _pools, _pools.Length << 1);
|
Array.Resize(ref _pools, _pools.Length << 1);
|
||||||
ArrayUtility.Fill(_pools, _nullPool, oldCapacity, oldCapacity - _pools.Length);
|
ArrayUtility.Fill(_pools, _nullPool, oldCapacity, oldCapacity - _pools.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_pools[uniqueID] == _nullPool)
|
if (_pools[uniqueID] == _nullPool)
|
||||||
{
|
{
|
||||||
var pool = new TPool();
|
var pool = new TPool();
|
||||||
_pools[uniqueID] = pool;
|
_pools[uniqueID] = pool;
|
||||||
pool.OnInit(this, uniqueID);
|
pool.OnInit(this, uniqueID);
|
||||||
_poolsCount++;
|
_poolsCount++;
|
||||||
//EcsDebug.Print(pool.GetType().FullName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (TPool)_pools[uniqueID];
|
return (TPool)_pools[uniqueID];
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@ -158,39 +149,38 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Queries
|
#region Queries
|
||||||
public TExecutor GetExecutor<TExecutor>(Func<EcsWorld, TExecutor> builder) where TExecutor: EcsQueryExecutor
|
public TExecutor GetExecutor<TExecutor>() where TExecutor : EcsQueryExecutor, new()
|
||||||
{
|
{
|
||||||
int id = WorldMetaStorage.GetExecutorId<TExecutor>(_worldTypeID);
|
int id = WorldMetaStorage.GetExecutorId<TExecutor>(_worldTypeID);
|
||||||
if (id >= _executors.Length)
|
if (id >= _executors.Length)
|
||||||
Array.Resize(ref _executors, _executors.Length << 1);
|
Array.Resize(ref _executors, _executors.Length << 1);
|
||||||
if (_executors[id] == null)
|
if (_executors[id] == null)
|
||||||
_executors[id] = builder(this);
|
{
|
||||||
|
var executor = new TExecutor();
|
||||||
|
executor.Initialize(this);
|
||||||
|
_executors[id] = executor;
|
||||||
|
}
|
||||||
return (TExecutor)_executors[id];
|
return (TExecutor)_executors[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
private EcsWhereExecutor<TSubject> EcsWhereExecutorBuilder<TSubject>(EcsWorld world) where TSubject : EcsSubject
|
|
||||||
{
|
|
||||||
return new EcsWhereExecutor<TSubject>(world.GetSubject<TSubject>());
|
|
||||||
}
|
|
||||||
public EcsWhereResult<TSubject> WhereFor<TSubject>(EcsReadonlyGroup sourceGroup, out TSubject subject) where TSubject : EcsSubject
|
public EcsWhereResult<TSubject> WhereFor<TSubject>(EcsReadonlyGroup sourceGroup, out TSubject subject) where TSubject : EcsSubject
|
||||||
{
|
{
|
||||||
var executor = GetExecutor(EcsWhereExecutorBuilder<TSubject>);
|
var executor = GetExecutor<EcsWhereExecutor<TSubject>>();
|
||||||
subject = executor.Subject;
|
subject = executor.Subject;
|
||||||
return executor.ExecuteFor(sourceGroup);
|
return executor.ExecuteFor(sourceGroup);
|
||||||
}
|
}
|
||||||
public EcsWhereResult<TSubject> WhereFor<TSubject>(EcsReadonlyGroup sourceGroup) where TSubject : EcsSubject
|
public EcsWhereResult<TSubject> WhereFor<TSubject>(EcsReadonlyGroup sourceGroup) where TSubject : EcsSubject
|
||||||
{
|
{
|
||||||
return GetExecutor(EcsWhereExecutorBuilder<TSubject>).ExecuteFor(sourceGroup);
|
return GetExecutor<EcsWhereExecutor<TSubject>>().ExecuteFor(sourceGroup);
|
||||||
}
|
}
|
||||||
public EcsWhereResult<TSubject> Where<TSubject>(out TSubject subject) where TSubject : EcsSubject
|
public EcsWhereResult<TSubject> Where<TSubject>(out TSubject subject) where TSubject : EcsSubject
|
||||||
{
|
{
|
||||||
var executor = GetExecutor(EcsWhereExecutorBuilder<TSubject>);
|
var executor = GetExecutor<EcsWhereExecutor<TSubject>>();
|
||||||
subject = executor.Subject;
|
subject = executor.Subject;
|
||||||
return executor.Execute();
|
return executor.Execute();
|
||||||
}
|
}
|
||||||
public EcsWhereResult<TSubject> Where<TSubject>() where TSubject : EcsSubject
|
public EcsWhereResult<TSubject> Where<TSubject>() where TSubject : EcsSubject
|
||||||
{
|
{
|
||||||
return GetExecutor(EcsWhereExecutorBuilder<TSubject>).Execute();
|
return GetExecutor<EcsWhereExecutor<TSubject>>().Execute();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -332,15 +322,16 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Groups
|
#region Groups Pool
|
||||||
internal void RegisterGroup(EcsGroup group)
|
internal void RegisterGroup(EcsGroup group)
|
||||||
{
|
{
|
||||||
_groups.Add(new WeakReference<EcsGroup>(group));
|
_groups.Add(new WeakReference<EcsGroup>(group));
|
||||||
}
|
}
|
||||||
internal EcsGroup GetGroupFromPool()
|
internal EcsGroup GetGroupFromPool()
|
||||||
{
|
{
|
||||||
if (_groupsPool.Count <= 0) return new EcsGroup(this);
|
EcsGroup result = _groupsPool.Count <= 0 ? new EcsGroup(this) : _groupsPool.Pop();
|
||||||
return _groupsPool.Pop();
|
result._isReleased = false;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
internal void ReleaseGroup(EcsGroup group)
|
internal void ReleaseGroup(EcsGroup group)
|
||||||
{
|
{
|
||||||
@ -348,6 +339,7 @@ namespace DCFApixels.DragonECS
|
|||||||
if (group.World != this)
|
if (group.World != this)
|
||||||
throw new ArgumentException("groupFilter.WorldIndex != this");
|
throw new ArgumentException("groupFilter.WorldIndex != this");
|
||||||
#endif
|
#endif
|
||||||
|
group._isReleased = true;
|
||||||
group.Clear();
|
group.Clear();
|
||||||
_groupsPool.Push(group);
|
_groupsPool.Push(group);
|
||||||
}
|
}
|
||||||
@ -369,40 +361,13 @@ namespace DCFApixels.DragonECS
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
// public int GetComponents(int entity, ref object[] list)
|
#region NullWorld
|
||||||
// {
|
private sealed class EcsNullWorld : EcsWorld<EcsNullWorld>
|
||||||
// var entityOffset = GetRawEntityOffset(entity);
|
{
|
||||||
// var itemsCount = _entities[entityOffset + RawEntityOffsets.ComponentsCount];
|
public EcsNullWorld() : base(false) { }
|
||||||
// if (itemsCount == 0) { return 0; }
|
}
|
||||||
// if (list == null || list.Length < itemsCount)
|
|
||||||
// {
|
|
||||||
// list = new object[_pools.Length];
|
|
||||||
// }
|
|
||||||
// var dataOffset = entityOffset + RawEntityOffsets.Components;
|
|
||||||
// for (var i = 0; i < itemsCount; i++)
|
|
||||||
// {
|
|
||||||
// list[i] = _pools[_entities[dataOffset + i]].GetRaw(entity);
|
|
||||||
// }
|
|
||||||
// return itemsCount;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public int GetComponentTypes(int entity, ref Type[] list)
|
|
||||||
// {
|
|
||||||
// var entityOffset = GetRawEntityOffset(entity);
|
|
||||||
// var itemsCount = _entities[entityOffset + RawEntityOffsets.ComponentsCount];
|
|
||||||
// if (itemsCount == 0) { return 0; }
|
|
||||||
// if (list == null || list.Length < itemsCount)
|
|
||||||
// {
|
|
||||||
// list = new Type[_pools.Length];
|
|
||||||
// }
|
|
||||||
// var dataOffset = entityOffset + RawEntityOffsets.Components;
|
|
||||||
// for (var i = 0; i < itemsCount; i++)
|
|
||||||
// {
|
|
||||||
// list[i] = _pools[_entities[dataOffset + i]].GetComponentType();
|
|
||||||
// }
|
|
||||||
// return itemsCount;
|
|
||||||
// }
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -414,31 +379,33 @@ namespace DCFApixels.DragonECS
|
|||||||
internal EcsWorld(bool isIndexable) : base(isIndexable) { }
|
internal EcsWorld(bool isIndexable) : base(isIndexable) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Utils
|
#region WorldMetaStorage
|
||||||
public static class WorldMetaStorage
|
public static class WorldMetaStorage
|
||||||
{
|
{
|
||||||
private static List<Resizer> _resizer = new List<Resizer>();
|
private static List<Resizer> _resizer = new List<Resizer>();
|
||||||
private static int _tokenCount = 0;
|
private static int _tokenCount = 0;
|
||||||
private static int[] _componentCounts = new int[0];
|
|
||||||
private static int[] _subjectsCounts = new int[0];
|
private static WorldTypeMeta[] _metas = new WorldTypeMeta[0];
|
||||||
private static Dictionary<Type, int> _worldIds = new Dictionary<Type, int>();
|
private static Dictionary<Type, int> _worldIds = new Dictionary<Type, int>();
|
||||||
private static class WorldIndex<TWorldArchetype>
|
private static class WorldIndex<TWorldArchetype>
|
||||||
{
|
{
|
||||||
public static int id = GetWorldId(typeof(TWorldArchetype));
|
public static int id = GetWorldID(typeof(TWorldArchetype));
|
||||||
}
|
}
|
||||||
private static int GetToken()
|
private static int GetToken()
|
||||||
{
|
{
|
||||||
_tokenCount++;
|
WorldTypeMeta meta = new WorldTypeMeta();
|
||||||
Array.Resize(ref _componentCounts, _tokenCount);
|
meta.id = _tokenCount;
|
||||||
Array.Resize(ref _subjectsCounts, _tokenCount);
|
Array.Resize(ref _metas, ++_tokenCount);
|
||||||
|
_metas[_tokenCount - 1] = meta;
|
||||||
|
|
||||||
foreach (var item in _resizer)
|
foreach (var item in _resizer)
|
||||||
item.Resize(_tokenCount);
|
item.Resize(_tokenCount);
|
||||||
return _tokenCount - 1;
|
return _tokenCount - 1;
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static int GetWorldId(Type archetype)
|
public static int GetWorldID(Type archetype)
|
||||||
{
|
{
|
||||||
if(_worldIds.TryGetValue(archetype, out int id) == false)
|
if(!_worldIds.TryGetValue(archetype, out int id))
|
||||||
{
|
{
|
||||||
id = GetToken();
|
id = GetToken();
|
||||||
_worldIds.Add(archetype, id);
|
_worldIds.Add(archetype, id);
|
||||||
@ -453,6 +420,11 @@ namespace DCFApixels.DragonECS
|
|||||||
public static int GetSubjectId<T>(int worldID) => Subject<T>.Get(worldID);
|
public static int GetSubjectId<T>(int worldID) => Subject<T>.Get(worldID);
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static int GetExecutorId<T>(int worldID) => Executor<T>.Get(worldID);
|
public static int GetExecutorId<T>(int worldID) => Executor<T>.Get(worldID);
|
||||||
|
|
||||||
|
public static bool IsComponentTypeDeclared(int worldID, Type type) => _metas[worldID].IsDeclaredType(type);
|
||||||
|
public static Type GetComponentType(int worldID, int componentID) => _metas[worldID].GetComponentType(componentID);
|
||||||
|
|
||||||
|
#region Resizer
|
||||||
private abstract class Resizer
|
private abstract class Resizer
|
||||||
{
|
{
|
||||||
public abstract void Resize(int size);
|
public abstract void Resize(int size);
|
||||||
@ -466,6 +438,7 @@ namespace DCFApixels.DragonECS
|
|||||||
Array.Resize(ref Executor<T>.ids, size);
|
Array.Resize(ref Executor<T>.ids, size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endregion
|
||||||
private static class Component<T>
|
private static class Component<T>
|
||||||
{
|
{
|
||||||
public static int[] ids;
|
public static int[] ids;
|
||||||
@ -481,7 +454,11 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
ref int id = ref ids[token];
|
ref int id = ref ids[token];
|
||||||
if (id < 0)
|
if (id < 0)
|
||||||
id = _componentCounts[token]++;
|
{
|
||||||
|
var meta = _metas[token];
|
||||||
|
id = meta.componentCount++;
|
||||||
|
meta.AddType(id, typeof(T));
|
||||||
|
}
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -500,7 +477,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
ref int id = ref ids[token];
|
ref int id = ref ids[token];
|
||||||
if (id < 0)
|
if (id < 0)
|
||||||
id = _subjectsCounts[token]++;
|
id = _metas[token].subjectsCount++;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -519,10 +496,35 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
ref int id = ref ids[token];
|
ref int id = ref ids[token];
|
||||||
if (id < 0)
|
if (id < 0)
|
||||||
id = _subjectsCounts[token]++;
|
id = _metas[token].executorsCount++;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class WorldTypeMeta
|
||||||
|
{
|
||||||
|
public int id;
|
||||||
|
public int componentCount;
|
||||||
|
public int subjectsCount;
|
||||||
|
public int executorsCount;
|
||||||
|
private Type[] types;
|
||||||
|
private HashSet<Type> declaredComponentTypes;
|
||||||
|
public void AddType(int id, Type type)
|
||||||
|
{
|
||||||
|
if(types.Length <= id)
|
||||||
|
Array.Resize(ref types, id + 10);
|
||||||
|
types[id] = type;
|
||||||
|
|
||||||
|
declaredComponentTypes.Add(type);
|
||||||
|
}
|
||||||
|
public Type GetComponentType(int componentID) => types[componentID];
|
||||||
|
public bool IsDeclaredType(Type type) => declaredComponentTypes.Contains(type);
|
||||||
|
public WorldTypeMeta()
|
||||||
|
{
|
||||||
|
types = new Type[10];
|
||||||
|
declaredComponentTypes = new HashSet<Type>();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -564,4 +566,12 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Extensions
|
||||||
|
public static class IntExtensions
|
||||||
|
{
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static entlong ToEntityLong(this int self, EcsWorld world) => world.GetEntityLong(self);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,14 @@
|
|||||||
{
|
{
|
||||||
public abstract class EcsQueryExecutor
|
public abstract class EcsQueryExecutor
|
||||||
{
|
{
|
||||||
|
private EcsWorld _world;
|
||||||
|
public EcsWorld World => _world;
|
||||||
|
internal void Initialize(EcsWorld world)
|
||||||
|
{
|
||||||
|
_world = world;
|
||||||
|
OnInitialize();
|
||||||
|
}
|
||||||
|
protected abstract void OnInitialize();
|
||||||
internal void Destroy() => OnDestroy();
|
internal void Destroy() => OnDestroy();
|
||||||
protected abstract void OnDestroy();
|
protected abstract void OnDestroy();
|
||||||
}
|
}
|
||||||
|
@ -1,26 +1,28 @@
|
|||||||
using Unity.Profiling;
|
namespace DCFApixels.DragonECS
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
|
||||||
{
|
{
|
||||||
public sealed class EcsWhereExecutor<TSubject> : EcsQueryExecutor where TSubject : EcsSubject
|
public sealed class EcsWhereExecutor<TSubject> : EcsQueryExecutor where TSubject : EcsSubject
|
||||||
{
|
{
|
||||||
private readonly TSubject _subject;
|
private TSubject _subject;
|
||||||
private readonly EcsGroup _filteredGroup;
|
private EcsGroup _filteredGroup;
|
||||||
|
|
||||||
private long _executeVersion;
|
private long _executeVersion;
|
||||||
|
|
||||||
private ProfilerMarker _executeWhere = new ProfilerMarker("JoinAttachQuery.Where");
|
private EcsProfilerMarker _executeWhere = new EcsProfilerMarker("Where");
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
public TSubject Subject => _subject;
|
public TSubject Subject => _subject;
|
||||||
internal long ExecuteVersion => _executeVersion;
|
internal long ExecuteVersion => _executeVersion;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region OnInitialize/OnDestroy
|
||||||
public EcsWhereExecutor(TSubject subject)
|
protected sealed override void OnInitialize()
|
||||||
{
|
{
|
||||||
_subject = subject;
|
_subject = World.GetSubject<TSubject>();
|
||||||
_filteredGroup = EcsGroup.New(subject.World);
|
_filteredGroup = EcsGroup.New(World);
|
||||||
|
}
|
||||||
|
protected sealed override void OnDestroy()
|
||||||
|
{
|
||||||
|
_filteredGroup.Release();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -37,10 +39,6 @@ namespace DCFApixels.DragonECS
|
|||||||
return new EcsWhereResult<TSubject>(this, _filteredGroup.Readonly);
|
return new EcsWhereResult<TSubject>(this, _filteredGroup.Readonly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected sealed override void OnDestroy()
|
|
||||||
{
|
|
||||||
_filteredGroup.Release();
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +50,6 @@ namespace DCFApixels.DragonECS
|
|||||||
public readonly EcsReadonlyGroup group;
|
public readonly EcsReadonlyGroup group;
|
||||||
private readonly long _version;
|
private readonly long _version;
|
||||||
public bool IsRelevant => _version == _executer.ExecuteVersion;
|
public bool IsRelevant => _version == _executer.ExecuteVersion;
|
||||||
|
|
||||||
public EcsWhereResult(EcsWhereExecutor<TSubject> executer, EcsReadonlyGroup group)
|
public EcsWhereResult(EcsWhereExecutor<TSubject> executer, EcsReadonlyGroup group)
|
||||||
{
|
{
|
||||||
_executer = executer;
|
_executer = executer;
|
||||||
@ -67,7 +64,6 @@ namespace DCFApixels.DragonECS
|
|||||||
#endif
|
#endif
|
||||||
return group.GetEnumerator();
|
return group.GetEnumerator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return group.ToString();
|
return group.ToString();
|
||||||
|
@ -31,15 +31,6 @@ namespace DCFApixels.DragonECS
|
|||||||
void RemoveListener(IEcsPoolEventListener listener);
|
void RemoveListener(IEcsPoolEventListener listener);
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
public interface IEcsPoolEventListener
|
|
||||||
{
|
|
||||||
/// <summary>Called after adding an entity to the pool, but before changing values.</summary>
|
|
||||||
void OnAdd(int entityID);
|
|
||||||
/// <summary>Is called when EcsPool.Write or EcsPool.Add is called, but before changing values.</summary>
|
|
||||||
void OnWrite(int entityID);
|
|
||||||
/// <summary>Called after deleting an entity from the pool</summary>
|
|
||||||
void OnDel(int entityID);
|
|
||||||
}
|
|
||||||
public interface IEcsPool<T>
|
public interface IEcsPool<T>
|
||||||
{
|
{
|
||||||
ref T Add(int entityID);
|
ref T Add(int entityID);
|
||||||
@ -47,7 +38,6 @@ namespace DCFApixels.DragonECS
|
|||||||
ref T Write(int entityID);
|
ref T Write(int entityID);
|
||||||
}
|
}
|
||||||
/// <summary>Only used to implement a custom pool. In other contexts use IEcsPool or IEcsPool<T>.</summary>
|
/// <summary>Only used to implement a custom pool. In other contexts use IEcsPool or IEcsPool<T>.</summary>
|
||||||
/// <typeparam name="T">Component type</typeparam>
|
|
||||||
public interface IEcsPoolImplementation : IEcsPool
|
public interface IEcsPoolImplementation : IEcsPool
|
||||||
{
|
{
|
||||||
void OnInit(EcsWorld world, int componentID);
|
void OnInit(EcsWorld world, int componentID);
|
||||||
@ -98,7 +88,7 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Dummy
|
#region Dummy EcsNullPool
|
||||||
namespace Internal
|
namespace Internal
|
||||||
{
|
{
|
||||||
public struct NullComponent { }
|
public struct NullComponent { }
|
||||||
@ -216,7 +206,16 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Extensions
|
#region Callbacks Interface
|
||||||
|
public interface IEcsPoolEventListener
|
||||||
|
{
|
||||||
|
/// <summary>Called after adding an entity to the pool, but before changing values.</summary>
|
||||||
|
void OnAdd(int entityID);
|
||||||
|
/// <summary>Is called when EcsPool.Write or EcsPool.Add is called, but before changing values.</summary>
|
||||||
|
void OnWrite(int entityID);
|
||||||
|
/// <summary>Called after deleting an entity from the pool</summary>
|
||||||
|
void OnDel(int entityID);
|
||||||
|
}
|
||||||
public static class PoolEventListExtensions
|
public static class PoolEventListExtensions
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
namespace DCFApixels.DragonECS
|
|
||||||
{
|
|
||||||
public static class IntExtensions
|
|
||||||
{
|
|
||||||
public static entlong ToEntityLong(this int self, EcsWorld world)
|
|
||||||
{
|
|
||||||
return world.GetEntityLong(self);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +1,17 @@
|
|||||||
#pragma warning disable IDE1006
|
#pragma warning disable IDE1006
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using static DCFApixels.DragonECS.entlong.ThrowHalper;
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
using static entlong.ThrowHalper;
|
|
||||||
// [ id 32 | gen 16 | world 16 ]
|
// [ id 32 | gen 16 | world 16 ]
|
||||||
/// <summary>Strong identifier/Permanent entity identifier</summary>
|
/// <summary>Strong identifier/Permanent entity identifier</summary>
|
||||||
[StructLayout(LayoutKind.Explicit, Pack = 2, Size = 8)]
|
[StructLayout(LayoutKind.Explicit, Pack = 2, Size = 8)]
|
||||||
|
[DebuggerTypeProxy(typeof(DebuggerProxy))]
|
||||||
public readonly struct entlong : IEquatable<long>, IEquatable<entlong>
|
public readonly struct entlong : IEquatable<long>, IEquatable<entlong>
|
||||||
{
|
{
|
||||||
public static readonly entlong NULL = default;
|
public static readonly entlong NULL = default;
|
||||||
@ -33,8 +35,6 @@ namespace DCFApixels.DragonECS
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
get => this == NULL;
|
get => this == NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
||||||
public int ID
|
public int ID
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@ -46,7 +46,6 @@ namespace DCFApixels.DragonECS
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
||||||
public short Gen
|
public short Gen
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@ -69,7 +68,6 @@ namespace DCFApixels.DragonECS
|
|||||||
return EcsWorld.Worlds[world];
|
return EcsWorld.Worlds[world];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
||||||
public short WorldID
|
public short WorldID
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@ -158,5 +156,33 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region DebuggerProxy
|
||||||
|
internal class DebuggerProxy
|
||||||
|
{
|
||||||
|
private List<object> _componentsList;
|
||||||
|
private entlong _value;
|
||||||
|
public long full => _value.full;
|
||||||
|
public int id => _value.id;
|
||||||
|
public int gen => _value.gen;
|
||||||
|
public int world => _value.world;
|
||||||
|
public EntState State => _value.IsNull ? EntState.Null : _value.IsAlive ? EntState.Alive : EntState.Dead;
|
||||||
|
public EcsWorld EcsWorld => _value.World;
|
||||||
|
public IEnumerable<object> components
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
_value.World.GetComponents(_value.ID, _componentsList);
|
||||||
|
return _componentsList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public DebuggerProxy(entlong value)
|
||||||
|
{
|
||||||
|
_value = value;
|
||||||
|
_componentsList = new List<object>();
|
||||||
|
}
|
||||||
|
public enum EntState { Null, Dead, Alive, }
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user