mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 09:54:35 +08:00
update EcsGroup
rename set operations replace Span with ReadOnlySpan
This commit is contained in:
parent
a4c2b65eb9
commit
29e92ede0b
@ -16,8 +16,8 @@
|
||||
public readonly S1 s1;
|
||||
public CombinedSubject(Builder b)
|
||||
{
|
||||
s0 = b.Combine<S0>();
|
||||
s1 = b.Combine<S1>();
|
||||
s0 = b.CombineInclude<S0>();
|
||||
s1 = b.CombineInclude<S1>();
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,9 +31,9 @@
|
||||
public readonly S2 s2;
|
||||
public CombinedSubject(Builder b)
|
||||
{
|
||||
s0 = b.Combine<S0>();
|
||||
s1 = b.Combine<S1>();
|
||||
s2 = b.Combine<S2>();
|
||||
s0 = b.CombineInclude<S0>();
|
||||
s1 = b.CombineInclude<S1>();
|
||||
s2 = b.CombineInclude<S2>();
|
||||
}
|
||||
}
|
||||
|
||||
@ -49,10 +49,10 @@
|
||||
public readonly S3 s3;
|
||||
public CombinedSubject(Builder b)
|
||||
{
|
||||
s0 = b.Combine<S0>();
|
||||
s1 = b.Combine<S1>();
|
||||
s2 = b.Combine<S2>();
|
||||
s3 = b.Combine<S3>();
|
||||
s0 = b.CombineInclude<S0>();
|
||||
s1 = b.CombineInclude<S1>();
|
||||
s2 = b.CombineInclude<S2>();
|
||||
s3 = b.CombineInclude<S3>();
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,11 +70,11 @@
|
||||
public readonly S4 s4;
|
||||
public CombinedSubject(Builder b)
|
||||
{
|
||||
s0 = b.Combine<S0>();
|
||||
s1 = b.Combine<S1>();
|
||||
s2 = b.Combine<S2>();
|
||||
s3 = b.Combine<S3>();
|
||||
s4 = b.Combine<S4>();
|
||||
s0 = b.CombineInclude<S0>();
|
||||
s1 = b.CombineInclude<S1>();
|
||||
s2 = b.CombineInclude<S2>();
|
||||
s3 = b.CombineInclude<S3>();
|
||||
s4 = b.CombineInclude<S4>();
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,12 +94,12 @@
|
||||
public readonly S5 s5;
|
||||
public CombinedSubject(Builder b)
|
||||
{
|
||||
s0 = b.Combine<S0>();
|
||||
s1 = b.Combine<S1>();
|
||||
s2 = b.Combine<S2>();
|
||||
s3 = b.Combine<S3>();
|
||||
s4 = b.Combine<S4>();
|
||||
s5 = b.Combine<S5>();
|
||||
s0 = b.CombineInclude<S0>();
|
||||
s1 = b.CombineInclude<S1>();
|
||||
s2 = b.CombineInclude<S2>();
|
||||
s3 = b.CombineInclude<S3>();
|
||||
s4 = b.CombineInclude<S4>();
|
||||
s5 = b.CombineInclude<S5>();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,8 +71,8 @@ namespace DCFApixels.DragonECS
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Bake(List<int> entities) => _source.Bake(entities);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Span<int> ToSpan() => _source.ToSpan();
|
||||
public Span<int> ToSpan(int start, int length) => _source.ToSpan(start, length);
|
||||
public ReadOnlySpan<int> ToSpan() => _source.ToSpan();
|
||||
public ReadOnlySpan<int> ToSpan(int start, int length) => _source.ToSpan(start, length);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int First() => _source.First();
|
||||
@ -163,7 +163,6 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
return world.GetFreeGroup();
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal EcsGroup(EcsWorld world, int denseCapacity = 64)
|
||||
{
|
||||
_source = world;
|
||||
@ -282,13 +281,13 @@ namespace DCFApixels.DragonECS
|
||||
foreach (var e in this)
|
||||
entities.Add(e);
|
||||
}
|
||||
public Span<int> ToSpan() => new Span<int>(_dense, 0, _count);
|
||||
public Span<int> ToSpan(int start, int length)
|
||||
public ReadOnlySpan<int> ToSpan() => new ReadOnlySpan<int>(_dense, 0, _count);
|
||||
public ReadOnlySpan<int> ToSpan(int start, int length)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (start + length > _count) ThrowArgumentOutOfRangeException();
|
||||
#endif
|
||||
return new Span<int>(_dense, start, length);
|
||||
return new ReadOnlySpan<int>(_dense, start, length);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -323,9 +322,9 @@ namespace DCFApixels.DragonECS
|
||||
|
||||
/// <summary>as Intersect sets</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void AndWith(EcsReadonlyGroup group) => AndWith(group.GetGroupInternal());
|
||||
public void IntersectWith(EcsReadonlyGroup group) => IntersectWith(group.GetGroupInternal());
|
||||
/// <summary>as Intersect sets</summary>
|
||||
public void AndWith(EcsGroup group)
|
||||
public void IntersectWith(EcsGroup group)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (World != group.World) ThrowArgumentDifferentWorldsException();
|
||||
@ -337,9 +336,9 @@ namespace DCFApixels.DragonECS
|
||||
|
||||
/// <summary>as Symmetric Except sets</summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void XorWith(EcsReadonlyGroup group) => XorWith(group.GetGroupInternal());
|
||||
public void SymmetricExceptWith(EcsReadonlyGroup group) => SymmetricExceptWith(group.GetGroupInternal());
|
||||
/// <summary>as Symmetric Except sets</summary>
|
||||
public void XorWith(EcsGroup group)
|
||||
public void SymmetricExceptWith(EcsGroup group)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (_source != group.World) ThrowArgumentDifferentWorldsException();
|
||||
@ -390,7 +389,7 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
/// <summary>as Intersect sets</summary>
|
||||
/// <returns>new group from pool</returns>
|
||||
public static EcsGroup And(EcsGroup a, EcsGroup b)
|
||||
public static EcsGroup Intersect(EcsGroup a, EcsGroup b)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (a._source != b._source) ThrowArgumentDifferentWorldsException();
|
||||
@ -404,7 +403,7 @@ namespace DCFApixels.DragonECS
|
||||
|
||||
/// <summary>as Symmetric Except sets</summary>
|
||||
/// <returns>new group from pool</returns>
|
||||
public static EcsGroup Xor(EcsGroup a, EcsGroup b)
|
||||
public static EcsGroup SymmetricExcept(EcsGroup a, EcsGroup b)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (a._source != b._source) ThrowArgumentDifferentWorldsException();
|
||||
|
@ -100,8 +100,8 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Combine
|
||||
public TOtherSubject Combine<TOtherSubject>() where TOtherSubject : EcsSubject
|
||||
#region Combine Include/Exclude/Optional
|
||||
public TOtherSubject CombineInclude<TOtherSubject>() where TOtherSubject : EcsSubject
|
||||
{
|
||||
var result = _world.GetSubject<TOtherSubject>();
|
||||
_inc.ExceptWith(result.mask._exc);//удаляю конфликтующие ограничения
|
||||
@ -111,6 +111,20 @@ namespace DCFApixels.DragonECS
|
||||
_exc.UnionWith(result.mask._exc);
|
||||
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
|
||||
|
||||
private void End(out EcsMask mask)
|
||||
@ -120,7 +134,7 @@ namespace DCFApixels.DragonECS
|
||||
var exc = _exc.ToArray();
|
||||
Array.Sort(exc);
|
||||
|
||||
mask = new EcsMask(_world.Archetype, inc, exc);
|
||||
mask = new EcsMask(_world.Archetype, inc, exc, _inc.Overlaps(exc));
|
||||
_world = null;
|
||||
_inc = null;
|
||||
_exc = null;
|
||||
@ -170,24 +184,16 @@ namespace DCFApixels.DragonECS
|
||||
internal readonly Type _worldType;
|
||||
internal readonly int[] _inc;
|
||||
internal readonly int[] _exc;
|
||||
public EcsMask(Type worldType, int[] inc, int[] exc)
|
||||
internal readonly bool _isConflicting;
|
||||
|
||||
public EcsMask(Type worldType, int[] inc, int[] exc, bool isConflicting)
|
||||
{
|
||||
_worldType = worldType;
|
||||
_inc = inc;
|
||||
_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
|
||||
public override string ToString() => CreateLogString(_worldType, _inc, _exc);
|
||||
#endregion
|
||||
|
@ -42,6 +42,8 @@ namespace DCFApixels.DragonECS
|
||||
|
||||
private object[] _components;
|
||||
|
||||
private EcsGroup _emptyGroup;
|
||||
|
||||
#region Properties
|
||||
public abstract Type Archetype { get; }
|
||||
public int UniqueID => uniqueID;
|
||||
@ -84,6 +86,7 @@ namespace DCFApixels.DragonECS
|
||||
|
||||
_groups = new List<WeakReference<EcsGroup>>();
|
||||
_allEntites = GetFreeGroup();
|
||||
_emptyGroup = GetFreeGroup();
|
||||
|
||||
_subjects = new EcsSubject[128];
|
||||
_executors = new EcsQueryExecutor[128];
|
||||
@ -354,6 +357,7 @@ namespace DCFApixels.DragonECS
|
||||
group.Clear();
|
||||
_groupsPool.Push(group);
|
||||
}
|
||||
internal EcsGroup GetEmptyGroup() => _emptyGroup;
|
||||
#endregion
|
||||
|
||||
#region Debug
|
||||
|
Loading…
Reference in New Issue
Block a user