mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-11-13 17:15:54 +08:00
update set operations for EcsGroup
This commit is contained in:
parent
a00c47a980
commit
5243218b73
118
src/EcsGroup.cs
118
src/EcsGroup.cs
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using static UnityEngine.Networking.UnityWebRequest;
|
||||||
using delayedOp = System.Int32;
|
using delayedOp = System.Int32;
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
@ -10,6 +11,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
private readonly EcsGroup _source;
|
private readonly EcsGroup _source;
|
||||||
|
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public EcsReadonlyGroup(EcsGroup source) => _source = source;
|
public EcsReadonlyGroup(EcsGroup source) => _source = source;
|
||||||
@ -44,6 +46,24 @@ namespace DCFApixels.DragonECS
|
|||||||
return new EcsGroup(_source);
|
return new EcsGroup(_source);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Object
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
if (_source != null)
|
||||||
|
return _source.ToString();
|
||||||
|
return "NULL";
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Internal
|
||||||
|
internal void Release()
|
||||||
|
{
|
||||||
|
_source.World.ReleaseGroup(_source);
|
||||||
|
}
|
||||||
|
internal EcsGroup GetGroupInternal() => _source;
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
// не может содержать значение 0
|
// не может содержать значение 0
|
||||||
@ -206,26 +226,6 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region AddGroup/RemoveGroup
|
|
||||||
public void AddGroup(EcsReadonlyGroup group)
|
|
||||||
{ foreach (var item in group) Add(item.id); }
|
|
||||||
public void RemoveGroup(EcsReadonlyGroup group)
|
|
||||||
{ foreach (var item in group) Remove(item.id); }
|
|
||||||
public void AddGroup(EcsGroup group)
|
|
||||||
{ foreach (var item in group) Add(item.id); }
|
|
||||||
public void RemoveGroup(EcsGroup group)
|
|
||||||
{ foreach (var item in group) Remove(item.id); }
|
|
||||||
|
|
||||||
public void UncheckedAddGroup(EcsReadonlyGroup group)
|
|
||||||
{ foreach (var item in group) AddInternal(item.id); }
|
|
||||||
public void UncheckedRemoveGroup(EcsReadonlyGroup group)
|
|
||||||
{ foreach (var item in group) RemoveInternal(item.id); }
|
|
||||||
public void UncheckedAddGroup(EcsGroup group)
|
|
||||||
{ foreach (var item in group) AddInternal(item.id); }
|
|
||||||
public void UncheckedRemoveGroup(EcsGroup group)
|
|
||||||
{ foreach (var item in group) RemoveInternal(item.id); }
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
internal void OnWorldResize(int newSize)
|
internal void OnWorldResize(int newSize)
|
||||||
{
|
{
|
||||||
Array.Resize(ref _sparse, newSize);
|
Array.Resize(ref _sparse, newSize);
|
||||||
@ -245,55 +245,58 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
public void Clear() => _count = 0;
|
public void Clear() => _count = 0;
|
||||||
|
|
||||||
#region Set operations
|
public void CopyFrom(EcsGroup group)
|
||||||
public static EcsReadonlyGroup And(EcsGroup a, EcsGroup b)
|
|
||||||
{
|
{
|
||||||
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
||||||
if (a.World != b.World) throw new ArgumentException("a.World != b.World");
|
if (group.World != _source) throw new ArgumentException("group.World != World");
|
||||||
#endif
|
#endif
|
||||||
EcsGroup result = a.World.GetGroupFromPool();
|
Clear();
|
||||||
foreach (var item in a)
|
foreach (var item in group)
|
||||||
if(b.Contains(item.id))
|
AggressiveAdd(item.id);
|
||||||
result.AggressiveAdd(item.id);
|
}
|
||||||
|
|
||||||
return result.Readonly;
|
#region Set operations
|
||||||
}
|
/// <summary>as Union sets</summary>
|
||||||
public static EcsReadonlyGroup Union(EcsGroup a, EcsGroup b)
|
public void AddGroup(EcsGroup group)
|
||||||
{
|
{
|
||||||
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
||||||
if (a.World != b.World) throw new ArgumentException("a.World != b.World");
|
if (_source != group.World) throw new ArgumentException("World != group.World");
|
||||||
#endif
|
#endif
|
||||||
EcsGroup result = a.World.GetGroupFromPool();
|
foreach (var item in group)
|
||||||
foreach (var item in a)
|
if (!Contains(item.id))
|
||||||
result.AggressiveAdd(item.id);
|
AggressiveAdd(item.id);
|
||||||
foreach (var item in b)
|
|
||||||
result.Add(item.id);
|
|
||||||
return result.Readonly;
|
|
||||||
}
|
}
|
||||||
public static EcsReadonlyGroup Xor(EcsGroup a, EcsGroup b)
|
/// <summary>as Except sets</summary>
|
||||||
|
public void RemoveGroup(EcsGroup group)
|
||||||
{
|
{
|
||||||
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
||||||
if (a.World != b.World) throw new ArgumentException("a.World != b.World");
|
if (_source != group.World) throw new ArgumentException("World != group.World");
|
||||||
#endif
|
#endif
|
||||||
EcsGroup result = a.World.GetGroupFromPool();
|
foreach (var item in group)
|
||||||
foreach (var item in a)
|
if (Contains(item.id))
|
||||||
if (!b.Contains(item.id))
|
AggressiveRemove(item.id);
|
||||||
result.AggressiveAdd(item.id);
|
|
||||||
foreach (var item in b)
|
|
||||||
if (!a.Contains(item.id))
|
|
||||||
result.AggressiveAdd(item.id);
|
|
||||||
return result.Readonly;
|
|
||||||
}
|
}
|
||||||
public static EcsReadonlyGroup Remove(EcsGroup a, EcsGroup b)
|
/// <summary>as Intersect sets</summary>
|
||||||
|
public void AndWith(EcsGroup group)
|
||||||
{
|
{
|
||||||
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
||||||
if (a.World != b.World) throw new ArgumentException("a.World != b.World");
|
if (World != group.World) throw new ArgumentException("World != group.World");
|
||||||
#endif
|
#endif
|
||||||
EcsGroup result = a.World.GetGroupFromPool();
|
foreach (var item in this)
|
||||||
foreach (var item in a)
|
if (group.Contains(item.id))
|
||||||
if (!b.Contains(item.id))
|
AggressiveRemove(item.id);
|
||||||
result.AggressiveAdd(item.id);
|
}
|
||||||
return result.Readonly;
|
/// <summary>as Symmetric Except sets</summary>
|
||||||
|
public void XorWith(EcsGroup group)
|
||||||
|
{
|
||||||
|
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
||||||
|
if (_source != group.World) throw new ArgumentException("World != group.World");
|
||||||
|
#endif
|
||||||
|
foreach (var item in group)
|
||||||
|
if (Contains(item.id))
|
||||||
|
AggressiveRemove(item.id);
|
||||||
|
else
|
||||||
|
AggressiveAdd(item.id);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -355,6 +358,13 @@ namespace DCFApixels.DragonECS
|
|||||||
public void Dispose() => _source.Unlock();
|
public void Dispose() => _source.Unlock();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region OObject
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return string.Join(", ", _dense.AsSpan(1, _count).ToArray());
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class EcsGroupExtensions
|
public static class EcsGroupExtensions
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user