mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-11-12 16:45:55 +08:00
refactor collections
This commit is contained in:
parent
a863d6ee81
commit
d2356c1588
@ -18,100 +18,107 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
private readonly EcsGroup _source;
|
||||
|
||||
#region Constructors
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public EcsReadonlyGroup(EcsGroup source) => _source = source;
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
public bool IsNull => _source == null;
|
||||
public bool IsNull
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get { return _source == null; }
|
||||
}
|
||||
public int WorldID
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _source.WorldID;
|
||||
get { return _source.WorldID; }
|
||||
}
|
||||
public EcsWorld World
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _source.World;
|
||||
get { return _source.World; }
|
||||
}
|
||||
public int Count
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _source.Count;
|
||||
get { return _source.Count; }
|
||||
}
|
||||
public int CapacityDense
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _source.CapacityDense;
|
||||
get { return _source.CapacityDense; }
|
||||
}
|
||||
public int CapacitySparce
|
||||
public int CapacitySparce //TODO remove
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _source.CapacitySparce;
|
||||
get { return _source.CapacitySparce; }
|
||||
}
|
||||
public bool IsReleazed
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _source.IsReleased;
|
||||
get { return _source.IsReleased; }
|
||||
}
|
||||
public int this[int index]
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _source[index];
|
||||
get { return _source[index]; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public EcsReadonlyGroup(EcsGroup source)
|
||||
{
|
||||
_source = source;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Has(int entityID) => _source.Has(entityID);
|
||||
public bool Has(int entityID) { return _source.Has(entityID); }
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int IndexOf(int entityID) => _source.IndexOf(entityID);
|
||||
public int IndexOf(int entityID) { return _source.IndexOf(entityID); }
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public EcsGroup.Enumerator GetEnumerator() => _source.GetEnumerator();
|
||||
public EcsGroup.Enumerator GetEnumerator() { return _source.GetEnumerator(); }
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public EcsGroup Clone() => _source.Clone();
|
||||
public EcsGroup Clone() { return _source.Clone(); }
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int[] Bake() => _source.Bake();
|
||||
public int[] Bake() { return _source.Bake(); }
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int Bake(ref int[] entities) => _source.Bake(ref entities);
|
||||
public int Bake(ref int[] entities) { return _source.Bake(ref entities); }
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Bake(List<int> entities) => _source.Bake(entities);
|
||||
public void Bake(List<int> entities) { _source.Bake(entities); }
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public EcsSpan ToSpan() => _source.ToSpan();
|
||||
public EcsSpan ToSpan() { return _source.ToSpan(); }
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public EcsSpan ToSpan(int start, int length) => _source.ToSpan(start, length);
|
||||
public EcsSpan ToSpan(int start, int length) { return _source.ToSpan(start, length); }
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public EcsGroup.LongsIterator GetLongs() => _source.GetLongs();
|
||||
public EcsGroup.LongsIterator GetLongs() { return _source.GetLongs(); }
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int First() => _source.First();
|
||||
public int First() { return _source.First(); }
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int Last() => _source.Last();
|
||||
public int Last() { return _source.Last(); }
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool SetEquals(EcsReadonlyGroup group) => _source.SetEquals(group._source);
|
||||
public bool SetEquals(EcsGroup group) { return _source.SetEquals(group); }
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool SetEquals(EcsGroup group) => _source.SetEquals(group);
|
||||
public bool SetEquals(EcsReadonlyGroup group) { return _source.SetEquals(group._source); }
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool SetEquals(EcsSpan span) => _source.SetEquals(span);
|
||||
public bool SetEquals(EcsSpan span) { return _source.SetEquals(span); }
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Overlaps(EcsReadonlyGroup group) => _source.Overlaps(group._source);
|
||||
public bool Overlaps(EcsGroup group) { return _source.Overlaps(group); }
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Overlaps(EcsGroup group) => _source.Overlaps(group);
|
||||
public bool Overlaps(EcsReadonlyGroup group) { return _source.Overlaps(group._source); }
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Overlaps(EcsSpan span) => _source.Overlaps(span);
|
||||
public bool Overlaps(EcsSpan span) { return _source.Overlaps(span); }
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool IsSubsetOf(EcsReadonlyGroup group) => _source.IsSubsetOf(group._source);
|
||||
public bool IsSubsetOf(EcsGroup group) { return _source.IsSubsetOf(group); }
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool IsSubsetOf(EcsGroup group) => _source.IsSubsetOf(group);
|
||||
public bool IsSubsetOf(EcsReadonlyGroup group) { return _source.IsSubsetOf(group._source); }
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool IsSupersetOf(EcsReadonlyGroup group) => _source.IsSupersetOf(group._source);
|
||||
public bool IsSupersetOf(EcsGroup group) { return _source.IsSupersetOf(group); }
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool IsSupersetOf(EcsGroup group) => _source.IsSupersetOf(group);
|
||||
public bool IsSupersetOf(EcsReadonlyGroup group) { return _source.IsSupersetOf(group._source); }
|
||||
#endregion
|
||||
|
||||
#region Internal
|
||||
@ -127,23 +134,23 @@ namespace DCFApixels.DragonECS
|
||||
#pragma warning disable CS0809 // Устаревший член переопределяет неустаревший член
|
||||
[Obsolete("Equals() on EcsGroup will always throw an exception. Use the equality operator instead.")]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public override bool Equals(object obj) => throw new NotSupportedException();
|
||||
public override bool Equals(object obj) { throw new NotSupportedException(); }
|
||||
[Obsolete("GetHashCode() on EcsGroup will always throw an exception.")]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public override int GetHashCode() => throw new NotSupportedException();
|
||||
public override int GetHashCode() { throw new NotSupportedException(); }
|
||||
#pragma warning restore CS0809 // Устаревший член переопределяет неустаревший член
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static implicit operator EcsSpan(EcsReadonlyGroup a) => a.ToSpan();
|
||||
public static implicit operator EcsSpan(EcsReadonlyGroup a) { return a.ToSpan(); }
|
||||
#endregion
|
||||
}
|
||||
|
||||
[DebuggerTypeProxy(typeof(DebuggerProxy))]
|
||||
public unsafe class EcsGroup : IDisposable, IEnumerable<int>, IEntityStorage
|
||||
public class EcsGroup : IDisposable, IEnumerable<int>, IEntityStorage
|
||||
{
|
||||
private EcsWorld _source;
|
||||
private int[] _dense;
|
||||
private int[] _sparse;
|
||||
private int _count;
|
||||
private int _count = 0;
|
||||
internal bool _isReleased = true;
|
||||
|
||||
#region Properties
|
||||
@ -167,7 +174,7 @@ namespace DCFApixels.DragonECS
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _dense.Length;
|
||||
}
|
||||
public int CapacitySparce
|
||||
public int CapacitySparce //TODO remove
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _sparse.Length;
|
||||
@ -188,7 +195,7 @@ namespace DCFApixels.DragonECS
|
||||
get
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (index < 0 || index >= Count) Throw.ArgumentOutOfRange();
|
||||
if (index < 0 || index >= Count) { Throw.ArgumentOutOfRange(); }
|
||||
#endif
|
||||
return _dense[++index];
|
||||
}
|
||||
@ -205,12 +212,13 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
_source = world;
|
||||
_source.RegisterGroup(this);
|
||||
_dense = new int[denseCapacity];
|
||||
_dense = new int[denseCapacity]; //TODO добавить в конфиг мира значение
|
||||
_sparse = new int[world.Capacity];
|
||||
|
||||
_count = 0;
|
||||
}
|
||||
public void Dispose() => _source.ReleaseGroup(this);
|
||||
public void Dispose()
|
||||
{
|
||||
_source.ReleaseGroup(this);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Has/IndexOf
|
||||
@ -227,39 +235,51 @@ namespace DCFApixels.DragonECS
|
||||
#endregion
|
||||
|
||||
#region Add/Remove
|
||||
public void AddUnchecked(int entityID) => AddInternal(entityID);
|
||||
public void AddUnchecked(int entityID)
|
||||
{
|
||||
Add_Internal(entityID);
|
||||
}
|
||||
public bool Add(int entityID)
|
||||
{
|
||||
if (Has(entityID))
|
||||
{
|
||||
return false;
|
||||
AddInternal(entityID);
|
||||
}
|
||||
Add_Internal(entityID);
|
||||
return true;
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal void AddInternal(int entityID)
|
||||
internal void Add_Internal(int entityID)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (Has(entityID)) Throw.Group_AlreadyContains(entityID);
|
||||
if (Has(entityID)) { Throw.Group_AlreadyContains(entityID); }
|
||||
#endif
|
||||
if (++_count >= _dense.Length)
|
||||
{
|
||||
Array.Resize(ref _dense, _dense.Length << 1);
|
||||
}
|
||||
_dense[_count] = entityID;
|
||||
_sparse[entityID] = _count;
|
||||
}
|
||||
|
||||
public void RemoveUnchecked(int entityID) => RemoveInternal(entityID);
|
||||
public void RemoveUnchecked(int entityID)
|
||||
{
|
||||
Remove_Internal(entityID);
|
||||
}
|
||||
public bool Remove(int entityID)
|
||||
{
|
||||
if (!Has(entityID))
|
||||
if (Has(entityID) == false)
|
||||
{
|
||||
return false;
|
||||
RemoveInternal(entityID);
|
||||
}
|
||||
Remove_Internal(entityID);
|
||||
return true;
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal void RemoveInternal(int entityID)
|
||||
internal void Remove_Internal(int entityID)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (!Has(entityID)) Throw.Group_DoesNotContain(entityID);
|
||||
if (!Has(entityID)) { Throw.Group_DoesNotContain(entityID); }
|
||||
#endif
|
||||
_dense[_sparse[entityID]] = _dense[_count];
|
||||
_sparse[_dense[_count--]] = _sparse[entityID];
|
||||
@ -271,7 +291,9 @@ namespace DCFApixels.DragonECS
|
||||
foreach (var e in this)
|
||||
{
|
||||
if (!_source.IsUsed(e))
|
||||
RemoveInternal(e);
|
||||
{
|
||||
Remove_Internal(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
@ -280,24 +302,44 @@ namespace DCFApixels.DragonECS
|
||||
public void Clear()
|
||||
{
|
||||
_count = 0;
|
||||
//массив _dense нет смысла очищать
|
||||
for (int i = 0; i < _sparse.Length; i++)
|
||||
{
|
||||
_sparse[i] = 0;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region CopyFrom/Clone/Bake/ToSpan
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void CopyFrom(EcsReadonlyGroup group) => CopyFrom(group.GetSource_Internal());
|
||||
public void CopyFrom(EcsGroup group)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (group.World != _source) throw new ArgumentException("groupFilter.WorldIndex != WorldIndex");
|
||||
if (group.World != _source) { Throw.Group_ArgumentDifferentWorldsException(); }
|
||||
#endif
|
||||
if (_count > 0)
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
foreach (var item in group)
|
||||
AddInternal(item);
|
||||
{
|
||||
Add_Internal(item);
|
||||
}
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void CopyFrom(EcsReadonlyGroup group)
|
||||
{
|
||||
CopyFrom(group.GetSource_Internal());
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void CopyFrom(EcsSpan span)
|
||||
{
|
||||
if (_count > 0)
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
for (int i = 0; i < span.Length; i++)
|
||||
{
|
||||
Add_Internal(span[i]);
|
||||
}
|
||||
}
|
||||
public EcsGroup Clone()
|
||||
{
|
||||
@ -314,7 +356,9 @@ namespace DCFApixels.DragonECS
|
||||
public int Bake(ref int[] entities)
|
||||
{
|
||||
if (entities.Length < _count)
|
||||
{
|
||||
entities = new int[_count];
|
||||
}
|
||||
Array.Copy(_dense, 1, entities, 0, _count);
|
||||
return _count;
|
||||
}
|
||||
@ -334,10 +378,7 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
start -= 1;
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (start < 0 || start + length > _count)
|
||||
{
|
||||
Throw.ArgumentOutOfRange();
|
||||
}
|
||||
if (start < 0 || start + length > _count) { Throw.ArgumentOutOfRange(); }
|
||||
#endif
|
||||
return new EcsSpan(WorldID, _dense, start, length);
|
||||
}
|
||||
@ -357,7 +398,7 @@ namespace DCFApixels.DragonECS
|
||||
#endif
|
||||
foreach (var item in group)
|
||||
if (!Has(item))
|
||||
AddInternal(item);
|
||||
Add_Internal(item);
|
||||
}
|
||||
public void UnionWith(EcsSpan span)
|
||||
{
|
||||
@ -367,7 +408,7 @@ namespace DCFApixels.DragonECS
|
||||
foreach (var item in span)
|
||||
{
|
||||
if (!Has(item))
|
||||
AddInternal(item);
|
||||
Add_Internal(item);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
@ -405,7 +446,7 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
int item = _dense[i];
|
||||
if (group.Has(item))
|
||||
RemoveInternal(item);
|
||||
Remove_Internal(item);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -413,7 +454,7 @@ namespace DCFApixels.DragonECS
|
||||
foreach (var item in group)
|
||||
{
|
||||
if (Has(item))
|
||||
RemoveInternal(item);
|
||||
Remove_Internal(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -425,7 +466,7 @@ namespace DCFApixels.DragonECS
|
||||
foreach (var item in span)
|
||||
{
|
||||
if (Has(item))
|
||||
RemoveInternal(item);
|
||||
Remove_Internal(item);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
@ -444,7 +485,7 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
int item = _dense[i];
|
||||
if (!group.Has(item))
|
||||
RemoveInternal(item);
|
||||
Remove_Internal(item);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
@ -461,9 +502,9 @@ namespace DCFApixels.DragonECS
|
||||
#endif
|
||||
foreach (var item in group)
|
||||
if (Has(item))
|
||||
RemoveInternal(item);
|
||||
Remove_Internal(item);
|
||||
else
|
||||
AddInternal(item);
|
||||
Add_Internal(item);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -472,9 +513,9 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
foreach (var item in _source.Entities)
|
||||
if (Has(item))
|
||||
RemoveInternal(item);
|
||||
Remove_Internal(item);
|
||||
else
|
||||
AddInternal(item);
|
||||
Add_Internal(item);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -587,7 +628,7 @@ namespace DCFApixels.DragonECS
|
||||
#endif
|
||||
EcsGroup result = a._source.GetFreeGroup();
|
||||
foreach (var item in a)
|
||||
result.AddInternal(item);
|
||||
result.Add_Internal(item);
|
||||
foreach (var item in b)
|
||||
result.Add(item);
|
||||
return result;
|
||||
@ -602,7 +643,7 @@ namespace DCFApixels.DragonECS
|
||||
EcsGroup result = a._source.GetFreeGroup();
|
||||
foreach (var item in a)
|
||||
if (!b.Has(item))
|
||||
result.AddInternal(item);
|
||||
result.Add_Internal(item);
|
||||
return result;
|
||||
}
|
||||
/// <summary>as Intersect sets</summary>
|
||||
@ -615,7 +656,7 @@ namespace DCFApixels.DragonECS
|
||||
EcsGroup result = a._source.GetFreeGroup();
|
||||
foreach (var item in a)
|
||||
if (b.Has(item))
|
||||
result.AddInternal(item);
|
||||
result.Add_Internal(item);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -629,10 +670,10 @@ namespace DCFApixels.DragonECS
|
||||
EcsGroup result = a._source.GetFreeGroup();
|
||||
foreach (var item in a)
|
||||
if (!b.Has(item))
|
||||
result.AddInternal(item);
|
||||
result.Add_Internal(item);
|
||||
foreach (var item in b)
|
||||
if (!a.Has(item))
|
||||
result.AddInternal(item);
|
||||
result.Add_Internal(item);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -641,7 +682,7 @@ namespace DCFApixels.DragonECS
|
||||
EcsGroup result = a._source.GetFreeGroup();
|
||||
foreach (var item in a._source.Entities)
|
||||
if (!a.Has(item))
|
||||
result.AddInternal(item);
|
||||
result.Add_Internal(item);
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
@ -723,32 +764,22 @@ namespace DCFApixels.DragonECS
|
||||
public override string ToString()
|
||||
{
|
||||
return CollectionUtility.EntitiesToString(_dense.Skip(1).Take(_count), "group");
|
||||
//return $"group({_count}) {{{string.Join(", ", _dense.Skip(1).Take(_count).OrderBy(o => o))}}}";
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int First()
|
||||
{
|
||||
return _dense[1];
|
||||
}
|
||||
public int First() { return _dense[1]; }
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int Last()
|
||||
{
|
||||
return _dense[_count];
|
||||
}
|
||||
public int Last() { return _dense[_count]; }
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal void OnWorldResize(int newSize)
|
||||
{
|
||||
Array.Resize(ref _sparse, newSize);
|
||||
}
|
||||
internal void OnWorldResize(int newSize) { Array.Resize(ref _sparse, newSize); }
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static implicit operator EcsReadonlyGroup(EcsGroup a) => a.Readonly;
|
||||
public static implicit operator EcsReadonlyGroup(EcsGroup a) { return a.Readonly; }
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static implicit operator EcsSpan(EcsGroup a) => a.ToSpan();
|
||||
public static implicit operator EcsSpan(EcsGroup a) { return a.ToSpan(); }
|
||||
internal class DebuggerProxy
|
||||
{
|
||||
private EcsGroup _group;
|
||||
public EcsWorld World => _group.World;
|
||||
public bool IsReleased => _group.IsReleased;
|
||||
public EcsWorld World { get { return _group.World; } }
|
||||
public bool IsReleased { get { return _group.IsReleased; } }
|
||||
public EntitySlotInfo[] Entities
|
||||
{
|
||||
get
|
||||
@ -762,11 +793,11 @@ namespace DCFApixels.DragonECS
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public int Count => _group.Count;
|
||||
public int CapacityDense => _group.CapacityDense;
|
||||
public int CapacitySparce => _group.CapacitySparce;
|
||||
public override string ToString() => _group.ToString();
|
||||
public DebuggerProxy(EcsGroup group) => _group = group;
|
||||
public int Count { get { return _group.Count; } }
|
||||
public int CapacityDense { get { return _group.CapacityDense; } }
|
||||
public int CapacitySparce { get { return _group.CapacitySparce; } }
|
||||
public override string ToString() { return _group.ToString(); }
|
||||
public DebuggerProxy(EcsGroup group) { _group = group; }
|
||||
public DebuggerProxy(EcsReadonlyGroup group) : this(group.GetSource_Internal()) { }
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -14,29 +14,29 @@ namespace DCFApixels.DragonECS
|
||||
private readonly ReadOnlySpan<int> _values;
|
||||
|
||||
#region Properties
|
||||
public bool IsNull
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get { return _worldID == 0; }
|
||||
}
|
||||
public int WorldID
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _worldID;
|
||||
get { return _worldID; }
|
||||
}
|
||||
public EcsWorld World
|
||||
{
|
||||
get => EcsWorld.GetWorld(_worldID);
|
||||
get { return EcsWorld.GetWorld(_worldID); }
|
||||
}
|
||||
public int Length
|
||||
public int Length //TODO rename to Count
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _values.Length;
|
||||
get { return _values.Length; }
|
||||
}
|
||||
public int this[int index]
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _values[index];
|
||||
}
|
||||
public bool IsNull
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _worldID == 0;
|
||||
get { return _values[index]; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -51,7 +51,7 @@ namespace DCFApixels.DragonECS
|
||||
internal EcsSpan(int worldID, int[] array)
|
||||
{
|
||||
_worldID = worldID;
|
||||
_values = array;
|
||||
_values = new ReadOnlySpan<int>(array);
|
||||
}
|
||||
internal EcsSpan(int worldID, int[] array, int length)
|
||||
{
|
||||
@ -70,15 +70,15 @@ namespace DCFApixels.DragonECS
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int[] Bake()
|
||||
{
|
||||
int[] result = new int[_values.Length];
|
||||
_values.CopyTo(result);
|
||||
return result;
|
||||
return _values.ToArray();
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int Bake(ref int[] entities)
|
||||
{
|
||||
if (entities.Length < _values.Length)
|
||||
{
|
||||
Array.Resize(ref entities, _values.Length);
|
||||
}
|
||||
int[] result = new int[_values.Length];
|
||||
_values.CopyTo(result);
|
||||
return _values.Length;
|
||||
@ -95,42 +95,40 @@ namespace DCFApixels.DragonECS
|
||||
#endregion
|
||||
|
||||
#region operators
|
||||
public static bool operator ==(EcsSpan left, EcsSpan right) => left._values == right._values;
|
||||
public static bool operator !=(EcsSpan left, EcsSpan right) => left._values != right._values;
|
||||
public static bool operator ==(EcsSpan left, EcsSpan right) { return left._values == right._values; }
|
||||
public static bool operator !=(EcsSpan left, EcsSpan right) { return left._values != right._values; }
|
||||
#endregion
|
||||
|
||||
#region Enumerator
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public ReadOnlySpan<int>.Enumerator GetEnumerator() => _values.GetEnumerator();
|
||||
public ReadOnlySpan<int>.Enumerator GetEnumerator() { return _values.GetEnumerator(); }
|
||||
#endregion
|
||||
|
||||
#region Other
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public EcsSpan Slice(int start) => new EcsSpan(_worldID, _values.Slice(start));
|
||||
public EcsSpan Slice(int start) { return new EcsSpan(_worldID, _values.Slice(start)); }
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public EcsSpan Slice(int start, int length) => 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() => _values.ToArray();
|
||||
|
||||
#pragma warning disable CS0809 // Устаревший член переопределяет неустаревший член
|
||||
[Obsolete("Equals() on EcsSpan will always throw an exception. Use the equality operator instead.")]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public override bool Equals(object obj) => throw new NotSupportedException();
|
||||
[Obsolete("GetHashCode() on EcsSpan will always throw an exception.")]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public override int GetHashCode() => throw new NotSupportedException();
|
||||
#pragma warning restore CS0809 // Устаревший член переопределяет неустаревший член
|
||||
public int[] ToArray() { return _values.ToArray(); }
|
||||
public override string ToString()
|
||||
{
|
||||
return CollectionUtility.EntitiesToString(_values.ToArray(), "span");
|
||||
//return $"span({_values.Length}) {{{string.Join(", ", _values.ToArray().OrderBy(o => o))}}}";
|
||||
}
|
||||
#pragma warning disable CS0809 // Устаревший член переопределяет неустаревший член
|
||||
[Obsolete("Equals() on EcsSpan will always throw an exception. Use the equality operator instead.")]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public override bool Equals(object obj) { throw new NotSupportedException(); }
|
||||
[Obsolete("GetHashCode() on EcsSpan will always throw an exception.")]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public override int GetHashCode() { throw new NotSupportedException(); }
|
||||
#pragma warning restore CS0809 // Устаревший член переопределяет неустаревший член
|
||||
|
||||
internal class DebuggerProxy
|
||||
{
|
||||
private int[] _values;
|
||||
private int _worldID;
|
||||
public EcsWorld World => EcsWorld.GetWorld(_worldID);
|
||||
public EcsWorld World { get { return EcsWorld.GetWorld(_worldID); } }
|
||||
public EntitySlotInfo[] Entities
|
||||
{
|
||||
get
|
||||
@ -144,7 +142,7 @@ namespace DCFApixels.DragonECS
|
||||
return result;
|
||||
}
|
||||
}
|
||||
public int Count => _values.Length;
|
||||
public int Count { get { return _values.Length; } }
|
||||
public DebuggerProxy(EcsSpan span)
|
||||
{
|
||||
_values = new int[span.Length];
|
||||
|
||||
@ -200,7 +200,7 @@ namespace DCFApixels.DragonECS
|
||||
group.Clear();
|
||||
var enumerator = GetEnumerator();
|
||||
while (enumerator.MoveNext())
|
||||
group.AddInternal(enumerator.Current);
|
||||
group.Add_Internal(enumerator.Current);
|
||||
}
|
||||
public int CopyTo(ref int[] array)
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user