diff --git a/src/EcsGroup.cs b/src/EcsGroup.cs index 3e6ef94..d1eb690 100644 --- a/src/EcsGroup.cs +++ b/src/EcsGroup.cs @@ -269,7 +269,7 @@ namespace DCFApixels.DragonECS if(_count > 0) Clear(); foreach (var item in group) - AggressiveAdd(item.id); + AggressiveAdd(item); } public EcsGroup Clone() { @@ -290,8 +290,8 @@ namespace DCFApixels.DragonECS if (_source != group.World) throw new ArgumentException("WorldIndex != groupFilter.WorldIndex"); #endif foreach (var item in group) - if (!Contains(item.id)) - AggressiveAdd(item.id); + if (!Contains(item)) + AggressiveAdd(item); } /// as Except sets @@ -304,8 +304,8 @@ namespace DCFApixels.DragonECS if (_source != group.World) throw new ArgumentException("WorldIndex != groupFilter.WorldIndex"); #endif foreach (var item in this) - if (group.Contains(item.id)) - AggressiveRemove(item.id); + if (group.Contains(item)) + AggressiveRemove(item); } /// as Intersect sets @@ -318,8 +318,8 @@ namespace DCFApixels.DragonECS if (World != group.World) throw new ArgumentException("WorldIndex != groupFilter.WorldIndex"); #endif foreach (var item in this) - if (!group.Contains(item.id)) - AggressiveRemove(item.id); + if (!group.Contains(item)) + AggressiveRemove(item); } /// as Symmetric Except sets @@ -332,10 +332,10 @@ namespace DCFApixels.DragonECS if (_source != group.World) throw new ArgumentException("WorldIndex != groupFilter.WorldIndex"); #endif foreach (var item in group) - if (Contains(item.id)) - AggressiveRemove(item.id); + if (Contains(item)) + AggressiveRemove(item); else - AggressiveAdd(item.id); + AggressiveAdd(item); } #endregion @@ -349,8 +349,8 @@ namespace DCFApixels.DragonECS #endif EcsGroup result = a._source.GetGroupFromPool(); foreach (var item in a) - if (!b.Contains(item.id)) - result.AggressiveAdd(item.id); + if (!b.Contains(item)) + result.AggressiveAdd(item); a._source.ReleaseGroup(a); return result; } @@ -363,8 +363,8 @@ namespace DCFApixels.DragonECS #endif EcsGroup result = a._source.GetGroupFromPool(); foreach (var item in a) - if (b.Contains(item.id)) - result.AggressiveAdd(item.id); + if (b.Contains(item)) + result.AggressiveAdd(item); a._source.ReleaseGroup(a); return result; } @@ -377,9 +377,9 @@ namespace DCFApixels.DragonECS #endif EcsGroup result = a._source.GetGroupFromPool(); foreach (var item in a) - result.AggressiveAdd(item.id); + result.AggressiveAdd(item); foreach (var item in a) - result.Add(item.id); + result.Add(item); return result; } #endregion @@ -432,10 +432,10 @@ namespace DCFApixels.DragonECS _count = group.Count; _index = 0; } - public ent Current + public int Current { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => new ent(_dense[_index]); + get => _dense[_index]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool MoveNext() => ++_index <= _count && _count<_dense.Length; // <= потму что отсчет начинается с индекса 1 //_count < _dense.Length дает среде понять что проверки на выход за границы не нужны @@ -456,7 +456,7 @@ namespace DCFApixels.DragonECS if (other.Count != Count) return false; foreach (var item in other) - if (!Contains(item.id)) + if (!Contains(item)) return false; return true; } @@ -464,7 +464,7 @@ namespace DCFApixels.DragonECS { int hash = 0; foreach (var item in this) - hash ^= 1 << (item.id % 32); //реализация от балды, так как не нужен, но фишка в том что хеш не учитывает порядок сущьностей, что явлется правильным поведением. + hash ^= 1 << (item % 32); //реализация от балды, так как не нужен, но фишка в том что хеш не учитывает порядок сущьностей, что явлется правильным поведением. return hash; } #endregion diff --git a/src/EcsJoinQuery.cs b/src/EcsJoinQuery.cs index b093d86..cae2d11 100644 --- a/src/EcsJoinQuery.cs +++ b/src/EcsJoinQuery.cs @@ -1,13 +1,4 @@ -using Mono.CompilerServices.SymbolWriter; -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Runtime.CompilerServices; -using Unity.Profiling; -using UnityEngine; -using UnityEngine.Jobs; +using Unity.Profiling; namespace DCFApixels.DragonECS { @@ -28,13 +19,10 @@ namespace DCFApixels.DragonECS private int[] _mapping; private int[] _counts; - //private int[] _entites; private EntityLinkedList _linkedBasket; private bool _isJoinExecuted = false; public bool IsJoinExecuted => _isJoinExecuted; - //private LinkedList - private bool _isInitTargetWorlds = false; @@ -61,9 +49,9 @@ namespace DCFApixels.DragonECS //Подготовка массивов if (_targetWorldCapacity < _targetWorld.Capacity) { + _targetWorldCapacity = _targetWorld.Capacity; _mapping = new int[_targetWorldCapacity]; _counts = new int[_targetWorldCapacity]; - _targetWorldCapacity = _targetWorld.Capacity; } else { @@ -72,16 +60,15 @@ namespace DCFApixels.DragonECS } if (_targetPoolCapacity < _targetPool.Capacity) { - _linkedBasket.Resize(_targetPoolCapacity); _targetPoolCapacity = _targetPool.Capacity; + _linkedBasket.Resize(_targetPoolCapacity); } _linkedBasket.Clear(); //Конец подготовки массивов ExecuteWhere(); - foreach (var e in groupFilter) + foreach (var attachID in groupFilter) { - int attachID = e.id; EcsEntity attachTarget = _targetPool.Read(attachID).Target; // if (!attachTarget.IsAlive)//TODO пофиксить IsAlive //{ @@ -177,39 +164,5 @@ namespace DCFApixels.DragonECS { return groupFilter.GetEnumerator(); } - - public NodesEnumrable GetNodes(int entityID) - { - throw new NotImplementedException(); - } - } - - public readonly ref struct NodesEnumrable - { - private readonly int[] _nodes; - private readonly int _start; - private readonly int _count; - public NodesEnumrable(int[] nodes, int start, int count) - { - _nodes = nodes; - _start = start; - _count = count; - } - public NodesEnumerator GetEnumerator() => new NodesEnumerator(_nodes, _start, _count); - } - public ref struct NodesEnumerator - { - private readonly int[] _nodes; - private readonly int _end; - private int _index; - public NodesEnumerator(int[] nodes, int start, int count) - { - _nodes = nodes; - int end = start + count; - _end = end < _nodes.Length ? end : _nodes.Length; - _index = start; - } - public ent Current => new ent(_nodes[_index]); - public bool MoveNext() => ++_index <= _end; } } diff --git a/src/EcsQuery.cs b/src/EcsQuery.cs index 994a102..e554a71 100644 --- a/src/EcsQuery.cs +++ b/src/EcsQuery.cs @@ -85,18 +85,17 @@ namespace DCFApixels.DragonECS result.Clear(); foreach (var e in group) { - int entityID = e.id; for (int i = 0, iMax = mask.Inc.Length; i < iMax; i++) { - if (!pools[mask.Inc[i]].Has(entityID)) + if (!pools[mask.Inc[i]].Has(e)) goto next; } for (int i = 0, iMax = mask.Exc.Length; i < iMax; i++) { - if (pools[mask.Exc[i]].Has(entityID)) + if (pools[mask.Exc[i]].Has(e)) goto next; } - result.AggressiveAdd(entityID); + result.AggressiveAdd(e); next: continue; } result.Sort(); diff --git a/src/Entities/EcsEntity.cs b/src/Entities/EcsEntity.cs index 611eec5..ed41eef 100644 --- a/src/Entities/EcsEntity.cs +++ b/src/Entities/EcsEntity.cs @@ -21,9 +21,8 @@ namespace DCFApixels.DragonECS [FieldOffset(0)] public readonly short world; - [MethodImpl(MethodImplOptions.AggressiveInlining)] + //[MethodImpl(MethodImplOptions.AggressiveInlining)] //public ent ToEnt() => EcsWorld.Worlds[world].EntityIsAlive(id, gen) ? new ent(id) : default; - public ent ToEnt() => new ent(id); public bool IsAlive => EcsWorld.Worlds[world].EntityIsAlive(id, gen); @@ -65,8 +64,8 @@ namespace DCFApixels.DragonECS public static bool operator !=(in EcsEntity a, in EcsEntity b) => a.full != b.full; [MethodImpl(MethodImplOptions.AggressiveInlining)] public static explicit operator long(in EcsEntity a) => a.full; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static explicit operator ent(in EcsEntity a) => a.ToEnt(); + //[MethodImpl(MethodImplOptions.AggressiveInlining)] + //public static explicit operator ent(in EcsEntity a) => a.ToEnt(); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static explicit operator EcsEntity(in long a) => new EcsEntity(a); #endregion diff --git a/src/Entities/ent.cs b/src/Entities/ent.cs deleted file mode 100644 index be9133e..0000000 --- a/src/Entities/ent.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using UnityEngine.Rendering; - -namespace DCFApixels.DragonECS -{ -#pragma warning disable CS0660, CS0661, IDE1006 - /// Weak identifier/Single frame entity identifier - [StructLayout(LayoutKind.Sequential, Pack = 4, Size = 4)] - public readonly ref struct ent - { - [MarshalAs(UnmanagedType.I4)] - internal readonly int id; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal ent(int id) => this.id = id; - - public static implicit operator int(ent entityID) => entityID.id; - - public static bool operator ==(ent a, ent b) => a.id == b.id; - public static bool operator !=(ent a, ent b) => a.id != b.id; - - public static bool operator ==(ent a, Null? _) => a.id == 0; - public static bool operator ==(Null? _, ent b) => b.id == 0; - public static bool operator !=(ent a, Null? _) => a.id != 0; - public static bool operator !=(Null? _, ent b) => b.id != 0; - - public struct Null { } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public EcsEntity ToStrongID(EcsWorld world) => world.GetEcsEntity(id); - } -}