From 555909fcc06a4c125587ad543f52c288e9018a23 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Sun, 23 Apr 2023 11:51:50 +0800 Subject: [PATCH] refactoring --- src/EcsJoinQuery.cs | 10 ++-------- src/Utils/EntityLinkedList.cs | 29 ++++++----------------------- 2 files changed, 8 insertions(+), 31 deletions(-) diff --git a/src/EcsJoinQuery.cs b/src/EcsJoinQuery.cs index 353b98e..11765c3 100644 --- a/src/EcsJoinQuery.cs +++ b/src/EcsJoinQuery.cs @@ -68,19 +68,13 @@ namespace DCFApixels.DragonECS else { ArrayUtility.Fill(_counts, 0); + ArrayUtility.Fill(_mapping, 0); } - ArrayUtility.Fill(_mapping, -1); - if (_targetPoolCapacity < _targetPool.Capacity) { - _entites = new int[_targetPoolCapacity]; _linkedBasket.Resize(_targetPoolCapacity); _targetPoolCapacity = _targetPool.Capacity; } - else - { - ArrayUtility.Fill(_entites, 0); - } _linkedBasket.Clear(); //Конец подготовки массивов @@ -97,7 +91,7 @@ namespace DCFApixels.DragonECS int attachTargetID = attachTarget.id; ref int nodeIndex = ref _mapping[attachTargetID]; - if(nodeIndex< 0) + if(nodeIndex <= 0) nodeIndex = _linkedBasket.Add(attachID); else _linkedBasket.Insert(nodeIndex, attachID); diff --git a/src/Utils/EntityLinkedList.cs b/src/Utils/EntityLinkedList.cs index 1e4705a..af41450 100644 --- a/src/Utils/EntityLinkedList.cs +++ b/src/Utils/EntityLinkedList.cs @@ -1,18 +1,11 @@ using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; -using UnityEditor; namespace DCFApixels.DragonECS { public class EntityLinkedList { - public const int First = 0; + public const int Enter = 0; private Node[] _nodes; private int _count; @@ -41,8 +34,8 @@ namespace DCFApixels.DragonECS { //ArrayUtility.Fill(_nodes, Node.Empty); for (int i = 0; i < _nodes.Length; i++) - _nodes[i].next = -1; - _lastNodeIndex = First; + _nodes[i].next = 0; + _lastNodeIndex = Enter; _count = 0; } @@ -87,21 +80,18 @@ namespace DCFApixels.DragonECS private readonly Node[] _nodes; private int _index; private int _next; - public Enumerator(Node[] nodes) { _nodes = nodes; _index = -1; - _next = First; + _next = Enter; } - public int Current => _nodes[_index].entityID; - public bool MoveNext() { _index = _next; _next = _nodes[_next].next; - return _index >= 0; + return _index > 0; } } @@ -110,14 +100,12 @@ namespace DCFApixels.DragonECS private readonly EntityLinkedList _source; private readonly int _startNodeIndex; private readonly int _count; - public EnumerableSpan(EntityLinkedList source, int startNodeIndex, int count) { _source = source; _startNodeIndex = startNodeIndex; _count = count; } - public SpanEnumerator GetEnumerator() => new SpanEnumerator(_source._nodes, _startNodeIndex, _count); } public struct SpanEnumerator @@ -126,7 +114,6 @@ namespace DCFApixels.DragonECS private int _index; private int _count; private int _next; - public SpanEnumerator(Node[] nodes, int startIndex, int count) { _nodes = nodes; @@ -134,16 +121,12 @@ namespace DCFApixels.DragonECS _count = count; _next = startIndex; } - public int Current => _nodes[_index].entityID; - public bool MoveNext() { - if (_count <= 0) - return false; _index = _next; _next = _nodes[_next].next; - return _index >= 0 && _count-- > 0; + return _index > 0 && _count-- > 0; } } #endregion