diff --git a/src/EcsFilter.cs b/src/EcsFilter.cs index 90deec7..ffe9f4d 100644 --- a/src/EcsFilter.cs +++ b/src/EcsFilter.cs @@ -19,6 +19,7 @@ namespace DCFApixels.DragonECS private readonly SparseSet _entities; private DelayedOp[] _delayedOps; + private int _delayedOpsCount; private int _lockCount; @@ -49,7 +50,7 @@ namespace DCFApixels.DragonECS internal void Add(int entityID) { if (_lockCount > 0) - AddDelayedOp(entityID, false); + AddDelayedOp(entityID, true); _entities.Add(entityID); } @@ -62,15 +63,32 @@ namespace DCFApixels.DragonECS private void AddDelayedOp(int entityID, bool isAdd) { + if(_delayedOpsCount >= _delayedOps.Length) + { + Array.Resize(ref _delayedOps, _delayedOps.Length << 1); + } + + _delayedOps[_delayedOpsCount].Entity = entityID; + _delayedOps[_delayedOpsCount].Added = isAdd; } #region GetEnumerator private void Unlock() { #if DEBUG - if (_lockCount <= 0) { throw new Exception($"Invalid lock-unlock balance for {nameof(EcsFilter)}."); } + if (_lockCount <= 0) + { + throw new Exception($"Invalid lock-unlock balance for {nameof(EcsFilter)}."); + } #endif _lockCount--; + if (_lockCount <= 0) + { + for (int i = 0; i < _delayedOpsCount; i++) + { + + } + } } public Enumerator GetEnumerator() { @@ -112,7 +130,7 @@ namespace DCFApixels.DragonECS } } - struct DelayedOp + private struct DelayedOp { public bool Added; public int Entity; diff --git a/src/Pools/EcsPool.cs b/src/EcsPool.cs similarity index 77% rename from src/Pools/EcsPool.cs rename to src/EcsPool.cs index 598910b..fc71b96 100644 --- a/src/Pools/EcsPool.cs +++ b/src/EcsPool.cs @@ -1,22 +1,33 @@ using System.Collections; using System.Collections.Generic; +using DCFApixels.DragonECS.Reflection; using System.Runtime.CompilerServices; using UnityEngine; namespace DCFApixels.DragonECS { + public interface IEcsPool + { + public EcsWorld World { get; } + public int ID { get; } + public EcsMemberBase Type { get; } + public bool Has(int index); + public void Add(int index); + public void Del(int index); + } + public class EcsPool : IEcsPool { private int _id; private readonly EcsWorld _source; - private readonly EcsType _type; + private readonly EcsMember _type; private readonly SparseSet _sparseSet; private T[] _denseItems; #region Properites public EcsWorld World => _source; public int ID => _id; - public EcsType Type => _type; + public EcsMemberBase Type => _type; public ref T this[int index] { [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -26,7 +37,7 @@ namespace DCFApixels.DragonECS #endregion #region Constructors - public EcsPool(EcsWorld source, EcsType type, int capacity) + public EcsPool(EcsWorld source, EcsMember type, int capacity) { _source = source; _type = type; diff --git a/src/Pools/EcsPool.cs.meta b/src/EcsPool.cs.meta similarity index 100% rename from src/Pools/EcsPool.cs.meta rename to src/EcsPool.cs.meta diff --git a/src/EcsTable.cs b/src/EcsTable.cs index f1fd971..603a011 100644 --- a/src/EcsTable.cs +++ b/src/EcsTable.cs @@ -7,10 +7,14 @@ namespace DCFApixels.DragonECS public abstract class EcsTable { internal EcsFilter _filter; + + public EcsTable(ref TableBuilder tableBuilder) { } + public EcsFilter Filter { get => _filter; } + } } diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index c0dc38c..80407da 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; @@ -43,7 +44,7 @@ namespace DCFApixels.DragonECS #endregion #region GetPool - public EcsPool GetPool() + public EcsPool GetPool(mem member) { Type type = typeof(T); if (_pools.TryGetValue(type, out IEcsPool pool)) @@ -76,13 +77,13 @@ namespace DCFApixels.DragonECS } #endregion - internal void OnEntityFieldAdd(int entityID, EcsType chaangedField) + internal void OnEntityFieldAdd(int entityID, mem chaangedField) { } - internal void OnEntityFieldDel(int entityID, EcsType chaangedField) + internal void OnEntityFieldDel(int entityID, EcsMember chaangedField) { } @@ -90,7 +91,65 @@ namespace DCFApixels.DragonECS public class Mask { + private readonly EcsWorld _world; + internal int[] Include; + internal int[] Exclude; + internal int IncludeCount; + internal int ExcludeCount; + internal int Hash; +#if DEBUG && !LEOECSLITE_NO_SANITIZE_CHECKS + bool _built; +#endif + internal Mask(EcsWorld world) + { + _world = world; + Include = new int[8]; + Exclude = new int[2]; + Reset(); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + void Reset() + { + IncludeCount = 0; + ExcludeCount = 0; + Hash = 0; +#if DEBUG && !LEOECSLITE_NO_SANITIZE_CHECKS + _built = false; +#endif + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Mask Inc(EcsMember member) where T : struct + { + var poolId = _world.GetPool().GetId(); +#if DEBUG && !LEOECSLITE_NO_SANITIZE_CHECKS + if (_built) { throw new Exception("Cant change built mask."); } + if (Array.IndexOf(Include, poolId, 0, IncludeCount) != -1) { throw new Exception($"{typeof(T).Name} already in constraints list."); } + if (Array.IndexOf(Exclude, poolId, 0, ExcludeCount) != -1) { throw new Exception($"{typeof(T).Name} already in constraints list."); } +#endif + if (IncludeCount == Include.Length) { Array.Resize(ref Include, IncludeCount << 1); } + Include[IncludeCount++] = poolId; + return this; + } + +#if UNITY_2020_3_OR_NEWER + [UnityEngine.Scripting.Preserve] +#endif + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Mask Exc(EcsMember member) where T : struct + { + var poolId = _world.GetPool().GetId(); +#if DEBUG && !LEOECSLITE_NO_SANITIZE_CHECKS + if (_built) { throw new Exception("Cant change built mask."); } + if (Array.IndexOf(Include, poolId, 0, IncludeCount) != -1) { throw new Exception($"{typeof(T).Name} already in constraints list."); } + if (Array.IndexOf(Exclude, poolId, 0, ExcludeCount) != -1) { throw new Exception($"{typeof(T).Name} already in constraints list."); } +#endif + if (ExcludeCount == Exclude.Length) { Array.Resize(ref Exclude, ExcludeCount << 1); } + Exclude[ExcludeCount++] = poolId; + return this; + } } } } diff --git a/src/Interfaces/IEcsProcessor.cs b/src/Interfaces/IEcsProcessor.cs index 67dcc32..e51f653 100644 --- a/src/Interfaces/IEcsProcessor.cs +++ b/src/Interfaces/IEcsProcessor.cs @@ -22,6 +22,16 @@ public interface IEcsMessage { } + public readonly struct _OnNewEntityCreated : IEcsMessage + { + public readonly ent entity; + + public _OnNewEntityCreated(ent entity) + { + this.entity = entity; + } + + } public interface IEcsDoMessege : IEcsProcessor where TMessage : IEcsMessage { diff --git a/src/Pools/EcsTagsPool.cs b/src/Pools/EcsTagsPool.cs deleted file mode 100644 index 66dcf8e..0000000 --- a/src/Pools/EcsTagsPool.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; - -namespace DCFApixels.DragonECS -{ - public class EcsTagsPool : IEcsPool - { - private int _id; - private readonly EcsWorld _source; - private readonly EcsType _type; - private readonly SparseSet _sparseSet; - - #region Properites - public EcsWorld World => _source; - public int ID => _id; - public EcsType Type => _type; - #endregion - - #region Constructors - public EcsTagsPool(EcsWorld source, EcsType type, int capacity) - { - _source = source; - _type = type; - _sparseSet = new SparseSet(capacity); - } - #endregion - - #region Add/Has/Del - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Add(int index) - { - _sparseSet.Add(index); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Del(int index) - { - _sparseSet.Add(index); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Has(int index) - { - return _sparseSet.Contains(index); - } - #endregion - } -} diff --git a/src/Pools/IEcsPool.cs b/src/Pools/IEcsPool.cs deleted file mode 100644 index da8f614..0000000 --- a/src/Pools/IEcsPool.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace DCFApixels.DragonECS -{ - public interface IEcsPool - { - public EcsWorld World { get; } - public int ID { get; } - public EcsType Type { get; } - public bool Has(int index); - public void Add(int index); - public void Del(int index); - } -} diff --git a/src/Pools.meta b/src/Primitives.meta similarity index 77% rename from src/Pools.meta rename to src/Primitives.meta index 55cbf0c..ab11560 100644 --- a/src/Pools.meta +++ b/src/Primitives.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 712e0669e3984c0479174a12942e4db6 +guid: 7c2d964089dec3d439486d9a2c94dda2 folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/src/ent.cs b/src/Primitives/ent.cs similarity index 100% rename from src/ent.cs rename to src/Primitives/ent.cs diff --git a/src/ent.cs.meta b/src/Primitives/ent.cs.meta similarity index 100% rename from src/ent.cs.meta rename to src/Primitives/ent.cs.meta diff --git a/src/Primitives/mem.cs b/src/Primitives/mem.cs new file mode 100644 index 0000000..3d4c8d0 --- /dev/null +++ b/src/Primitives/mem.cs @@ -0,0 +1,62 @@ +using System; +using System.Runtime.CompilerServices; +using DCFApixels.DragonECS.Reflection; + +namespace DCFApixels.DragonECS +{ + public readonly struct mem : IEquatable>, IEquatable + { + public static readonly mem NULL = new mem(-1); + + internal readonly int offsetedUniqueID; + + #region Properties + public int UniqueID + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => offsetedUniqueID - 1; + } + public bool HasValue + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => offsetedUniqueID != 0; + } + #endregion + + #region Constructors + private mem(int uniqueID) + { + offsetedUniqueID = uniqueID + 1; + } + #endregion + + #region Equals + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public override bool Equals(object obj) => obj is mem key && offsetedUniqueID == key.offsetedUniqueID; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Equals(mem other) => offsetedUniqueID == other.offsetedUniqueID; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Equals(int other) => offsetedUniqueID == (other + 1); + #endregion + + #region GetHashCode/ToString + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public override int GetHashCode() => offsetedUniqueID - 1; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public override string ToString() => HasValue ? MemberDeclarator.GetMemberInfo(this).ToString() : "NULL"; + + #endregion + + #region operators + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool operator ==(in mem left, in mem right) => left.Equals(right); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool operator !=(in mem left, in mem right) => !left.Equals(right); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator mem(string name) => new mem(MemberDeclarator.Declare(name).UniqueID); + #endregion + } +} diff --git a/src/Pools/IEcsPool.cs.meta b/src/Primitives/mem.cs.meta similarity index 83% rename from src/Pools/IEcsPool.cs.meta rename to src/Primitives/mem.cs.meta index 5be3cde..c4fca90 100644 --- a/src/Pools/IEcsPool.cs.meta +++ b/src/Primitives/mem.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 82d72237ee8aeb64c9e5455be807896a +guid: a21421fecdd5670448a3a10c804238f7 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/src/Primitives/tag.cs b/src/Primitives/tag.cs new file mode 100644 index 0000000..52e70e5 --- /dev/null +++ b/src/Primitives/tag.cs @@ -0,0 +1,4 @@ +namespace DCFApixels.DragonECS +{ + public struct tag { } +} diff --git a/src/TableMembers/TagType.cs.meta b/src/Primitives/tag.cs.meta similarity index 100% rename from src/TableMembers/TagType.cs.meta rename to src/Primitives/tag.cs.meta diff --git a/src/React/WorldFilterAttribute.cs b/src/React/WorldFilterAttribute.cs new file mode 100644 index 0000000..208423e --- /dev/null +++ b/src/React/WorldFilterAttribute.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DCFApixels.Assets.DragonECS.src.React +{ + [AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)] + sealed class WorldFilterAttribute : Attribute + { + public readonly string[] worlds; + + public WorldFilterAttribute(params string[] worlds) + { + this.worlds = worlds; + } + } +} diff --git a/src/Pools/EcsTagsPool.cs.meta b/src/React/WorldFilterAttribute.cs.meta similarity index 83% rename from src/Pools/EcsTagsPool.cs.meta rename to src/React/WorldFilterAttribute.cs.meta index 7b84cc0..863b196 100644 --- a/src/Pools/EcsTagsPool.cs.meta +++ b/src/React/WorldFilterAttribute.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 01fdcaed7dcb78b4eb4560c068cb0b27 +guid: 473f26450295507498d518fb452be90f MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/src/TableBuilder.cs b/src/TableBuilder.cs new file mode 100644 index 0000000..3cb3682 --- /dev/null +++ b/src/TableBuilder.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DCFApixels.DragonECS +{ + public readonly ref struct TableBuilder + { + private readonly EcsWorld _world; + + public EcsPool Cache(mem member) + { + + } + public EcsPool Inc(mem member) + { + + } + public EcsPool Exc(mem member) + { + + } + } +} diff --git a/src/TableBuilder.cs.meta b/src/TableBuilder.cs.meta new file mode 100644 index 0000000..52eba19 --- /dev/null +++ b/src/TableBuilder.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3ae306a1fd41f78428c59018eeaf21f3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/TableMembers/EcsTag.cs b/src/TableMembers/EcsTag.cs index 7fee0bd..0f8df7c 100644 --- a/src/TableMembers/EcsTag.cs +++ b/src/TableMembers/EcsTag.cs @@ -5,12 +5,12 @@ using System.Runtime.CompilerServices; namespace DCFApixels.DragonECS { - public readonly struct EcsTag : IEcsMemberCachePool + public readonly struct EcsTag : IEcsMemberCachePool { - private readonly EcsPool _pool; + private readonly EcsPool _pool; private readonly int _poolID; - public EcsPool Pool => _pool; + public EcsPool Pool => _pool; public int PoolID => _poolID; private EcsTag(int poolID) @@ -18,7 +18,7 @@ namespace DCFApixels.DragonECS _pool = null; _poolID = poolID; } - internal EcsTag(EcsPool pool) + internal EcsTag(EcsPool pool) { _pool = pool; _poolID = pool.ID; @@ -32,17 +32,17 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator EcsTag(in int poolID) => new EcsTag(poolID); - void IEcsMemberCachePool.Inject(out EcsTag self, EcsPool pool) + void IEcsMemberCachePool.Inject(out EcsTag self, EcsPool pool) { self = new EcsTag(pool); } } - public readonly struct EcsIncTag : IEcsMemberCachePool + public readonly struct EcsIncTag : IEcsMemberCachePool { - private readonly EcsPool _pool; + private readonly EcsPool _pool; private readonly int _poolID; - public EcsPool Pool => _pool; + public EcsPool Pool => _pool; public int PoolID => _poolID; private EcsIncTag(int poolID) @@ -50,7 +50,7 @@ namespace DCFApixels.DragonECS _pool = null; _poolID = poolID; } - internal EcsIncTag(EcsPool pool) + internal EcsIncTag(EcsPool pool) { _pool = pool; _poolID = pool.ID; @@ -59,17 +59,17 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator EcsIncTag(in int poolID) => new EcsIncTag(poolID); - void IEcsMemberCachePool.Inject(out EcsIncTag self, EcsPool pool) + void IEcsMemberCachePool.Inject(out EcsIncTag self, EcsPool pool) { self = new EcsIncTag(pool); } } - public readonly struct EcsExcTag : IEcsMemberCachePool + public readonly struct EcsExcTag : IEcsMemberCachePool { - private readonly EcsPool _pool; + private readonly EcsPool _pool; private readonly int _poolID; - public EcsPool Pool => _pool; + public EcsPool Pool => _pool; public int PoolID => _poolID; private EcsExcTag(int poolID) @@ -77,7 +77,7 @@ namespace DCFApixels.DragonECS _pool = null; _poolID = poolID; } - internal EcsExcTag(EcsPool pool) + internal EcsExcTag(EcsPool pool) { _pool = pool; _poolID = pool.ID; @@ -86,7 +86,7 @@ namespace DCFApixels.DragonECS [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator EcsExcTag(in int poolID) => new EcsExcTag(poolID); - void IEcsMemberCachePool.Inject(out EcsExcTag self, EcsPool pool) + void IEcsMemberCachePool.Inject(out EcsExcTag self, EcsPool pool) { self = new EcsExcTag(pool); } diff --git a/src/TableMembers/TagType.cs b/src/TableMembers/TagType.cs deleted file mode 100644 index 0b70912..0000000 --- a/src/TableMembers/TagType.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace DCFApixels.DragonECS -{ - public struct TagType { } -} diff --git a/src/Utils/EcsMember.cs b/src/Utils/EcsMember.cs new file mode 100644 index 0000000..ee518f3 --- /dev/null +++ b/src/Utils/EcsMember.cs @@ -0,0 +1,143 @@ +using System.Collections.Generic; +using System; +using System.Runtime.CompilerServices; +using DCFApixels.DragonECS.Reflection; + +namespace DCFApixels.DragonECS +{ + namespace Reflection + { + public static class MemberDeclarator + { +#if !DCFA_ECS_NO_SANITIZE_CHECKS + private static HashSet _usedNames = new HashSet(1024); +#endif + private static EcsMemberBase[] _member = new EcsMemberBase[1024]; + private static int _typesCount = 0; + public static EcsMember Declare(string name) + { + name = $"{typeof(T).FullName}__{name}"; +#if DEBUG && !DCFA_ECS_NO_SANITIZE_CHECKS + if (_typesCount < 0) + { + throw new EcsFrameworkException($"Maximum available members exceeded. The member of \"{name}\" was not declared"); + } + if (_usedNames.Contains(name)) + { + throw new EcsFrameworkException($"The node with the name \"{name}\" has already been declared"); + } + _usedNames.Add(name); +#endif + if (_typesCount >= _member.Length) + { + Array.Resize(ref _member, _member.Length << 1); + } + + EcsMember member = new EcsMember(name, _typesCount); + _member[_typesCount++] = member; + + return member; + } + + public static EcsMember GetMemberInfo(mem member) + { +#if DEBUG && !DCFA_ECS_NO_SANITIZE_CHECKS + if (member.HasValue == false) + { + throw new ArgumentException($"The member argument is empty"); + } +#endif + + return (EcsMember)_member[member.UniqueID]; + } + } + + public abstract class EcsMemberBase : IEquatable + { + protected const string TO_STRING_HEADER = "EcsMember:"; + + protected string _name; + protected int _uniqueID; + protected Type _type; + + #region Propertiees + public int UniqueID + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _uniqueID; + } + #endregion + + #region GetHashCode/ToString + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public override int GetHashCode() => _uniqueID; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public override string ToString() => TO_STRING_HEADER + _name; + + #endregion + + #region Equals + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public override bool Equals(object obj) + { + return obj is EcsMemberBase key && _name == key._name; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Equals(EcsMemberBase other) + { + return _uniqueID == other._uniqueID; + } + #endregion + + #region operators + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool operator ==(in EcsMemberBase left, in EcsMemberBase right) => left.Equals(right); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool operator !=(in EcsMemberBase left, in EcsMemberBase right) => !left.Equals(right); + #endregion + } + public class EcsMember : EcsMemberBase, IEquatable> + { + #region Constructors + private EcsMember() { } + internal EcsMember(string name, int uniqueID) + { + _name = name; + _uniqueID = uniqueID; + _type = typeof(T); + } + #endregion + + #region Equals + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public override bool Equals(object obj) => obj is EcsMember key && _uniqueID == key._uniqueID; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool Equals(EcsMember other) => _uniqueID == other._uniqueID; + #endregion + + #region GetHashCode/ToString + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public override int GetHashCode() => _uniqueID; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public override string ToString() => TO_STRING_HEADER + _name; + + #endregion + + #region operators + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool operator ==(in EcsMember left, in EcsMember right) => left.Equals(right); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool operator !=(in EcsMember left, in EcsMember right) => !left.Equals(right); + + + //[MethodImpl(MethodImplOptions.AggressiveInlining)] + //public static implicit operator EcsMember(string name) => MemberDeclarator.Declare(name); + #endregion + } + } + +} \ No newline at end of file diff --git a/src/Utils/EcsType.cs.meta b/src/Utils/EcsMember.cs.meta similarity index 100% rename from src/Utils/EcsType.cs.meta rename to src/Utils/EcsMember.cs.meta diff --git a/src/Utils/EcsType.cs b/src/Utils/EcsType.cs deleted file mode 100644 index 7600d68..0000000 --- a/src/Utils/EcsType.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System.Collections.Generic; -using System; -using System.Runtime.CompilerServices; - -namespace DCFApixels.DragonECS -{ - - public class EcsType : IEquatable - { - private static int _idIncrement = 0; - - //свободно еще 4 байта, возможно можно выделить под айдишники - private string _name; - private int _uniqueID; - - #region Constructors - internal EcsType(string name) - { - _name = name; - _uniqueID = _idIncrement++; - -#if DEBUG - if (_idIncrement == 0) - { - throw new EcsFrameworkException($"The maximum number of identifiers is allocated. Max:{uint.MaxValue}"); - } -#endif - } - #endregion - - #region Equals - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public override bool Equals(object obj) - { - return obj is EcsType key && _name == key._name; - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(EcsType other) - { - return _uniqueID == other._uniqueID; - } - #endregion - - #region GetHashCode/ToString - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public override int GetHashCode() => _uniqueID; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public override string ToString() => "EcsType." + _name; - - #endregion - - #region operators - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool operator ==(in EcsType left, in EcsType right) => left.Equals(right); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool operator !=(in EcsType left, in EcsType right) => !left.Equals(right); - #endregion - } - - - public static class EcsTypeMap - { - private static Dictionary _types = new Dictionary(256); - - public static EcsType GetEcsType(string name) - { - if (_types.TryGetValue(name, out EcsType type)) - return type; - - type = new EcsType(name); - _types.Add(name, type); - return type; - } - } -} \ No newline at end of file diff --git a/src/Utils/entityArraysPool.cs b/src/Utils/entityArraysPool.cs index 437c6e2..61bae7d 100644 --- a/src/Utils/entityArraysPool.cs +++ b/src/Utils/entityArraysPool.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace DCFApixels.DragonECS { - public class entityArraysPool + public class EntityArraysPool { //public int[] } diff --git a/test/Mems.cs b/test/Mems.cs new file mode 100644 index 0000000..ebf6df3 --- /dev/null +++ b/test/Mems.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace DCFApixels.DragonECS +{ + public static class Mems + { + public static readonly mem health = "health"; + public static readonly mem regeneration = "regeneration"; + public static readonly mem position = "position"; + public static readonly mem rotation = "rotation"; + public static readonly mem scale = "scale"; + } +} diff --git a/test/Mems.cs.meta b/test/Mems.cs.meta new file mode 100644 index 0000000..d1ec085 --- /dev/null +++ b/test/Mems.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9478c808aeb8de24a883819991780c9b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/test/Startup.cs b/test/Startup.cs new file mode 100644 index 0000000..18fc3a3 --- /dev/null +++ b/test/Startup.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using DCFApixels; +using UnityEngine; + +namespace DCFApixels.DragonECS +{ + public class Startup : MonoBehaviour + { + + private EcsSession _ecsSession; + + private void Start() + { + _ecsSession + .AddWorld("") + .Add(new TestSystem()) + .Init(); + } + + private void Update() + { + _ecsSession.Run(); + } + + private void OnDestroy() + { + _ecsSession.Destroy(); + } + } +} diff --git a/test/Startup.cs.meta b/test/Startup.cs.meta new file mode 100644 index 0000000..a4f9497 --- /dev/null +++ b/test/Startup.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8520d71f413c71442bd847f51820760e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/test/TransformTable.cs b/test/TransformTable.cs index 358a7b7..3ada8c7 100644 --- a/test/TransformTable.cs +++ b/test/TransformTable.cs @@ -1,12 +1,63 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using DCFApixels; +using UnityEngine; namespace DCFApixels.DragonECS { - public struct TransformTable + public class TransformTable : EcsTable { + public readonly EcsPool position; + public readonly EcsPool rotation; + public readonly EcsPool scale; + + public TransformTable(ref TableBuilder tableBuilder) : base(ref tableBuilder) + { + position = tableBuilder.Inc(Mems.position); + rotation = tableBuilder.Inc(Mems.rotation); + scale = tableBuilder.Inc(Mems.scale); + } + } + + public class PositionTable : EcsTable + { + public readonly EcsPool position; + public readonly EcsPool rotation; + public readonly EcsPool scale; + + public PositionTable(ref TableBuilder tableBuilder) : base(ref tableBuilder) + { + position = tableBuilder.Inc(Mems.position); + rotation = tableBuilder.Cache(Mems.rotation); + scale = tableBuilder.Cache(Mems.scale); + } + } + + public class RotationTable : EcsTable + { + public readonly EcsPool position; + public readonly EcsPool rotation; + public readonly EcsPool scale; + + public RotationTable(ref TableBuilder tableBuilder) : base(ref tableBuilder) + { + position = tableBuilder.Cache(Mems.position); + rotation = tableBuilder.Inc(Mems.rotation); + scale = tableBuilder.Cache(Mems.scale); + } + } + + public class ScaleTable : EcsTable + { + public readonly EcsPool position; + public readonly EcsPool rotation; + public readonly EcsPool scale; + + public ScaleTable(ref TableBuilder tableBuilder) : base(ref tableBuilder) + { + position = tableBuilder.Cache(Mems.position); + rotation = tableBuilder.Cache(Mems.rotation); + scale = tableBuilder.Inc(Mems.scale); + } } }