mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 18:14:37 +08:00
[*] update ToArray add ToCollection for collections
This commit is contained in:
parent
e271c77cab
commit
ca232ac33b
@ -90,6 +90,10 @@ namespace DCFApixels.DragonECS
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public int[] ToArray() { return _source.ToArray(); }
|
public int[] ToArray() { return _source.ToArray(); }
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public int ToArray(ref int[] dynamicBuffer) { return _source.ToArray(ref dynamicBuffer); }
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public void ToCollection(ICollection<int> collection) { _source.ToCollection(collection); }
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public EcsGroup.Enumerator GetEnumerator() { return _source.GetEnumerator(); }
|
public EcsGroup.Enumerator GetEnumerator() { return _source.GetEnumerator(); }
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@ -387,13 +391,32 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new EcsSpan(WorldID, _dense, 1, _count);
|
return new EcsSpan(WorldID, _dense, 1, _count);
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public int[] ToArray()
|
public int[] ToArray()
|
||||||
{
|
{
|
||||||
int[] result = new int[_count];
|
int[] result = new int[_count];
|
||||||
Array.Copy(_dense, 1, result, 0, _count);
|
Array.Copy(_dense, 1, result, 0, _count);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
public int ToArray(ref int[] dynamicBuffer)
|
||||||
|
{
|
||||||
|
if (dynamicBuffer.Length < _count)
|
||||||
|
{
|
||||||
|
Array.Resize(ref dynamicBuffer, ArrayUtility.NormalizeSizeToPowerOfTwo(_count));
|
||||||
|
}
|
||||||
|
int i = 0;
|
||||||
|
foreach (var e in this)
|
||||||
|
{
|
||||||
|
dynamicBuffer[i++] = e;
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
public void ToCollection(ICollection<int> collection)
|
||||||
|
{
|
||||||
|
foreach (var e in this)
|
||||||
|
{
|
||||||
|
collection.Add(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Set operations
|
#region Set operations
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using DCFApixels.DragonECS.Internal;
|
using DCFApixels.DragonECS.Internal;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
@ -78,13 +79,32 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Slice/ToArry
|
#region Slice/ToArray
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public EcsSpan Slice(int start) { return new EcsSpan(_worldID, _values.Slice(start)); }
|
public EcsSpan Slice(int start) { return new EcsSpan(_worldID, _values.Slice(start)); }
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public EcsSpan Slice(int start, int length) { return new EcsSpan(_worldID, _values.Slice(start, length)); }
|
public EcsSpan Slice(int start, int length) { return new EcsSpan(_worldID, _values.Slice(start, length)); }
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public int[] ToArray() { return _values.ToArray(); }
|
public int[] ToArray() { return _values.ToArray(); }
|
||||||
|
public int ToArray(ref int[] dynamicBuffer)
|
||||||
|
{
|
||||||
|
if (dynamicBuffer.Length < _values.Length)
|
||||||
|
{
|
||||||
|
Array.Resize(ref dynamicBuffer, ArrayUtility.NormalizeSizeToPowerOfTwo(_values.Length));
|
||||||
|
}
|
||||||
|
int i = 0;
|
||||||
|
foreach (var e in this)
|
||||||
|
{
|
||||||
|
dynamicBuffer[i++] = e;
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
public void ToCollection(ICollection<int> collection)
|
||||||
|
{
|
||||||
|
foreach (var e in this)
|
||||||
|
{
|
||||||
|
collection.Add(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region operators
|
#region operators
|
||||||
@ -199,8 +219,36 @@ namespace DCFApixels.DragonECS
|
|||||||
public EcsLongsSpan Slice(int start, int length) { return new EcsLongsSpan(_source.Slice(start, length)); }
|
public EcsLongsSpan Slice(int start, int length) { return new EcsLongsSpan(_source.Slice(start, length)); }
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public EcsSpan ToSpan() { return _source; }
|
public EcsSpan ToSpan() { return _source; }
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
public entlong[] ToArray()
|
||||||
public int[] ToArray() { return _source.ToArray(); }
|
{
|
||||||
|
entlong[] result = new entlong[_source.Count];
|
||||||
|
int i = 0;
|
||||||
|
foreach (var e in this)
|
||||||
|
{
|
||||||
|
result[i++] = e;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public int ToArray(ref entlong[] dynamicBuffer)
|
||||||
|
{
|
||||||
|
if (dynamicBuffer.Length < _source.Count)
|
||||||
|
{
|
||||||
|
Array.Resize(ref dynamicBuffer, ArrayUtility.NormalizeSizeToPowerOfTwo(_source.Count));
|
||||||
|
}
|
||||||
|
int i = 0;
|
||||||
|
foreach (var e in this)
|
||||||
|
{
|
||||||
|
dynamicBuffer[i++] = e;
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
public void ToCollection(ICollection<entlong> collection)
|
||||||
|
{
|
||||||
|
foreach (var e in this)
|
||||||
|
{
|
||||||
|
collection.Add(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region operators
|
#region operators
|
||||||
|
Loading…
Reference in New Issue
Block a user