Revert "update EcsGroup"

This reverts commit 29e92ede0b.
This commit is contained in:
Mikhail 2023-06-05 00:22:06 +08:00
parent 29e92ede0b
commit a7323363c4
4 changed files with 47 additions and 56 deletions

View File

@ -16,8 +16,8 @@
public readonly S1 s1; public readonly S1 s1;
public CombinedSubject(Builder b) public CombinedSubject(Builder b)
{ {
s0 = b.CombineInclude<S0>(); s0 = b.Combine<S0>();
s1 = b.CombineInclude<S1>(); s1 = b.Combine<S1>();
} }
} }
@ -31,9 +31,9 @@
public readonly S2 s2; public readonly S2 s2;
public CombinedSubject(Builder b) public CombinedSubject(Builder b)
{ {
s0 = b.CombineInclude<S0>(); s0 = b.Combine<S0>();
s1 = b.CombineInclude<S1>(); s1 = b.Combine<S1>();
s2 = b.CombineInclude<S2>(); s2 = b.Combine<S2>();
} }
} }
@ -49,10 +49,10 @@
public readonly S3 s3; public readonly S3 s3;
public CombinedSubject(Builder b) public CombinedSubject(Builder b)
{ {
s0 = b.CombineInclude<S0>(); s0 = b.Combine<S0>();
s1 = b.CombineInclude<S1>(); s1 = b.Combine<S1>();
s2 = b.CombineInclude<S2>(); s2 = b.Combine<S2>();
s3 = b.CombineInclude<S3>(); s3 = b.Combine<S3>();
} }
} }
@ -70,11 +70,11 @@
public readonly S4 s4; public readonly S4 s4;
public CombinedSubject(Builder b) public CombinedSubject(Builder b)
{ {
s0 = b.CombineInclude<S0>(); s0 = b.Combine<S0>();
s1 = b.CombineInclude<S1>(); s1 = b.Combine<S1>();
s2 = b.CombineInclude<S2>(); s2 = b.Combine<S2>();
s3 = b.CombineInclude<S3>(); s3 = b.Combine<S3>();
s4 = b.CombineInclude<S4>(); s4 = b.Combine<S4>();
} }
} }
@ -94,12 +94,12 @@
public readonly S5 s5; public readonly S5 s5;
public CombinedSubject(Builder b) public CombinedSubject(Builder b)
{ {
s0 = b.CombineInclude<S0>(); s0 = b.Combine<S0>();
s1 = b.CombineInclude<S1>(); s1 = b.Combine<S1>();
s2 = b.CombineInclude<S2>(); s2 = b.Combine<S2>();
s3 = b.CombineInclude<S3>(); s3 = b.Combine<S3>();
s4 = b.CombineInclude<S4>(); s4 = b.Combine<S4>();
s5 = b.CombineInclude<S5>(); s5 = b.Combine<S5>();
} }
} }

View File

