From e2371103c1497afffe0537584649b6062de9b507 Mon Sep 17 00:00:00 2001
From: Mikhail <99481254+DCFApixels@users.noreply.github.com>
Date: Fri, 21 Apr 2023 16:03:50 +0800
Subject: [PATCH] fix filter fbug
---
src/Builtin/Components.cs | 30 -------------
src/Builtin/InjectSystem.cs | 2 +-
src/Builtin/Worlds.cs | 4 +-
src/EcsEdgeWorld.cs | 23 ----------
src/EcsJoinQuery.cs | 83 ++++++++++++++++++++++++++++++++++++
src/EcsQuery.cs | 60 ++++----------------------
src/EcsWorld.cs | 2 +-
src/Interfaces/IEcsTable.cs | 2 +-
src/Pools/EcsAttachPool.cs | 21 ++++++---
src/Pools/EcsNotNullPool.cs | 18 ++++++--
src/Pools/EcsPool.cs | 20 +++++++--
src/Pools/EcsRelationPool.cs | 21 ++++++---
src/Pools/EcsSinglePool.cs | 15 ++++++-
src/Pools/EcsTagPool.cs | 18 ++++++--
14 files changed, 188 insertions(+), 131 deletions(-)
delete mode 100644 src/Builtin/Components.cs
delete mode 100644 src/EcsEdgeWorld.cs
create mode 100644 src/EcsJoinQuery.cs
diff --git a/src/Builtin/Components.cs b/src/Builtin/Components.cs
deleted file mode 100644
index 46ec954..0000000
--- a/src/Builtin/Components.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace DCFApixels.DragonECS
-{
- ///
- /// Используется для реализации отношений. traget - это сущьность к которой крепится эта сущьность. other - это сущьность с которой traget образует связь
- ///
- [StructLayout(LayoutKind.Explicit, Pack = 8, Size = 16)]
- public readonly struct Edge
- {
- [FieldOffset(0), MarshalAs(UnmanagedType.U8)]
- public readonly EcsEntity origin;
- [FieldOffset(1), MarshalAs(UnmanagedType.U8)]
- public readonly EcsEntity other;
-
- /// alias for "origin"
- public EcsEntity left
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => origin;
- }
- /// alias for "other"
- public EcsEntity right
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- get => other;
- }
- }
-}
diff --git a/src/Builtin/InjectSystem.cs b/src/Builtin/InjectSystem.cs
index 8fc3239..5615de9 100644
--- a/src/Builtin/InjectSystem.cs
+++ b/src/Builtin/InjectSystem.cs
@@ -52,7 +52,7 @@ namespace DCFApixels.DragonECS
public void Inject(T obj);
}
- [DebugHide, DebugColor(DebugColor.Gray)]
+ [DebugHide, DebugColor(DebugColor.Gray)]
public sealed class InjectRunner : EcsRunner>, IEcsInject
{
private IEcsPreInject _preInjectchache;
diff --git a/src/Builtin/Worlds.cs b/src/Builtin/Worlds.cs
index 73a3828..3278ef9 100644
--- a/src/Builtin/Worlds.cs
+++ b/src/Builtin/Worlds.cs
@@ -11,8 +11,8 @@
{
public EcsDefaultWrold(EcsPipeline pipeline = null) : base(pipeline) { }
}
- public sealed class EcsEventWrold : EcsEdgeWorld
+ public sealed class EcsEventWrold : EcsWorld
{
- public EcsEventWrold(EcsWorld firstTarget, EcsWorld secondTarget, EcsPipeline pipeline = null) : base(firstTarget, secondTarget, pipeline) { }
+ public EcsEventWrold(EcsPipeline pipeline = null) : base(pipeline) { }
}
}
diff --git a/src/EcsEdgeWorld.cs b/src/EcsEdgeWorld.cs
deleted file mode 100644
index a6c68e3..0000000
--- a/src/EcsEdgeWorld.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace DCFApixels.DragonECS
-{
- public class EcsEdgeWorld : EcsWorld where TWorldArchetype : EcsWorld
- {
- private EcsWorld _firstTarget;
- private EcsWorld _secondTarget;
- public EcsEdgeWorld(EcsWorld firstTarget, EcsWorld secondTarget, EcsPipeline pipeline) : base(pipeline)
- {
- _firstTarget = firstTarget;
- _secondTarget = secondTarget;
- }
- public EcsEdgeWorld(EcsWorld firstTarget, EcsPipeline pipeline) : base(pipeline)
- {
- _firstTarget = firstTarget;
- }
- }
-}
diff --git a/src/EcsJoinQuery.cs b/src/EcsJoinQuery.cs
new file mode 100644
index 0000000..c404d17
--- /dev/null
+++ b/src/EcsJoinQuery.cs
@@ -0,0 +1,83 @@
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using Unity.Profiling;
+
+namespace DCFApixels.DragonECS
+{
+ public abstract class EcsJoinQueryBase : EcsQueryBase
+ {
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ protected void ExecuteWhere()
+ {
+ var pools = World.GetAllPools();
+ EcsReadonlyGroup all = World.Entities;
+ groupFilter.Clear();
+ foreach (var e in all)
+ {
+ int entityID = e.id;
+ for (int i = 0, iMax = mask.Inc.Length; i < iMax; i++)
+ {
+ if (!pools[mask.Inc[i]].Has(entityID))
+ goto next;
+ }
+ for (int i = 0, iMax = mask.Exc.Length; i < iMax; i++)
+ {
+ if (pools[mask.Exc[i]].Has(entityID))
+ goto next;
+ }
+ groupFilter.AggressiveAdd(entityID);
+ next: continue;
+ }
+ groupFilter.Sort();
+ }
+ }
+ public abstract class EcsJoinAttachQuery : EcsJoinQueryBase
+ where TAttachComponent : struct, IEcsAttachComponent
+ {
+ private EcsWorld _targetWorld;
+ private EcsAttachPool _targetPool;
+
+ private ProfilerMarker _execute = new ProfilerMarker("EcsJoinAttachQuery.Execute");
+ protected sealed override void OnBuild(Builder b)
+ {
+ _targetPool = b.Include();
+ }
+ public sealed override void Execute()
+ {
+ using (_execute.Auto())
+ {
+ ExecuteWhere();
+ }
+ }
+ public EcsGroup.Enumerator GetEnumerator()
+ {
+ return groupFilter.GetEnumerator();
+ }
+ }
+ public abstract class EcsJoinRelationQuery : EcsJoinQueryBase
+ where TRelationComponent : struct, IEcsRelationComponent
+ {
+ private EcsWorld _firstWorld;
+ private EcsWorld _secondWorld;
+ private EcsRelationPool _targetPool;
+
+ private ProfilerMarker _execute = new ProfilerMarker("EcsJoinRelationQuery.Execute");
+ protected sealed override void OnBuild(Builder b)
+ {
+ _targetPool = source.GetPool();
+ }
+ public sealed override void Execute()
+ {
+ using (_execute.Auto())
+ {
+ ExecuteWhere();
+ }
+ }
+ public EcsGroup.Enumerator GetEnumerator()
+ {
+ return groupFilter.GetEnumerator();
+ }
+ }
+}
diff --git a/src/EcsQuery.cs b/src/EcsQuery.cs
index 6c454e4..9198ea8 100644
--- a/src/EcsQuery.cs
+++ b/src/EcsQuery.cs
@@ -14,7 +14,7 @@ namespace DCFApixels.DragonECS
#region Builder
protected virtual void Init(Builder b) { }
- protected abstract void OnBuildAfter();
+ protected abstract void OnBuild(Builder b);
public abstract void Execute();
public sealed class Builder : EcsQueryBuilderBase
{
@@ -45,8 +45,8 @@ namespace DCFApixels.DragonECS
}
newQuery.groupFilter = EcsGroup.New(world);
newQuery.source = world;
+ newQuery.OnBuild(builder);
builder.End(out newQuery.mask);
- newQuery.OnBuildAfter();
return (TQuery)(object)newQuery;
}
@@ -77,61 +77,16 @@ namespace DCFApixels.DragonECS
}
#endregion
}
- public abstract class EcsJoinAttachQuery : EcsQueryBase
- {
- // private EcsPool attachPool;
-
- private ProfilerMarker _getEnumerator = new ProfilerMarker("EcsJoinAttachQuery.Execute");
- protected sealed override void OnBuildAfter()
- {
- throw new NotImplementedException();
- // attachPool = World.GetPool();
- }
- public sealed override void Execute()
- {
- using (_getEnumerator.Auto())
- {
- throw new NotImplementedException();
- }
- }
- public EcsGroup.Enumerator GetEnumerator()
- {
- return groupFilter.GetEnumerator();
- }
- }
- public abstract class EcsJoinRelationQuery : EcsQueryBase
- {
- // private EcsPool attachPool;
-
- private ProfilerMarker _getEnumerator = new ProfilerMarker("EcsJoinAttachQuery.Execute");
- protected sealed override void OnBuildAfter()
- {
- throw new NotImplementedException();
- // attachPool = World.GetPool();
- }
- public sealed override void Execute()
- {
- using (_getEnumerator.Auto())
- {
- throw new NotImplementedException();
- }
- }
- public EcsGroup.Enumerator GetEnumerator()
- {
- return groupFilter.GetEnumerator();
- }
- }
public abstract class EcsQuery : EcsQueryBase
{
- private ProfilerMarker _getEnumerator = new ProfilerMarker("EcsQuery.Execute");
- protected sealed override void OnBuildAfter() { }
+ private ProfilerMarker _execute = new ProfilerMarker("EcsQuery.Execute");
+ protected sealed override void OnBuild(Builder b) { }
public sealed override void Execute()
{
- using (_getEnumerator.Auto())
+ using (_execute.Auto())
{
var pools = World.GetAllPools();
-
EcsReadonlyGroup all = World.Entities;
groupFilter.Clear();
foreach (var e in all)
@@ -140,14 +95,15 @@ namespace DCFApixels.DragonECS
for (int i = 0, iMax = mask.Inc.Length; i < iMax; i++)
{
if (!pools[mask.Inc[i]].Has(entityID))
- continue;
+ goto next;
}
for (int i = 0, iMax = mask.Exc.Length; i < iMax; i++)
{
if (pools[mask.Exc[i]].Has(entityID))
- continue;
+ goto next;
}
groupFilter.AggressiveAdd(entityID);
+ next: continue;
}
groupFilter.Sort();
}
diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs
index 9c4c122..d5f49ae 100644
--- a/src/EcsWorld.cs
+++ b/src/EcsWorld.cs
@@ -146,7 +146,7 @@ namespace DCFApixels.DragonECS
#endregion
#region Queries
- public TQuery Where(out TQuery query) where TQuery : EcsQueryBase
+ public TQuery Where(out TQuery query) where TQuery : EcsQuery
{
query = Select();
query.Execute();
diff --git a/src/Interfaces/IEcsTable.cs b/src/Interfaces/IEcsTable.cs
index f96956c..e1ef7dd 100644
--- a/src/Interfaces/IEcsTable.cs
+++ b/src/Interfaces/IEcsTable.cs
@@ -19,7 +19,7 @@ namespace DCFApixels.DragonECS
public ReadOnlySpan GetAllPools();
public TQuery Select() where TQuery : EcsQueryBase;
public TQuery Where(out TQuery query) where TQuery : EcsQuery;
- public TQuery Join(out TQuery query) where TQuery : EcsJoinAttachQuery;
+ // public TQuery Join(out TQuery query) where TQuery : EcsJoinQueryBase;
public bool IsMaskCompatible(EcsComponentMask mask, int entityID);
diff --git a/src/Pools/EcsAttachPool.cs b/src/Pools/EcsAttachPool.cs
index 1004520..77c7203 100644
--- a/src/Pools/EcsAttachPool.cs
+++ b/src/Pools/EcsAttachPool.cs
@@ -30,12 +30,11 @@ namespace DCFApixels.DragonECS
protected override void Init(EcsWorld world)
{
_source = world;
+ _poolRunners = new PoolRunners(world.Pipeline);
_entityFlags = new bool[world.Capacity];
_items = new T[world.Capacity];
_count = 0;
-
- _poolRunners = new PoolRunners(world.Pipeline);
}
#endregion
@@ -118,10 +117,22 @@ namespace DCFApixels.DragonECS
}
public static class EcsAttachComponentPoolExt
{
- public static EcsAttachPool GetPool(this EcsWorld self)
- where TAttachComponent : struct, IEcsAttachComponent
+ public static EcsAttachPool GetPool(this EcsWorld self) where TAttachComponent : struct, IEcsAttachComponent
{
return self.GetPool>();
- }
+ }
+
+ public static EcsAttachPool Include(this EcsQueryBuilderBase self) where TAttachComponent : struct, IEcsAttachComponent
+ {
+ return self.Include>();
+ }
+ public static EcsAttachPool Exclude(this EcsQueryBuilderBase self) where TAttachComponent : struct, IEcsAttachComponent
+ {
+ return self.Exclude>();
+ }
+ public static EcsAttachPool Optional(this EcsQueryBuilderBase self) where TAttachComponent : struct, IEcsAttachComponent
+ {
+ return self.Optional>();
+ }
}
}
diff --git a/src/Pools/EcsNotNullPool.cs b/src/Pools/EcsNotNullPool.cs
index d20fc86..b0e7cd0 100644
--- a/src/Pools/EcsNotNullPool.cs
+++ b/src/Pools/EcsNotNullPool.cs
@@ -74,10 +74,22 @@ namespace DCFApixels.DragonECS
public interface INotNullComponent { }
public static class EcsNotNullPoolExt
{
- public static EcsNotNullPool GetPool(this EcsWorld self)
- where TNotNullComponent : struct, INotNullComponent
+ public static EcsNotNullPool GetPool(this EcsWorld self) where TNotNullComponent : struct, INotNullComponent
{
return self.GetPool>();
- }
+ }
+
+ public static EcsNotNullPool Include(this EcsQueryBuilderBase self) where TNotNullComponent : struct, INotNullComponent
+ {
+ return self.Include>();
+ }
+ public static EcsNotNullPool Exclude(this EcsQueryBuilderBase self) where TNotNullComponent : struct, INotNullComponent
+ {
+ return self.Exclude>();
+ }
+ public static EcsNotNullPool Optional(this EcsQueryBuilderBase self) where TNotNullComponent : struct, INotNullComponent
+ {
+ return self.Optional>();
+ }
}
}
diff --git a/src/Pools/EcsPool.cs b/src/Pools/EcsPool.cs
index 3846b98..e1b2b83 100644
--- a/src/Pools/EcsPool.cs
+++ b/src/Pools/EcsPool.cs
@@ -112,7 +112,7 @@ namespace DCFApixels.DragonECS
Array.Resize(ref _items, _items.Length << 1);
}
- _mapping[entityID] = itemIndex;
+ //_mapping[entityID] = itemIndex; TODO
_poolRunners.add.OnComponentAdd(entityID);
}
_poolRunners.write.OnComponentWrite(entityID);
@@ -166,10 +166,22 @@ namespace DCFApixels.DragonECS
public interface IEcsComponent { }
public static class EcsPoolExt
{
- public static EcsPool GetPool(this EcsWorld self)
- where TComponent : struct, IEcsComponent
+ public static EcsPool GetPool(this EcsWorld self) where TComponent : struct, IEcsComponent
{
return self.GetPool>();
- }
+ }
+
+ public static EcsPool Include(this EcsQueryBuilderBase self) where TComponent : struct, IEcsComponent
+ {
+ return self.Include>();
+ }
+ public static EcsPool Exclude(this EcsQueryBuilderBase self) where TComponent : struct, IEcsComponent
+ {
+ return self.Exclude>();
+ }
+ public static EcsPool Optional(this EcsQueryBuilderBase self) where TComponent : struct, IEcsComponent
+ {
+ return self.Optional>();
+ }
}
}
diff --git a/src/Pools/EcsRelationPool.cs b/src/Pools/EcsRelationPool.cs
index 164a3d0..d7d77c3 100644
--- a/src/Pools/EcsRelationPool.cs
+++ b/src/Pools/EcsRelationPool.cs
@@ -31,12 +31,11 @@ namespace DCFApixels.DragonECS
protected override void Init(EcsWorld world)
{
_source = world;
+ _poolRunners = new PoolRunners(world.Pipeline);
_entityFlags = new bool[world.Capacity];
_items = new T[world.Capacity];
_count = 0;
-
- _poolRunners = new PoolRunners(world.Pipeline);
}
#endregion
@@ -125,10 +124,22 @@ namespace DCFApixels.DragonECS
}
public static class EcsRelationPoolExt
{
- public static EcsRelationPool GetPool(this EcsWorld self)
- where TRelationComponent : struct, IEcsRelationComponent
+ public static EcsRelationPool GetPool(this EcsWorld self) where TRelationComponent : struct, IEcsRelationComponent
{
return self.GetPool>();
- }
+ }
+
+ public static EcsRelationPool Include(this EcsQueryBuilderBase self) where TRelationComponent : struct, IEcsRelationComponent
+ {
+ return self.Include>();
+ }
+ public static EcsRelationPool Exclude(this EcsQueryBuilderBase self) where TRelationComponent : struct, IEcsRelationComponent
+ {
+ return self.Exclude>();
+ }
+ public static EcsRelationPool Optional(this EcsQueryBuilderBase self) where TRelationComponent : struct, IEcsRelationComponent
+ {
+ return self.Optional>();
+ }
}
}
diff --git a/src/Pools/EcsSinglePool.cs b/src/Pools/EcsSinglePool.cs
index 3f58361..d2bc247 100644
--- a/src/Pools/EcsSinglePool.cs
+++ b/src/Pools/EcsSinglePool.cs
@@ -100,6 +100,19 @@ namespace DCFApixels.DragonECS
where TSingleComponent : struct, IEcsSingleComponent
{
return self.GetPool>();
- }
+ }
+
+ public static EcsSinglePool Include(this EcsQueryBuilderBase self) where TSingleComponent : struct, IEcsSingleComponent
+ {
+ return self.Include>();
+ }
+ public static EcsSinglePool Exclude(this EcsQueryBuilderBase self) where TSingleComponent : struct, IEcsSingleComponent
+ {
+ return self.Exclude>();
+ }
+ public static EcsSinglePool Optional(this EcsQueryBuilderBase self) where TSingleComponent : struct, IEcsSingleComponent
+ {
+ return self.Optional>();
+ }
}
}
diff --git a/src/Pools/EcsTagPool.cs b/src/Pools/EcsTagPool.cs
index 6e93734..ce6004f 100644
--- a/src/Pools/EcsTagPool.cs
+++ b/src/Pools/EcsTagPool.cs
@@ -77,10 +77,22 @@ namespace DCFApixels.DragonECS
public interface IEcsTagComponent { }
public static class EcsTagPoolExt
{
- public static EcsTagPool GetPool(this EcsWorld self)
- where TTagComponent : struct, IEcsTagComponent
+ public static EcsTagPool GetPool(this EcsWorld self) where TTagComponent : struct, IEcsTagComponent
{
return self.GetPool>();
- }
+ }
+
+ public static EcsTagPool Include(this EcsQueryBuilderBase self) where TTagComponent : struct, IEcsTagComponent
+ {
+ return self.Include>();
+ }
+ public static EcsTagPool Exclude(this EcsQueryBuilderBase self) where TTagComponent : struct, IEcsTagComponent
+ {
+ return self.Exclude>();
+ }
+ public static EcsTagPool Optional(this EcsQueryBuilderBase self) where TTagComponent : struct, IEcsTagComponent
+ {
+ return self.Optional>();
+ }
}
}