From fb19bdf0d566846c3b6e8a32d22172e7227fc3eb Mon Sep 17 00:00:00 2001 From: DCFApixels <99481254+DCFApixels@users.noreply.github.com> Date: Mon, 10 Mar 2025 13:07:23 +0800 Subject: [PATCH] update/fixs --- src/Builtin/EcsGraphWorld.cs | 13 ++++++++++-- src/EntityGraph.cs | 27 ++++++++++++++++++++++++- src/Executors/JoinToSubGraphExecutor.cs | 19 +++++++++-------- src/Utils/RelInfo.cs | 13 +++++++++++- 4 files changed, 60 insertions(+), 12 deletions(-) diff --git a/src/Builtin/EcsGraphWorld.cs b/src/Builtin/EcsGraphWorld.cs index 9c255bd..829c450 100644 --- a/src/Builtin/EcsGraphWorld.cs +++ b/src/Builtin/EcsGraphWorld.cs @@ -8,11 +8,20 @@ namespace DCFApixels.DragonECS [MetaDescription(EcsConsts.AUTHOR, "Inherits EcsWorld without extending its functionality and is used for specific injections. Can be used as argument to EcsWorld.CreateGraph(new " + nameof(EcsGraphWorld) + "()) and to store relation entity.")] [DebuggerTypeProxy(typeof(DebuggerProxy))] [MetaID("ECC4CF479301897718600925B00A7DB4")] - public sealed class EcsGraphWorld : EcsWorld, IInjectionUnit + public sealed class EcsGraphWorld : EcsWorld, IInjectionUnit, IInjectionBlock { public EcsGraphWorld() : base() { } public EcsGraphWorld(EcsWorldConfig config = null, string name = null, short worldID = -1) : base(config, name == null ? "Default" : name, worldID) { } public EcsGraphWorld(IConfigContainer configs, string name = null, short worldID = -1) : base(configs, name == null ? "Default" : name, worldID) { } - void IInjectionUnit.InitInjectionNode(InjectionGraph nodes) { nodes.AddNode(this); } + + void IInjectionUnit.InitInjectionNode(InjectionGraph nodes) + { + nodes.AddNode(this); + nodes.AddNode(); + } + public void InjectTo(Injector inj) + { + inj.Inject(this.GetGraph()); + } } } \ No newline at end of file diff --git a/src/EntityGraph.cs b/src/EntityGraph.cs index 55a8f7b..d314d22 100644 --- a/src/EntityGraph.cs +++ b/src/EntityGraph.cs @@ -1,4 +1,5 @@ -using DCFApixels.DragonECS.Graphs.Internal; +using DCFApixels.DragonECS.Core; +using DCFApixels.DragonECS.Graphs.Internal; using System; using System.Runtime.CompilerServices; @@ -163,6 +164,14 @@ namespace DCFApixels.DragonECS #region GetRelInfo [MethodImpl(MethodImplOptions.AggressiveInlining)] + public int GetRelationOpposite(int relEntityID, int nodeEntityID) + { +#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS + if (relEntityID <= 0 || relEntityID >= _relEntityInfos.Length) { Throw.UndefinedException(); } +#endif + return new StartEnd(_relEntityInfos[relEntityID]).GetOpposite(nodeEntityID); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public StartEnd GetRelationStartEnd(int relEntityID) { #if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS @@ -171,6 +180,22 @@ namespace DCFApixels.DragonECS return new StartEnd(_relEntityInfos[relEntityID]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool IsRelationStart(int relEntityID, int nodeEntityID) + { +#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS + if (relEntityID <= 0 || relEntityID >= _relEntityInfos.Length) { Throw.UndefinedException(); } +#endif + return _relEntityInfos[relEntityID].start == nodeEntityID; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public bool IsRelationEnd(int relEntityID, int nodeEntityID) + { +#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS + if (relEntityID <= 0 || relEntityID >= _relEntityInfos.Length) { Throw.UndefinedException(); } +#endif + return _relEntityInfos[relEntityID].end == nodeEntityID; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public int GetRelationStart(int relEntityID) { #if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS diff --git a/src/Executors/JoinToSubGraphExecutor.cs b/src/Executors/JoinToSubGraphExecutor.cs index 35059a1..a0bf18e 100644 --- a/src/Executors/JoinToSubGraphExecutor.cs +++ b/src/Executors/JoinToSubGraphExecutor.cs @@ -1,5 +1,4 @@ using DCFApixels.DragonECS.Graphs.Internal; -using DCFApixels.DragonECS.UncheckedCore; using System; using System.Collections.Generic; using System.Diagnostics; @@ -18,8 +17,8 @@ namespace DCFApixels.DragonECS.Graphs.Internal private LinkedList _linkedList; private LinkedListHead[] _linkedListSourceHeads; - private int[] _sourceEntities; - private int _sourceEntitiesCount; + //заменить на спарссет без пейджей + private EcsGroup _sourceEntities; private int _targetWorldCapacity = -1; //private EcsProfilerMarker _executeMarker = new EcsProfilerMarker("Join"); @@ -45,9 +44,9 @@ namespace DCFApixels.DragonECS.Graphs.Internal _graphWorld = world; _linkedList = new OnlyAppendHeadLinkedList(_graphWorld.Capacity); _linkedListSourceHeads = new LinkedListHead[_graphWorld.Capacity]; - _sourceEntities = new int[_graphWorld.Capacity * 2]; _graphWorld.AddListener(this); _graph = _graphWorld.GetGraph(); + _sourceEntities = EcsGroup.New(_graph.World); } public void Destroy() { @@ -76,12 +75,14 @@ namespace DCFApixels.DragonECS.Graphs.Internal else { //ArrayUtility.Fill(_linkedListSourceHeads, default); //TODO оптимизировать, сделав не полную отчистку а только по элементов с прошлого раза - for (int i = 0; i < _sourceEntitiesCount; i++) + //for (int i = 0; i < _sourceEntitiesCount; i++) + for (int i = 0; i < _sourceEntities.Count; i++) { _linkedListSourceHeads[_sourceEntities[i]] = default; } } - _sourceEntitiesCount = 0; + //_sourceEntitiesCount = 0; + _sourceEntities.Clear(); _linkedList.Clear(); //Заполнение массивов @@ -125,10 +126,11 @@ namespace DCFApixels.DragonECS.Graphs.Internal { return; } + _sourceEntities.Add(sourceEntityID); ref var basket = ref _linkedListSourceHeads[sourceEntityID]; + //EcsDebug.Print("e" + sourceEntityID); if (basket.head == 0) { - _sourceEntities[_sourceEntitiesCount++] = sourceEntityID; basket.head = _linkedList.NewHead(relationEntityID); } else @@ -188,7 +190,8 @@ namespace DCFApixels.DragonECS.Graphs.Internal #region GetEntites internal EcsSpan GetNodeEntities() { - return UncheckedCoreUtility.CreateSpan(_graph.World.ID, _sourceEntities, _sourceEntitiesCount); + //return UncheckedCoreUtility.CreateSpan(_graph.World.ID, _sourceEntities, _sourceEntitiesCount); + return _sourceEntities.ToSpan(); } #endregion } diff --git a/src/Utils/RelInfo.cs b/src/Utils/RelInfo.cs index 92b2e36..387f7ec 100644 --- a/src/Utils/RelInfo.cs +++ b/src/Utils/RelInfo.cs @@ -55,12 +55,23 @@ namespace DCFApixels.DragonECS public static bool operator !=(StartEnd a, StartEnd b) { return a.start != b.start || a.end != b.end; } #endregion + #region Methods + public int GetOpposite(int entityID) + { +#if DEBUG + if (entityID != start && entityID != end) { Throw.UndefinedException(); } +#endif + //return entityID > end ? end : start; + return entityID == end ? start : end; + } + #endregion + #region Other public override int GetHashCode() { throw new NotSupportedException(); } public override bool Equals(object obj) { throw new NotSupportedException(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(StartEnd other) { return this == other; } - public override string ToString() { return $"arc({start} -> {end})"; } + public override string ToString() { return $"rel({start} -> {end})"; } #endregion } } \ No newline at end of file