mirror of
https://github.com/DCFApixels/DragonECS-Graphs.git
synced 2025-09-18 03:34:35 +08:00
Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
e2a6fd1c6b | ||
![]() |
c8c8337393 | ||
![]() |
21b891b44c | ||
![]() |
aff9c033d1 | ||
![]() |
516da428dd | ||
![]() |
741d2f6ebd | ||
![]() |
bcefb63aa3 | ||
![]() |
e2dcd8a402 | ||
![]() |
d15fe38b50 | ||
![]() |
f491884c37 | ||
![]() |
fb19bdf0d5 | ||
![]() |
df01e1cb81 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -35,6 +35,7 @@ ExportedObj/
|
||||
*.csproj
|
||||
*.unityproj
|
||||
*.sln
|
||||
*.sln.meta
|
||||
*.suo
|
||||
*.tmp
|
||||
*.user
|
||||
|
@ -8,7 +8,7 @@
|
||||
"displayName": "DragonECS-Graphs",
|
||||
"description": "Entity Graphs for DragonECS",
|
||||
"unity": "2020.3",
|
||||
"version": "0.3.2",
|
||||
"version": "0.3.5",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/DCFApixels/DragonECS-Graphs.git"
|
||||
|
@ -7,12 +7,21 @@ namespace DCFApixels.DragonECS
|
||||
[MetaGroup(EcsConsts.PACK_GROUP, EcsConsts.WORLDS_GROUP)]
|
||||
[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
|
||||
[MetaID("DragonECS_ECC4CF479301897718600925B00A7DB4")]
|
||||
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); }
|
||||
private const string DEFAULT_NAME = "Graph";
|
||||
public EcsGraphWorld() : base(default(EcsWorldConfig), DEFAULT_NAME) { }
|
||||
public EcsGraphWorld(EcsWorldConfig config = null, string name = null, short worldID = -1) : base(config, name == null ? DEFAULT_NAME : name, worldID) { }
|
||||
public EcsGraphWorld(IConfigContainer configs, string name = null, short worldID = -1) : base(configs, name == null ? DEFAULT_NAME : name, worldID) { }
|
||||
void IInjectionUnit.InitInjectionNode(InjectionGraph nodes)
|
||||
{
|
||||
nodes.AddNode(this);
|
||||
nodes.AddNode<EntityGraph>();
|
||||
}
|
||||
public void InjectTo(Injector inj)
|
||||
{
|
||||
inj.Inject(this.GetGraph());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,8 @@
|
||||
using DCFApixels.DragonECS.Graphs.Internal;
|
||||
#if DISABLE_DEBUG
|
||||
#undef DEBUG
|
||||
#endif
|
||||
using DCFApixels.DragonECS.Core;
|
||||
using DCFApixels.DragonECS.Graphs.Internal;
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
@ -84,14 +88,32 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
if (_matrix.TryGetValue(startEntityID, endEntityID, out int relEntityID))
|
||||
{
|
||||
#if DEBUG && DRAGONECS_DEEP_DEBUG
|
||||
if(_graphWorld.IsUsed(relEntityID) == false)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
var (s, e) = GetRelationStartEnd(relEntityID);
|
||||
if (s != startEntityID || e != endEntityID)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
#endif
|
||||
return relEntityID;
|
||||
}
|
||||
return NewRelationInternal(startEntityID, endEntityID);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int GetOrNewRelationNoDirection(int entityID, int otherEntityID)
|
||||
{
|
||||
return GetOrNewRelation(
|
||||
entityID < otherEntityID ? entityID : otherEntityID,
|
||||
entityID > otherEntityID ? entityID : otherEntityID);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int GetOrNewInverseRelation(int relEntityID)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS
|
||||
#if DEBUG || !DISABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (relEntityID <= 0 || relEntityID >= _relEntityInfos.Length) { Throw.UndefinedException(); }
|
||||
#endif
|
||||
var info = _relEntityInfos[relEntityID];
|
||||
@ -102,6 +124,15 @@ namespace DCFApixels.DragonECS
|
||||
private int NewRelationInternal(int startEntityID, int endEntityID)
|
||||
{
|
||||
int relEntityID = _graphWorld.NewEntity();
|
||||
|
||||
#if DEBUG && DRAGONECS_DEEP_DEBUG
|
||||
var (s, e) = GetRelationStartEnd(relEntityID);
|
||||
if (s != 0 || e != 0)
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
#endif
|
||||
|
||||
_matrix.Add(startEntityID, endEntityID, relEntityID);
|
||||
_relEntityInfos[relEntityID] = new RelationInfo(startEntityID, endEntityID);
|
||||
_count++;
|
||||
@ -133,7 +164,7 @@ namespace DCFApixels.DragonECS
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool TryGetInverseRelation(int relEntityID, out int inverseRelEntityID)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS
|
||||
#if DEBUG || !DISABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (relEntityID <= 0 || relEntityID >= _relEntityInfos.Length) { Throw.UndefinedException(); }
|
||||
#endif
|
||||
var info = _relEntityInfos[relEntityID];
|
||||
@ -163,17 +194,41 @@ namespace DCFApixels.DragonECS
|
||||
|
||||
#region GetRelInfo
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int GetRelationOpposite(int relEntityID, int nodeEntityID)
|
||||
{
|
||||
#if 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
|
||||
#if DEBUG || !DISABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (relEntityID <= 0 || relEntityID >= _relEntityInfos.Length) { Throw.UndefinedException(); }
|
||||
#endif
|
||||
return new StartEnd(_relEntityInfos[relEntityID]);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool IsRelationStart(int relEntityID, int nodeEntityID)
|
||||
{
|
||||
#if 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_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
|
||||
#if DEBUG || !DISABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (relEntityID <= 0 || relEntityID >= _relEntityInfos.Length) { Throw.UndefinedException(); }
|
||||
#endif
|
||||
return _relEntityInfos[relEntityID].start;
|
||||
@ -181,7 +236,7 @@ namespace DCFApixels.DragonECS
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int GetRelationEnd(int relEntityID)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS
|
||||
#if DEBUG || !DISABLE_DRAGONECS_ASSERT_CHEKS
|
||||
if (relEntityID <= 0 || relEntityID >= _relEntityInfos.Length) { Throw.UndefinedException(); }
|
||||
#endif
|
||||
return _relEntityInfos[relEntityID].end;
|
||||
|
@ -1,4 +1,7 @@
|
||||
using DCFApixels.DragonECS.Graphs.Internal;
|
||||
#if DISABLE_DEBUG
|
||||
#undef DEBUG
|
||||
#endif
|
||||
using DCFApixels.DragonECS.Graphs.Internal;
|
||||
using System;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
|
@ -1,4 +1,8 @@
|
||||
using DCFApixels.DragonECS.Graphs.Internal;
|
||||
#if DISABLE_DEBUG
|
||||
#undef DEBUG
|
||||
#endif
|
||||
using DCFApixels.DragonECS.Core;
|
||||
using DCFApixels.DragonECS.Graphs.Internal;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
|
@ -1,5 +1,7 @@
|
||||
using DCFApixels.DragonECS.Graphs.Internal;
|
||||
using DCFApixels.DragonECS.UncheckedCore;
|
||||
#if DISABLE_DEBUG
|
||||
#undef DEBUG
|
||||
#endif
|
||||
using DCFApixels.DragonECS.Graphs.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@ -13,13 +15,13 @@ namespace DCFApixels.DragonECS.Graphs.Internal
|
||||
private EcsWorld _graphWorld;
|
||||
private EntityGraph _graph;
|
||||
|
||||
private long _version;
|
||||
private long _version = 0;
|
||||
|
||||
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 +47,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()
|
||||
{
|
||||
@ -62,7 +64,7 @@ namespace DCFApixels.DragonECS.Graphs.Internal
|
||||
private SubGraphMap ExecuteFor_Internal(EcsSpan span, JoinMode mode)
|
||||
{
|
||||
//_executeMarker.Begin();
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
#if DEBUG || DRAGONECS_STABILITY_MODE
|
||||
if (span.IsNull) { /*_executeMarker.End();*/ Throw.ArgumentNull(nameof(span)); }
|
||||
if (span.WorldID != _graphWorld.ID) { /*_executeMarker.End();*/ Throw.Quiery_ArgumentDifferentWorldsException(); }
|
||||
#endif
|
||||
@ -76,12 +78,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 +129,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 +193,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
|
||||
}
|
||||
|
@ -1,4 +1,7 @@
|
||||
using System;
|
||||
#if DISABLE_DEBUG
|
||||
#undef DEBUG
|
||||
#endif
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
|
@ -1,4 +1,7 @@
|
||||
namespace DCFApixels.DragonECS.Graphs.Internal
|
||||
#if DISABLE_DEBUG
|
||||
#undef DEBUG
|
||||
#endif
|
||||
namespace DCFApixels.DragonECS.Graphs.Internal
|
||||
{
|
||||
internal static unsafe class IntHash
|
||||
{
|
||||
|
@ -1,4 +1,7 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
#if DISABLE_DEBUG
|
||||
#undef DEBUG
|
||||
#endif
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace DCFApixels.DragonECS.Graphs.Internal
|
||||
|
@ -1,4 +1,7 @@
|
||||
using System;
|
||||
#if DISABLE_DEBUG
|
||||
#undef DEBUG
|
||||
#endif
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
|
@ -1,4 +1,7 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
#if DISABLE_DEBUG
|
||||
#undef DEBUG
|
||||
#endif
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using TValue = System.Int32;
|
||||
|
||||
|
@ -1,4 +1,7 @@
|
||||
using System;
|
||||
#if DISABLE_DEBUG
|
||||
#undef DEBUG
|
||||
#endif
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
|
@ -1,4 +1,7 @@
|
||||
using System;
|
||||
#if DISABLE_DEBUG
|
||||
#undef DEBUG
|
||||
#endif
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
|
@ -1,4 +1,7 @@
|
||||
using DCFApixels.DragonECS.Graphs.Internal;
|
||||
#if DISABLE_DEBUG
|
||||
#undef DEBUG
|
||||
#endif
|
||||
using DCFApixels.DragonECS.Graphs.Internal;
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
@ -55,12 +58,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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user