update/fixs

This commit is contained in:
DCFApixels 2025-03-10 13:07:23 +08:00
parent df01e1cb81
commit fb19bdf0d5
4 changed files with 60 additions and 12 deletions

View File

@ -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.")] [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))] [DebuggerTypeProxy(typeof(DebuggerProxy))]
[MetaID("ECC4CF479301897718600925B00A7DB4")] [MetaID("ECC4CF479301897718600925B00A7DB4")]
public sealed class EcsGraphWorld : EcsWorld, IInjectionUnit public sealed class EcsGraphWorld : EcsWorld, IInjectionUnit, IInjectionBlock
{ {
public EcsGraphWorld() : base() { } public EcsGraphWorld() : base() { }
public EcsGraphWorld(EcsWorldConfig config = null, string name = null, short worldID = -1) : base(config, name == null ? "Default" : name, worldID) { } 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) { } 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<EntityGraph>();
}
public void InjectTo(Injector inj)
{
inj.Inject(this.GetGraph());
}
} }
} }

View File

@ -1,4 +1,5 @@
using DCFApixels.DragonECS.Graphs.Internal; using DCFApixels.DragonECS.Core;
using DCFApixels.DragonECS.Graphs.Internal;
using System; using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
@ -163,6 +164,14 @@ namespace DCFApixels.DragonECS
#region GetRelInfo #region GetRelInfo
[MethodImpl(MethodImplOptions.AggressiveInlining)] [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) public StartEnd GetRelationStartEnd(int relEntityID)
{ {
#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS #if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS
@ -171,6 +180,22 @@ namespace DCFApixels.DragonECS
return new StartEnd(_relEntityInfos[relEntityID]); return new StartEnd(_relEntityInfos[relEntityID]);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [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) public int GetRelationStart(int relEntityID)
{ {
#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS #if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS

View File

@ -1,5 +1,4 @@
using DCFApixels.DragonECS.Graphs.Internal; using DCFApixels.DragonECS.Graphs.Internal;
using DCFApixels.DragonECS.UncheckedCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
@ -18,8 +17,8 @@ namespace DCFApixels.DragonECS.Graphs.Internal
private LinkedList _linkedList; private LinkedList _linkedList;
private LinkedListHead[] _linkedListSourceHeads; private LinkedListHead[] _linkedListSourceHeads;
private int[] _sourceEntities; //заменить на спарссет без пейджей
private int _sourceEntitiesCount; private EcsGroup _sourceEntities;
private int _targetWorldCapacity = -1; private int _targetWorldCapacity = -1;
//private EcsProfilerMarker _executeMarker = new EcsProfilerMarker("Join"); //private EcsProfilerMarker _executeMarker = new EcsProfilerMarker("Join");
@ -45,9 +44,9 @@ namespace DCFApixels.DragonECS.Graphs.Internal
_graphWorld = world; _graphWorld = world;
_linkedList = new OnlyAppendHeadLinkedList(_graphWorld.Capacity); _linkedList = new OnlyAppendHeadLinkedList(_graphWorld.Capacity);
_linkedListSourceHeads = new LinkedListHead[_graphWorld.Capacity]; _linkedListSourceHeads = new LinkedListHead[_graphWorld.Capacity];
_sourceEntities = new int[_graphWorld.Capacity * 2];
_graphWorld.AddListener(this); _graphWorld.AddListener(this);
_graph = _graphWorld.GetGraph(); _graph = _graphWorld.GetGraph();
_sourceEntities = EcsGroup.New(_graph.World);
} }
public void Destroy() public void Destroy()
{ {
@ -76,12 +75,14 @@ namespace DCFApixels.DragonECS.Graphs.Internal
else else
{ {
//ArrayUtility.Fill(_linkedListSourceHeads, default); //TODO оптимизировать, сделав не полную отчистку а только по элементов с прошлого раза //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; _linkedListSourceHeads[_sourceEntities[i]] = default;
} }
} }
_sourceEntitiesCount = 0; //_sourceEntitiesCount = 0;
_sourceEntities.Clear();
_linkedList.Clear(); _linkedList.Clear();
//Заполнение массивов //Заполнение массивов
@ -125,10 +126,11 @@ namespace DCFApixels.DragonECS.Graphs.Internal
{ {
return; return;
} }
_sourceEntities.Add(sourceEntityID);
ref var basket = ref _linkedListSourceHeads[sourceEntityID]; ref var basket = ref _linkedListSourceHeads[sourceEntityID];
//EcsDebug.Print("e" + sourceEntityID);
if (basket.head == 0) if (basket.head == 0)
{ {
_sourceEntities[_sourceEntitiesCount++] = sourceEntityID;
basket.head = _linkedList.NewHead(relationEntityID); basket.head = _linkedList.NewHead(relationEntityID);
} }
else else
@ -188,7 +190,8 @@ namespace DCFApixels.DragonECS.Graphs.Internal
#region GetEntites #region GetEntites
internal EcsSpan GetNodeEntities() internal EcsSpan GetNodeEntities()
{ {
return UncheckedCoreUtility.CreateSpan(_graph.World.ID, _sourceEntities, _sourceEntitiesCount); //return UncheckedCoreUtility.CreateSpan(_graph.World.ID, _sourceEntities, _sourceEntitiesCount);
return _sourceEntities.ToSpan();
} }
#endregion #endregion
} }

View File

@ -55,12 +55,23 @@ namespace DCFApixels.DragonECS
public static bool operator !=(StartEnd a, StartEnd b) { return a.start != b.start || a.end != b.end; } public static bool operator !=(StartEnd a, StartEnd b) { return a.start != b.start || a.end != b.end; }
#endregion #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 #region Other
public override int GetHashCode() { throw new NotSupportedException(); } public override int GetHashCode() { throw new NotSupportedException(); }
public override bool Equals(object obj) { throw new NotSupportedException(); } public override bool Equals(object obj) { throw new NotSupportedException(); }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool Equals(StartEnd other) { return this == other; } 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 #endregion
} }
} }