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