mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-11-14 01:35:54 +08:00
refactoring
This commit is contained in:
parent
b5d9d0e5e1
commit
555909fcc0
@ -68,19 +68,13 @@ namespace DCFApixels.DragonECS
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
ArrayUtility.Fill(_counts, 0);
|
ArrayUtility.Fill(_counts, 0);
|
||||||
|
ArrayUtility.Fill(_mapping, 0);
|
||||||
}
|
}
|
||||||
ArrayUtility.Fill(_mapping, -1);
|
|
||||||
|
|
||||||
if (_targetPoolCapacity < _targetPool.Capacity)
|
if (_targetPoolCapacity < _targetPool.Capacity)
|
||||||
{
|
{
|
||||||
_entites = new int[_targetPoolCapacity];
|
|
||||||
_linkedBasket.Resize(_targetPoolCapacity);
|
_linkedBasket.Resize(_targetPoolCapacity);
|
||||||
_targetPoolCapacity = _targetPool.Capacity;
|
_targetPoolCapacity = _targetPool.Capacity;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
ArrayUtility.Fill(_entites, 0);
|
|
||||||
}
|
|
||||||
_linkedBasket.Clear();
|
_linkedBasket.Clear();
|
||||||
//Конец подготовки массивов
|
//Конец подготовки массивов
|
||||||
|
|
||||||
@ -97,7 +91,7 @@ namespace DCFApixels.DragonECS
|
|||||||
int attachTargetID = attachTarget.id;
|
int attachTargetID = attachTarget.id;
|
||||||
|
|
||||||
ref int nodeIndex = ref _mapping[attachTargetID];
|
ref int nodeIndex = ref _mapping[attachTargetID];
|
||||||
if(nodeIndex< 0)
|
if(nodeIndex <= 0)
|
||||||
nodeIndex = _linkedBasket.Add(attachID);
|
nodeIndex = _linkedBasket.Add(attachID);
|
||||||
else
|
else
|
||||||
_linkedBasket.Insert(nodeIndex, attachID);
|
_linkedBasket.Insert(nodeIndex, attachID);
|
||||||
|
|||||||
@ -1,18 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using UnityEditor;
|
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
public class EntityLinkedList
|
public class EntityLinkedList
|
||||||
{
|
{
|
||||||
public const int First = 0;
|
public const int Enter = 0;
|
||||||
|
|
||||||
private Node[] _nodes;
|
private Node[] _nodes;
|
||||||
private int _count;
|
private int _count;
|
||||||
@ -41,8 +34,8 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
//ArrayUtility.Fill(_nodes, Node.Empty);
|
//ArrayUtility.Fill(_nodes, Node.Empty);
|
||||||
for (int i = 0; i < _nodes.Length; i++)
|
for (int i = 0; i < _nodes.Length; i++)
|
||||||
_nodes[i].next = -1;
|
_nodes[i].next = 0;
|
||||||
_lastNodeIndex = First;
|
_lastNodeIndex = Enter;
|
||||||
_count = 0;
|
_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,21 +80,18 @@ namespace DCFApixels.DragonECS
|
|||||||
private readonly Node[] _nodes;
|
private readonly Node[] _nodes;
|
||||||
private int _index;
|
private int _index;
|
||||||
private int _next;
|
private int _next;
|
||||||
|
|
||||||
public Enumerator(Node[] nodes)
|
public Enumerator(Node[] nodes)
|
||||||
{
|
{
|
||||||
_nodes = nodes;
|
_nodes = nodes;
|
||||||
_index = -1;
|
_index = -1;
|
||||||
_next = First;
|
_next = Enter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Current => _nodes[_index].entityID;
|
public int Current => _nodes[_index].entityID;
|
||||||
|
|
||||||
public bool MoveNext()
|
public bool MoveNext()
|
||||||
{
|
{
|
||||||
_index = _next;
|
_index = _next;
|
||||||
_next = _nodes[_next].next;
|
_next = _nodes[_next].next;
|
||||||
return _index >= 0;
|
return _index > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,14 +100,12 @@ namespace DCFApixels.DragonECS
|
|||||||
private readonly EntityLinkedList _source;
|
private readonly EntityLinkedList _source;
|
||||||
private readonly int _startNodeIndex;
|
private readonly int _startNodeIndex;
|
||||||
private readonly int _count;
|
private readonly int _count;
|
||||||
|
|
||||||
public EnumerableSpan(EntityLinkedList source, int startNodeIndex, int count)
|
public EnumerableSpan(EntityLinkedList source, int startNodeIndex, int count)
|
||||||
{
|
{
|
||||||
_source = source;
|
_source = source;
|
||||||
_startNodeIndex = startNodeIndex;
|
_startNodeIndex = startNodeIndex;
|
||||||
_count = count;
|
_count = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpanEnumerator GetEnumerator() => new SpanEnumerator(_source._nodes, _startNodeIndex, _count);
|
public SpanEnumerator GetEnumerator() => new SpanEnumerator(_source._nodes, _startNodeIndex, _count);
|
||||||
}
|
}
|
||||||
public struct SpanEnumerator
|
public struct SpanEnumerator
|
||||||
@ -126,7 +114,6 @@ namespace DCFApixels.DragonECS
|
|||||||
private int _index;
|
private int _index;
|
||||||
private int _count;
|
private int _count;
|
||||||
private int _next;
|
private int _next;
|
||||||
|
|
||||||
public SpanEnumerator(Node[] nodes, int startIndex, int count)
|
public SpanEnumerator(Node[] nodes, int startIndex, int count)
|
||||||
{
|
{
|
||||||
_nodes = nodes;
|
_nodes = nodes;
|
||||||
@ -134,16 +121,12 @@ namespace DCFApixels.DragonECS
|
|||||||
_count = count;
|
_count = count;
|
||||||
_next = startIndex;
|
_next = startIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Current => _nodes[_index].entityID;
|
public int Current => _nodes[_index].entityID;
|
||||||
|
|
||||||
public bool MoveNext()
|
public bool MoveNext()
|
||||||
{
|
{
|
||||||
if (_count <= 0)
|
|
||||||
return false;
|
|
||||||
_index = _next;
|
_index = _next;
|
||||||
_next = _nodes[_next].next;
|
_next = _nodes[_next].next;
|
||||||
return _index >= 0 && _count-- > 0;
|
return _index > 0 && _count-- > 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user