mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 01:44:35 +08:00
fix filter fbug
This commit is contained in:
parent
699a64f0b6
commit
e2371103c1
@ -1,30 +0,0 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
/// <summary>
|
||||
/// Используется для реализации отношений. traget - это сущьность к которой крепится эта сущьность. other - это сущьность с которой traget образует связь
|
||||
/// </summary>
|
||||
[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;
|
||||
|
||||
/// <summary>alias for "origin"</summary>
|
||||
public EcsEntity left
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => origin;
|
||||
}
|
||||
/// <summary>alias for "other"</summary>
|
||||
public EcsEntity right
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => other;
|
||||
}
|
||||
}
|
||||
}
|
@ -52,7 +52,7 @@ namespace DCFApixels.DragonECS
|
||||
public void Inject(T obj);
|
||||
}
|
||||
|
||||
[DebugHide, DebugColor(DebugColor.Gray)]
|
||||
[DebugHide, DebugColor(DebugColor.Gray)]
|
||||
public sealed class InjectRunner<T> : EcsRunner<IEcsInject<T>>, IEcsInject<T>
|
||||
{
|
||||
private IEcsPreInject _preInjectchache;
|
||||
|
@ -11,8 +11,8 @@
|
||||
{
|
||||
public EcsDefaultWrold(EcsPipeline pipeline = null) : base(pipeline) { }
|
||||
}
|
||||
public sealed class EcsEventWrold : EcsEdgeWorld<EcsEventWrold>
|
||||
public sealed class EcsEventWrold : EcsWorld<EcsEventWrold>
|
||||
{
|
||||
public EcsEventWrold(EcsWorld firstTarget, EcsWorld secondTarget, EcsPipeline pipeline = null) : base(firstTarget, secondTarget, pipeline) { }
|
||||
public EcsEventWrold(EcsPipeline pipeline = null) : base(pipeline) { }
|
||||
}
|
||||
}
|
||||
|
@ -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<TWorldArchetype> : EcsWorld<TWorldArchetype> where TWorldArchetype : EcsWorld<TWorldArchetype>
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
83
src/EcsJoinQuery.cs
Normal file
83
src/EcsJoinQuery.cs
Normal file
@ -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<TAttachComponent> : EcsJoinQueryBase
|
||||
where TAttachComponent : struct, IEcsAttachComponent
|
||||
{
|
||||
private EcsWorld _targetWorld;
|
||||
private EcsAttachPool<TAttachComponent> _targetPool;
|
||||
|
||||
private ProfilerMarker _execute = new ProfilerMarker("EcsJoinAttachQuery.Execute");
|
||||
protected sealed override void OnBuild(Builder b)
|
||||
{
|
||||
_targetPool = b.Include<TAttachComponent>();
|
||||
}
|
||||
public sealed override void Execute()
|
||||
{
|
||||
using (_execute.Auto())
|
||||
{
|
||||
ExecuteWhere();
|
||||
}
|
||||
}
|
||||
public EcsGroup.Enumerator GetEnumerator()
|
||||
{
|
||||
return groupFilter.GetEnumerator();
|
||||
}
|
||||
}
|
||||
public abstract class EcsJoinRelationQuery<TRelationComponent> : EcsJoinQueryBase
|
||||
where TRelationComponent : struct, IEcsRelationComponent
|
||||
{
|
||||
private EcsWorld _firstWorld;
|
||||
private EcsWorld _secondWorld;
|
||||
private EcsRelationPool<TRelationComponent> _targetPool;
|
||||
|
||||
private ProfilerMarker _execute = new ProfilerMarker("EcsJoinRelationQuery.Execute");
|
||||
protected sealed override void OnBuild(Builder b)
|
||||
{
|
||||
_targetPool = source.GetPool<TRelationComponent>();
|
||||
}
|
||||
public sealed override void Execute()
|
||||
{
|
||||
using (_execute.Auto())
|
||||
{
|
||||
ExecuteWhere();
|
||||
}
|
||||
}
|
||||
public EcsGroup.Enumerator GetEnumerator()
|
||||
{
|
||||
return groupFilter.GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
@ -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<Edge> attachPool;
|
||||
|
||||
private ProfilerMarker _getEnumerator = new ProfilerMarker("EcsJoinAttachQuery.Execute");
|
||||
protected sealed override void OnBuildAfter()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
// attachPool = World.GetPool<Edge>();
|
||||
}
|
||||
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<Edge> attachPool;
|
||||
|
||||
private ProfilerMarker _getEnumerator = new ProfilerMarker("EcsJoinAttachQuery.Execute");
|
||||
protected sealed override void OnBuildAfter()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
// attachPool = World.GetPool<Edge>();
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ namespace DCFApixels.DragonECS
|
||||
#endregion
|
||||
|
||||
#region Queries
|
||||
public TQuery Where<TQuery>(out TQuery query) where TQuery : EcsQueryBase
|
||||
public TQuery Where<TQuery>(out TQuery query) where TQuery : EcsQuery
|
||||
{
|
||||
query = Select<TQuery>();
|
||||
query.Execute();
|
||||
|
@ -19,7 +19,7 @@ namespace DCFApixels.DragonECS
|
||||
public ReadOnlySpan<EcsPoolBase> GetAllPools();
|
||||
public TQuery Select<TQuery>() where TQuery : EcsQueryBase;
|
||||
public TQuery Where<TQuery>(out TQuery query) where TQuery : EcsQuery;
|
||||
public TQuery Join<TQuery>(out TQuery query) where TQuery : EcsJoinAttachQuery;
|
||||
// public TQuery Join<TQuery>(out TQuery query) where TQuery : EcsJoinQueryBase;
|
||||
|
||||
public bool IsMaskCompatible(EcsComponentMask mask, int entityID);
|
||||
|
||||
|
@ -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<TAttachComponent> GetPool<TAttachComponent>(this EcsWorld self)
|
||||
where TAttachComponent : struct, IEcsAttachComponent
|
||||
public static EcsAttachPool<TAttachComponent> GetPool<TAttachComponent>(this EcsWorld self) where TAttachComponent : struct, IEcsAttachComponent
|
||||
{
|
||||
return self.GetPool<TAttachComponent, EcsAttachPool<TAttachComponent>>();
|
||||
}
|
||||
}
|
||||
|
||||
public static EcsAttachPool<TAttachComponent> Include<TAttachComponent>(this EcsQueryBuilderBase self) where TAttachComponent : struct, IEcsAttachComponent
|
||||
{
|
||||
return self.Include<TAttachComponent, EcsAttachPool<TAttachComponent>>();
|
||||
}
|
||||
public static EcsAttachPool<TAttachComponent> Exclude<TAttachComponent>(this EcsQueryBuilderBase self) where TAttachComponent : struct, IEcsAttachComponent
|
||||
{
|
||||
return self.Exclude<TAttachComponent, EcsAttachPool<TAttachComponent>>();
|
||||
}
|
||||
public static EcsAttachPool<TAttachComponent> Optional<TAttachComponent>(this EcsQueryBuilderBase self) where TAttachComponent : struct, IEcsAttachComponent
|
||||
{
|
||||
return self.Optional<TAttachComponent, EcsAttachPool<TAttachComponent>>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -74,10 +74,22 @@ namespace DCFApixels.DragonECS
|
||||
public interface INotNullComponent { }
|
||||
public static class EcsNotNullPoolExt
|
||||
{
|
||||
public static EcsNotNullPool<TNotNullComponent> GetPool<TNotNullComponent>(this EcsWorld self)
|
||||
where TNotNullComponent : struct, INotNullComponent
|
||||
public static EcsNotNullPool<TNotNullComponent> GetPool<TNotNullComponent>(this EcsWorld self) where TNotNullComponent : struct, INotNullComponent
|
||||
{
|
||||
return self.GetPool<TNotNullComponent, EcsNotNullPool<TNotNullComponent>>();
|
||||
}
|
||||
}
|
||||
|
||||
public static EcsNotNullPool<TNotNullComponent> Include<TNotNullComponent>(this EcsQueryBuilderBase self) where TNotNullComponent : struct, INotNullComponent
|
||||
{
|
||||
return self.Include<TNotNullComponent, EcsNotNullPool<TNotNullComponent>>();
|
||||
}
|
||||
public static EcsNotNullPool<TNotNullComponent> Exclude<TNotNullComponent>(this EcsQueryBuilderBase self) where TNotNullComponent : struct, INotNullComponent
|
||||
{
|
||||
return self.Exclude<TNotNullComponent, EcsNotNullPool<TNotNullComponent>>();
|
||||
}
|
||||
public static EcsNotNullPool<TNotNullComponent> Optional<TNotNullComponent>(this EcsQueryBuilderBase self) where TNotNullComponent : struct, INotNullComponent
|
||||
{
|
||||
return self.Optional<TNotNullComponent, EcsNotNullPool<TNotNullComponent>>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ namespace DCFApixels.DragonECS
|
||||
Array.Resize(ref _items, _items.Length << 1);
|
||||
}
|
||||
|
||||
_mapping[entityID] = itemIndex;
|
||||
//_mapping[entityID] = itemIndex; TODO ïðîâåðèòü ÷òî ýòî ëèøíåå äåéñâèå
|
||||
_poolRunners.add.OnComponentAdd<T>(entityID);
|
||||
}
|
||||
_poolRunners.write.OnComponentWrite<T>(entityID);
|
||||
@ -166,10 +166,22 @@ namespace DCFApixels.DragonECS
|
||||
public interface IEcsComponent { }
|
||||
public static class EcsPoolExt
|
||||
{
|
||||
public static EcsPool<TComponent> GetPool<TComponent>(this EcsWorld self)
|
||||
where TComponent : struct, IEcsComponent
|
||||
public static EcsPool<TComponent> GetPool<TComponent>(this EcsWorld self) where TComponent : struct, IEcsComponent
|
||||
{
|
||||
return self.GetPool<TComponent, EcsPool<TComponent>>();
|
||||
}
|
||||
}
|
||||
|
||||
public static EcsPool<TComponent> Include<TComponent>(this EcsQueryBuilderBase self) where TComponent : struct, IEcsComponent
|
||||
{
|
||||
return self.Include<TComponent, EcsPool<TComponent>>();
|
||||
}
|
||||
public static EcsPool<TComponent> Exclude<TComponent>(this EcsQueryBuilderBase self) where TComponent : struct, IEcsComponent
|
||||
{
|
||||
return self.Exclude<TComponent, EcsPool<TComponent>>();
|
||||
}
|
||||
public static EcsPool<TComponent> Optional<TComponent>(this EcsQueryBuilderBase self) where TComponent : struct, IEcsComponent
|
||||
{
|
||||
return self.Optional<TComponent, EcsPool<TComponent>>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<TRelationComponent> GetPool<TRelationComponent>(this EcsWorld self)
|
||||
where TRelationComponent : struct, IEcsRelationComponent
|
||||
public static EcsRelationPool<TRelationComponent> GetPool<TRelationComponent>(this EcsWorld self) where TRelationComponent : struct, IEcsRelationComponent
|
||||
{
|
||||
return self.GetPool<TRelationComponent, EcsRelationPool<TRelationComponent>>();
|
||||
}
|
||||
}
|
||||
|
||||
public static EcsRelationPool<TRelationComponent> Include<TRelationComponent>(this EcsQueryBuilderBase self) where TRelationComponent : struct, IEcsRelationComponent
|
||||
{
|
||||
return self.Include<TRelationComponent, EcsRelationPool<TRelationComponent>>();
|
||||
}
|
||||
public static EcsRelationPool<TRelationComponent> Exclude<TRelationComponent>(this EcsQueryBuilderBase self) where TRelationComponent : struct, IEcsRelationComponent
|
||||
{
|
||||
return self.Exclude<TRelationComponent, EcsRelationPool<TRelationComponent>>();
|
||||
}
|
||||
public static EcsRelationPool<TRelationComponent> Optional<TRelationComponent>(this EcsQueryBuilderBase self) where TRelationComponent : struct, IEcsRelationComponent
|
||||
{
|
||||
return self.Optional<TRelationComponent, EcsRelationPool<TRelationComponent>>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -100,6 +100,19 @@ namespace DCFApixels.DragonECS
|
||||
where TSingleComponent : struct, IEcsSingleComponent
|
||||
{
|
||||
return self.GetPool<TSingleComponent, EcsSinglePool<TSingleComponent>>();
|
||||
}
|
||||
}
|
||||
|
||||
public static EcsSinglePool<TSingleComponent> Include<TSingleComponent>(this EcsQueryBuilderBase self) where TSingleComponent : struct, IEcsSingleComponent
|
||||
{
|
||||
return self.Include<TSingleComponent, EcsSinglePool<TSingleComponent>>();
|
||||
}
|
||||
public static EcsSinglePool<TSingleComponent> Exclude<TSingleComponent>(this EcsQueryBuilderBase self) where TSingleComponent : struct, IEcsSingleComponent
|
||||
{
|
||||
return self.Exclude<TSingleComponent, EcsSinglePool<TSingleComponent>>();
|
||||
}
|
||||
public static EcsSinglePool<TSingleComponent> Optional<TSingleComponent>(this EcsQueryBuilderBase self) where TSingleComponent : struct, IEcsSingleComponent
|
||||
{
|
||||
return self.Optional<TSingleComponent, EcsSinglePool<TSingleComponent>>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -77,10 +77,22 @@ namespace DCFApixels.DragonECS
|
||||
public interface IEcsTagComponent { }
|
||||
public static class EcsTagPoolExt
|
||||
{
|
||||
public static EcsTagPool<TTagComponent> GetPool<TTagComponent>(this EcsWorld self)
|
||||
where TTagComponent : struct, IEcsTagComponent
|
||||
public static EcsTagPool<TTagComponent> GetPool<TTagComponent>(this EcsWorld self) where TTagComponent : struct, IEcsTagComponent
|
||||
{
|
||||
return self.GetPool<TTagComponent, EcsTagPool<TTagComponent>>();
|
||||
}
|
||||
}
|
||||
|
||||
public static EcsTagPool<TTagComponent> Include<TTagComponent>(this EcsQueryBuilderBase self) where TTagComponent : struct, IEcsTagComponent
|
||||
{
|
||||
return self.Include<TTagComponent, EcsTagPool<TTagComponent>>();
|
||||
}
|
||||
public static EcsTagPool<TTagComponent> Exclude<TTagComponent>(this EcsQueryBuilderBase self) where TTagComponent : struct, IEcsTagComponent
|
||||
{
|
||||
return self.Exclude<TTagComponent, EcsTagPool<TTagComponent>>();
|
||||
}
|
||||
public static EcsTagPool<TTagComponent> Optional<TTagComponent>(this EcsQueryBuilderBase self) where TTagComponent : struct, IEcsTagComponent
|
||||
{
|
||||
return self.Optional<TTagComponent, EcsTagPool<TTagComponent>>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user