From 0813a68e04aa18670b050d2a8967b4de809120e5 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Thu, 20 Apr 2023 10:59:55 +0800 Subject: [PATCH] fix changes --- src/Builtin/Worlds.cs | 4 ++-- src/EcsEdgeWorld.cs | 23 +++++++++++++++++++ src/EcsPool.cs | 3 ++- src/EcsQuery.cs | 4 ++-- src/EcsRelationTable.cs | 25 -------------------- src/EcsWorld.cs | 46 +++++++++++++++++++------------------ src/Interfaces/IEcsTable.cs | 11 ++++++--- 7 files changed, 61 insertions(+), 55 deletions(-) create mode 100644 src/EcsEdgeWorld.cs delete mode 100644 src/EcsRelationTable.cs diff --git a/src/Builtin/Worlds.cs b/src/Builtin/Worlds.cs index 157eb73..d060658 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 : EcsWorld + public sealed class EcsEventWrold : EcsEdgeWorld { - public EcsEventWrold(EcsPipeline pipeline = null) : base(pipeline) { } + public EcsEventWrold(IEcsWorld firstTarget, IEcsWorld secondTarget, EcsPipeline pipeline = null) : base(firstTarget, secondTarget, pipeline) { } } } diff --git a/src/EcsEdgeWorld.cs b/src/EcsEdgeWorld.cs new file mode 100644 index 0000000..9e89653 --- /dev/null +++ b/src/EcsEdgeWorld.cs @@ -0,0 +1,23 @@ +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 IEcsWorld _firstTarget; + private IEcsWorld _secondTarget; + public EcsEdgeWorld(IEcsWorld firstTarget, IEcsWorld secondTarget, EcsPipeline pipeline) : base(pipeline) + { + _firstTarget = firstTarget; + _secondTarget = secondTarget; + } + public EcsEdgeWorld(IEcsWorld firstTarget, EcsPipeline pipeline) : base(pipeline) + { + _firstTarget = firstTarget; + } + } +} diff --git a/src/EcsPool.cs b/src/EcsPool.cs index 5040d3e..92c06d0 100644 --- a/src/EcsPool.cs +++ b/src/EcsPool.cs @@ -129,12 +129,13 @@ namespace DCFApixels.DragonECS } _poolRunnres.write.OnComponentWrite(entityID); return ref _items[itemIndex]; - // } + // } } [MethodImpl(MethodImplOptions.AggressiveInlining)] public ref T Write(int entityID) { // using (_writeMark.Auto()) + _poolRunnres.write.OnComponentWrite(entityID); return ref _items[_mapping[entityID]]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/EcsQuery.cs b/src/EcsQuery.cs index b8405c9..67472a6 100644 --- a/src/EcsQuery.cs +++ b/src/EcsQuery.cs @@ -82,7 +82,7 @@ namespace DCFApixels.DragonECS { private EcsPool attachPool; - private ProfilerMarker _getEnumerator = new ProfilerMarker("EcsQuery.Execute"); + private ProfilerMarker _getEnumerator = new ProfilerMarker("EcsQuery.Where"); protected sealed override void OnBuildAfter() { attachPool = World.GetPool(); @@ -102,7 +102,7 @@ namespace DCFApixels.DragonECS public abstract class EcsQuery : EcsQueryBase { - private ProfilerMarker _getEnumerator = new ProfilerMarker("EcsQuery.Execute"); + private ProfilerMarker _getEnumerator = new ProfilerMarker("EcsQuery.Where"); protected sealed override void OnBuildAfter() { } public sealed override void Execute() { diff --git a/src/EcsRelationTable.cs b/src/EcsRelationTable.cs deleted file mode 100644 index 61c0c3a..0000000 --- a/src/EcsRelationTable.cs +++ /dev/null @@ -1,25 +0,0 @@ -using DCFApixels.DragonECS; -using DCFApixels.DragonECS.Internal; -using System; -using System.Collections.Generic; - -namespace DCFApixels.DragonECS -{ - public interface IEcsRealationTable - { - } - internal class EcsRelationWorld : EcsWorld> - where TRelationTableArhetype : EcsRelationTableArchetypeBase { } - public sealed class EcsRelationTable : IEcsRealationTable - where TTableArhetype : EcsRelationTableArchetypeBase - { - public readonly IEcsWorld leftWorld; - public readonly IEcsWorld rightWorld; - - private int[] _relations; //dense - private int[] _leftMapping; - private int[] _rgihtMapping; - - private EcsRelationWorld _relationWorld; - } -} diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index c89b682..ea7ba15 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -1,8 +1,8 @@ -using DCFApixels.DragonECS.Internal; -using System; +using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using UnityEditor.Search; namespace DCFApixels.DragonECS { @@ -11,7 +11,6 @@ namespace DCFApixels.DragonECS #region Properties public int UniqueID { get; } public EcsPipeline Pipeline { get; } - public EcsReadonlyGroup Entities => default; #endregion #region Entities @@ -19,12 +18,6 @@ namespace DCFApixels.DragonECS public void DelEntity(EcsEntity entity); public bool EntityIsAlive(int entityID, short gen); public EcsEntity GetEcsEntity(int entityID); - public void Destroy(); - #endregion - - #region Group - internal EcsGroup GetGroupFromPool(); - internal void ReleaseGroup(EcsGroup group); #endregion } @@ -32,9 +25,7 @@ namespace DCFApixels.DragonECS { public static IEcsWorld[] Worlds = new IEcsWorld[8]; private static IntDispenser _worldIdDispenser = new IntDispenser(0); - public readonly short uniqueID; - protected EcsWorld() { uniqueID = (short)_worldIdDispenser.GetFree(); @@ -42,7 +33,6 @@ namespace DCFApixels.DragonECS Array.Resize(ref Worlds, Worlds.Length << 1); Worlds[uniqueID] = (IEcsWorld)this; } - protected void Realeze() { Worlds[uniqueID] = null; @@ -92,7 +82,7 @@ namespace DCFApixels.DragonECS #endregion #region Constructors - public EcsWorld(EcsPipeline pipline = null) + public EcsWorld(EcsPipeline pipline) { _pipeline = pipline ?? EcsPipeline.Empty; if (!_pipeline.IsInit) pipline.Init(); @@ -104,8 +94,10 @@ namespace DCFApixels.DragonECS _gens = new short[512]; _entitesCapacity = _gens.Length; - _queries = new EcsQuery[QueryType.capacity]; _groups = new List>(); + _allEntites = GetGroupFromPool(); + + _queries = new EcsQuery[QueryType.capacity]; _poolRunnres = new PoolRunnres(_pipeline); _entityCreate = _pipeline.GetRunner(); @@ -113,8 +105,6 @@ namespace DCFApixels.DragonECS _pipeline.GetRunner>().Inject((TWorldArchetype)this); _pipeline.GetRunner>().Inject(this); _pipeline.GetRunner().OnWorldCreate(this); - - _allEntites = GetGroupFromPool(); } #endregion @@ -139,16 +129,28 @@ namespace DCFApixels.DragonECS #endregion #region Query - public TQuery Query(out TQuery query) where TQuery : EcsQueryBase + public TQuery Where(out TQuery query) where TQuery : EcsQueryBase + { + //int uniqueID = QueryType.uniqueID; + //if (_queries.Length < QueryType.capacity) + // Array.Resize(ref _queries, QueryType.capacity); + //if (_queries[uniqueID] == null) + // _queries[uniqueID] = EcsQueryBase.Builder.Build(this); + //query = (TQuery)_queries[uniqueID]; + //query.Where(); + //return query; + query = Select(); + query.Execute(); + return query; + } + public TQuery Select() where TQuery : EcsQueryBase { int uniqueID = QueryType.uniqueID; if (_queries.Length < QueryType.capacity) Array.Resize(ref _queries, QueryType.capacity); if (_queries[uniqueID] == null) _queries[uniqueID] = EcsQueryBase.Builder.Build(this); - query = (TQuery)_queries[uniqueID]; - query.Execute(); - return query; + return (TQuery)_queries[uniqueID]; } #endregion @@ -254,14 +256,14 @@ namespace DCFApixels.DragonECS { _groups.Add(new WeakReference(group)); } - EcsGroup IEcsWorld.GetGroupFromPool() => GetGroupFromPool(); + EcsGroup IEcsTable.GetGroupFromPool() => GetGroupFromPool(); internal EcsGroup GetGroupFromPool() { if (_groupsPool.Count <= 0) return new EcsGroup(this); return _groupsPool.Pop(); } - void IEcsWorld.ReleaseGroup(EcsGroup group) + void IEcsTable.ReleaseGroup(EcsGroup group) { #if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS if (group.World != this) diff --git a/src/Interfaces/IEcsTable.cs b/src/Interfaces/IEcsTable.cs index 552921a..d0c5e5f 100644 --- a/src/Interfaces/IEcsTable.cs +++ b/src/Interfaces/IEcsTable.cs @@ -10,26 +10,31 @@ namespace DCFApixels.DragonECS public Type ArchetypeType { get; } public int Count { get; } public int Capacity { get; } + public EcsReadonlyGroup Entities => default; #endregion #region Methods + public int GetComponentID(); public EcsPool GetPool() where T : struct; public ReadOnlySpan GetAllPools(); - public TQuery Query(out TQuery query) where TQuery : EcsQueryBase; + public TQuery Where(out TQuery query) where TQuery : EcsQueryBase; + public TQuery Select() where TQuery : EcsQueryBase; - public int GetComponentID(); public bool IsMaskCompatible(int entityID) where TInc : struct, IInc where TExc : struct, IExc; public bool IsMaskCompatible(EcsComponentMask mask, int entityID); + + public void Destroy(); #endregion #region Internal Methods internal void RegisterGroup(EcsGroup group); + internal EcsGroup GetGroupFromPool(); + internal void ReleaseGroup(EcsGroup group); #endregion } public static class IEcsReadonlyTableExtensions { - [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsMaskCompatible(this IEcsTable self, int entityID) where TInc : struct, IInc { return self.IsMaskCompatible(entityID);