@ -71,8 +71,8 @@ namespace DCFApixels.DragonECS
[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 ReadOnlySpan<int> ToSpan() => _source.ToSpan(); public Span<int> ToSpan() => _source.ToSpan();
public ReadOnlySpan<int> ToSpan(int start, int length) => _source.ToSpan(start, length); public Span<int> ToSpan(int start, int length) => _source.ToSpan(start, length);
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public int First() => _source.First(); public int First() => _source.First();
@ -163,6 +163,7 @@ namespace DCFApixels.DragonECS
{ {
return world.GetFreeGroup(); return world.GetFreeGroup();
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal EcsGroup(EcsWorld world, int denseCapacity = 64) internal EcsGroup(EcsWorld world, int denseCapacity = 64)
{ {
_source = world; _source = world;
@ -281,13 +282,13 @@ namespace DCFApixels.DragonECS
foreach (var e in this) foreach (var e in this)
entities.Add(e); entities.Add(e);
} }
public ReadOnlySpan<int> ToSpan() => new ReadOnlySpan<int>(_dense, 0, _count); public Span<int> ToSpan() => new Span<int>(_dense, 0, _count);
public ReadOnlySpan<int> ToSpan(int start, int length) public Span<int> ToSpan(int start, int length)
{ {
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
if (start + length > _count) ThrowArgumentOutOfRangeException(); if (start + length > _count) ThrowArgumentOutOfRangeException();
#endif #endif
return new ReadOnlySpan<int>(_dense, start, length); return new Span<int>(_dense, start, length);
} }
#endregion #endregion
@ -322,9 +323,9 @@ namespace DCFApixels.DragonECS
/// <summary>as Intersect sets</summary> /// <summary>as Intersect sets</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void IntersectWith(EcsReadonlyGroup group) => IntersectWith(group.GetGroupInternal()); public void AndWith(EcsReadonlyGroup group) => AndWith(group.GetGroupInternal());
/// <summary>as Intersect sets</summary> /// <summary>as Intersect sets</summary>
public void IntersectWith(EcsGroup group) public void AndWith(EcsGroup group)
{ {
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
if (World != group.World) ThrowArgumentDifferentWorldsException(); if (World != group.World) ThrowArgumentDifferentWorldsException();
@ -336,9 +337,9 @@ namespace DCFApixels.DragonECS
/// <summary>as Symmetric Except sets</summary> /// <summary>as Symmetric Except sets</summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SymmetricExceptWith(EcsReadonlyGroup group) => SymmetricExceptWith(group.GetGroupInternal()); public void XorWith(EcsReadonlyGroup group) => XorWith(group.GetGroupInternal());
/// <summary>as Symmetric Except sets</summary> /// <summary>as Symmetric Except sets</summary>
public void SymmetricExceptWith(EcsGroup group) public void XorWith(EcsGroup group)
{ {
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
if (_source != group.World) ThrowArgumentDifferentWorldsException(); if (_source != group.World) ThrowArgumentDifferentWorldsException();
@ -389,7 +390,7 @@ namespace DCFApixels.DragonECS
} }
/// <summary>as Intersect sets</summary> /// <summary>as Intersect sets</summary>
/// <returns>new group from pool</returns> /// <returns>new group from pool</returns>
public static EcsGroup Intersect(EcsGroup a, EcsGroup b) public static EcsGroup And(EcsGroup a, EcsGroup b)
{ {
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
if (a._source != b._source) ThrowArgumentDifferentWorldsException(); if (a._source != b._source) ThrowArgumentDifferentWorldsException();
@ -403,7 +404,7 @@ namespace DCFApixels.DragonECS
/// <summary>as Symmetric Except sets</summary> /// <summary>as Symmetric Except sets</summary>
/// <returns>new group from pool</returns> /// <returns>new group from pool</returns>
public static EcsGroup SymmetricExcept(EcsGroup a, EcsGroup b) public static EcsGroup Xor(EcsGroup a, EcsGroup b)
{ {
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS #if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
if (a._source != b._source) ThrowArgumentDifferentWorldsException(); if (a._source != b._source) ThrowArgumentDifferentWorldsException();

View File

@ -100,8 +100,8 @@ namespace DCFApixels.DragonECS
} }
#endregion #endregion
#region Combine Include/Exclude/Optional #region Combine
public TOtherSubject CombineInclude<TOtherSubject>() where TOtherSubject : EcsSubject public TOtherSubject Combine<TOtherSubject>() where TOtherSubject : EcsSubject
{ {
var result = _world.GetSubject<TOtherSubject>(); var result = _world.GetSubject<TOtherSubject>();
_inc.ExceptWith(result.mask._exc);//удаляю конфликтующие ограничения _inc.ExceptWith(result.mask._exc);//удаляю конфликтующие ограничения
@ -111,20 +111,6 @@ namespace DCFApixels.DragonECS
_exc.UnionWith(result.mask._exc); _exc.UnionWith(result.mask._exc);
return result; return result;
} }
public TOtherSubject CombineExclude<TOtherSubject>() where TOtherSubject : EcsSubject
{
var result = _world.GetSubject<TOtherSubject>();
_inc.ExceptWith(result.mask._exc);//удаляю конфликтующие ограничения
_exc.ExceptWith(result.mask._inc);//удаляю конфликтующие ограничения
_inc.UnionWith(result.mask._inc);
_exc.UnionWith(result.mask._exc);
return result;
}
public TOtherSubject CombineOptional<TOtherSubject>() where TOtherSubject : EcsSubject
{
return _world.GetSubject<TOtherSubject>();
}
#endregion #endregion
private void End(out EcsMask mask) private void End(out EcsMask mask)
@ -134,7 +120,7 @@ namespace DCFApixels.DragonECS
var exc = _exc.ToArray(); var exc = _exc.ToArray();
Array.Sort(exc); Array.Sort(exc);
mask = new EcsMask(_world.Archetype, inc, exc, _inc.Overlaps(exc)); mask = new EcsMask(_world.Archetype, inc, exc);
_world = null; _world = null;
_inc = null; _inc = null;
_exc = null; _exc = null;
@ -184,14 +170,22 @@ namespace DCFApixels.DragonECS
internal readonly Type _worldType; internal readonly Type _worldType;
internal readonly int[] _inc; internal readonly int[] _inc;
internal readonly int[] _exc; internal readonly int[] _exc;
internal readonly bool _isConflicting; public EcsMask(Type worldType, int[] inc, int[] exc)
public EcsMask(Type worldType, int[] inc, int[] exc, bool isConflicting)
{ {
_worldType = worldType; _worldType = worldType;
_inc = inc; _inc = inc;
_exc = exc; _exc = exc;
_isConflicting = isConflicting; }
public static EcsMask Union(EcsMask a, EcsMask b)
{
if(a._worldType != b._worldType) ThrowHelper.ThrowArgumentDifferentWorldsException();
HashSet<int> incset = new HashSet<int>(a._inc);
HashSet<int> excset = new HashSet<int>(a._exc);
incset.UnionWith(b._inc);
excset.UnionWith(b._exc);
return new EcsMask(a._worldType, incset.ToArray(), excset.ToArray());
} }
#region Object #region Object

View File

@ -42,8 +42,6 @@ namespace DCFApixels.DragonECS
private object[] _components; private object[] _components;
private EcsGroup _emptyGroup;
#region Properties #region Properties
public abstract Type Archetype { get; } public abstract Type Archetype { get; }
public int UniqueID => uniqueID; public int UniqueID => uniqueID;
@ -86,7 +84,6 @@ namespace DCFApixels.DragonECS
_groups = new List<WeakReference<EcsGroup>>(); _groups = new List<WeakReference<EcsGroup>>();
_allEntites = GetFreeGroup(); _allEntites = GetFreeGroup();
_emptyGroup = GetFreeGroup();
_subjects = new EcsSubject[128]; _subjects = new EcsSubject[128];
_executors = new EcsQueryExecutor[128]; _executors = new EcsQueryExecutor[128];
@ -357,7 +354,6 @@ namespace DCFApixels.DragonECS
group.Clear(); group.Clear();
_groupsPool.Push(group); _groupsPool.Push(group);
} }
internal EcsGroup GetEmptyGroup() => _emptyGroup;
#endregion #endregion
#region Debug #region Debug