mirror of
https://github.com/DCFApixels/DragonECS-Graphs.git
synced 2025-09-18 11:54:35 +08:00
stash
This commit is contained in:
parent
2473c5dc78
commit
653a798af7
@ -153,23 +153,25 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Add/Del
|
#region Add/Del
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public void Add(int startEntityID, int endEntityID, int relEntityID)
|
||||||
|
{
|
||||||
|
_relNodesMapping[relEntityID] = new RelNodesInfo(
|
||||||
|
_startBaskets.AddToBasket(startEntityID, relEntityID),
|
||||||
|
_endBaskets.AddToBasket(endEntityID, relEntityID));
|
||||||
|
}
|
||||||
public void Add(int relEntityID)
|
public void Add(int relEntityID)
|
||||||
{
|
{
|
||||||
var (startEntityID, endEntityID) = _source.GetRelationInfo(relEntityID);
|
var (startEntityID, endEntityID) = _source.GetRelationInfo(relEntityID);
|
||||||
ref RelNodesInfo arcInfo = ref _relNodesMapping[relEntityID];
|
_relNodesMapping[relEntityID] = new RelNodesInfo(
|
||||||
|
_startBaskets.AddToBasket(startEntityID, relEntityID),
|
||||||
arcInfo.startNodeIndex = _startBaskets.AddToBasket(startEntityID, relEntityID);
|
_endBaskets.AddToBasket(endEntityID, relEntityID));
|
||||||
arcInfo.endNodeIndex = _endBaskets.AddToBasket(endEntityID, relEntityID);
|
|
||||||
}
|
}
|
||||||
public void Del(int relEntityID)
|
public void Del(int relEntityID)
|
||||||
{
|
{
|
||||||
var (startEntityID, endEntityID) = _source.GetRelationInfo(relEntityID);
|
var (startEntityID, _) = _source.GetRelationInfo(relEntityID);
|
||||||
ref RelNodesInfo relInfo = ref _relNodesMapping[relEntityID];
|
ref RelNodesInfo relInfo = ref _relNodesMapping[relEntityID];
|
||||||
_startBaskets.RemoveFromBasket(startEntityID, relInfo.startNodeIndex);
|
_startBaskets.RemoveFromBasket(startEntityID, relInfo.startNodeIndex);
|
||||||
if (!_isLoop)
|
|
||||||
{
|
|
||||||
//_startBaskets.RemoveFromBasket(endEntityID, relInfo.endNodeIndex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
public void DelStart(int startEntityID)
|
public void DelStart(int startEntityID)
|
||||||
{
|
{
|
||||||
@ -315,11 +317,16 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ArcInfo
|
#region ArcInfo
|
||||||
private struct RelNodesInfo : IEquatable<RelNodesInfo>
|
private readonly struct RelNodesInfo : IEquatable<RelNodesInfo>
|
||||||
{
|
{
|
||||||
public readonly static RelNodesInfo Empty = default;
|
public readonly static RelNodesInfo Empty = default;
|
||||||
public int startNodeIndex;
|
public readonly int startNodeIndex;
|
||||||
public int endNodeIndex;
|
public readonly int endNodeIndex;
|
||||||
|
public RelNodesInfo(int startNodeIndex, int endNodeIndex)
|
||||||
|
{
|
||||||
|
this.startNodeIndex = startNodeIndex;
|
||||||
|
this.endNodeIndex = endNodeIndex;
|
||||||
|
}
|
||||||
|
|
||||||
#region Object
|
#region Object
|
||||||
public override bool Equals(object obj)
|
public override bool Equals(object obj)
|
||||||
|
@ -124,72 +124,24 @@ namespace DCFApixels.DragonECS
|
|||||||
#region New/Del
|
#region New/Del
|
||||||
public int NewRelation(int startEntityID, int endEntityID)
|
public int NewRelation(int startEntityID, int endEntityID)
|
||||||
{
|
{
|
||||||
//if (HasRelation(startEntityID, endEntityID))
|
|
||||||
//{
|
|
||||||
// Throw.RelationAlreadyExists();
|
|
||||||
//}
|
|
||||||
|
|
||||||
int relEntity = _arcWorld.NewEntity();
|
int relEntity = _arcWorld.NewEntity();
|
||||||
//_relationsMatrix.Add(startEntityID, endEntityID, relEntity);
|
|
||||||
|
|
||||||
_relEntityInfos[relEntity] = new RelEntityInfo(startEntityID, endEntityID);
|
_relEntityInfos[relEntity] = new RelEntityInfo(startEntityID, endEntityID);
|
||||||
_relEntities.Add(relEntity);
|
_relEntities.AddUnchecked(relEntity);
|
||||||
_entitiesGraph.Add(relEntity);
|
_entitiesGraph.Add(startEntityID, endEntityID, relEntity);
|
||||||
return relEntity;
|
return relEntity;
|
||||||
}
|
}
|
||||||
//public void DelRelation(int startEntityID, int endEntityID)
|
|
||||||
//{
|
|
||||||
// if (_relationsMatrix.TryGetValue(startEntityID, endEntityID, out int relEntityID))
|
|
||||||
// {
|
|
||||||
// _arcWorld.DelEntity(relEntityID);
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// Throw.UndefinedRelationException();
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
public void DelRelation(int relEntityID)
|
public void DelRelation(int relEntityID)
|
||||||
{
|
{
|
||||||
_arcWorld.DelEntity(relEntityID);
|
_arcWorld.DelEntity(relEntityID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClearRelation_Internal(int relEntityID)
|
private void ClearRelation_Internal(int relEntityID)
|
||||||
{
|
{
|
||||||
_relEntities.Remove(relEntityID);
|
_relEntities.Remove(relEntityID);
|
||||||
_entitiesGraph.Del(relEntityID);
|
_entitiesGraph.Del(relEntityID);
|
||||||
_relEntityInfos[relEntityID] = RelEntityInfo.Empty;
|
_relEntityInfos[relEntityID] = RelEntityInfo.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
//private void ClearRelation_Internal(int startEntityID, int endEntityID)
|
|
||||||
//{
|
|
||||||
// if (_relationsMatrix.TryGetValue(startEntityID, endEntityID, out int relEntityID))
|
|
||||||
// {
|
|
||||||
// _relEntities.Remove(relEntityID);
|
|
||||||
// _entitiesGraph.Del(relEntityID);
|
|
||||||
// _relationsMatrix.Remove(startEntityID, endEntityID);
|
|
||||||
// _relEntityInfos[relEntityID] = RelEntityInfo.Empty;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region GetRelation/HasRelation
|
|
||||||
//public bool HasRelation(int startEntityID, int endEntityID)
|
|
||||||
//{
|
|
||||||
// return _relationsMatrix.Contains(startEntityID, endEntityID);
|
|
||||||
//}
|
|
||||||
//public int GetRelation(int startEntityID, int endEntityID)
|
|
||||||
//{
|
|
||||||
// if (!_relationsMatrix.TryGetValue(startEntityID, endEntityID, out int relEntityID))
|
|
||||||
// {
|
|
||||||
// Throw.UndefinedRelationException();
|
|
||||||
// }
|
|
||||||
// return relEntityID;
|
|
||||||
//}
|
|
||||||
//public bool TryGetRelation(int startEntityID, int endEntityID, out int relEntityID)
|
|
||||||
//{
|
|
||||||
// return _relationsMatrix.TryGetValue(startEntityID, endEntityID, out relEntityID);
|
|
||||||
//}
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ArcEntityInfo
|
#region ArcEntityInfo
|
||||||
@ -221,19 +173,6 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return GetRelationInfo(relEntityID).end;
|
return GetRelationInfo(relEntityID).end;
|
||||||
}
|
}
|
||||||
|
|
||||||
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
//public int GetInversedRelation(int relEntityID)
|
|
||||||
//{
|
|
||||||
// var (startEntityID, endEntityID) = GetRelationInfo(relEntityID);
|
|
||||||
// return GetRelation(endEntityID, startEntityID);
|
|
||||||
//}
|
|
||||||
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
//public bool TryGetInversedRelation(int relEntityID, out int inversedRelEntityID)
|
|
||||||
//{
|
|
||||||
// var (startEntityID, endEntityID) = GetRelationInfo(relEntityID);
|
|
||||||
// return TryGetRelation(endEntityID, startEntityID, out inversedRelEntityID);
|
|
||||||
//}
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Other
|
#region Other
|
||||||
|
@ -119,18 +119,18 @@ namespace DCFApixels.DragonECS
|
|||||||
int newNodeIndex = TakeRecycledNode();
|
int newNodeIndex = TakeRecycledNode();
|
||||||
if (basketInfo.count == 0)
|
if (basketInfo.count == 0)
|
||||||
{
|
{
|
||||||
basketInfo.nodeIndex = newNodeIndex;
|
//_nodes[newNodeIndex].Set(value, 0, 0);
|
||||||
_nodes[newNodeIndex].Set(value, 0, 0);
|
_nodes[newNodeIndex].value = value;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int nodeIndex = basketInfo.nodeIndex;
|
// int nextNodeIndex = basketInfo.nodeIndex;
|
||||||
ref Node nextNode = ref _nodes[nodeIndex];
|
// //_nodes[newNodeIndex].Set(value, 0, nextNodeIndex);
|
||||||
|
// _nodes[newNodeIndex].Set_Value_Next(value, nextNodeIndex);
|
||||||
_nodes[newNodeIndex].Set(value, nextNode.prev, nodeIndex);
|
// //_nodes[nextNodeIndex].prev = newNodeIndex;
|
||||||
basketInfo.nodeIndex = newNodeIndex;
|
_nodes[newNodeIndex].Set_Value_Next(value, basketInfo.nodeIndex);
|
||||||
nextNode.prev = newNodeIndex;
|
|
||||||
}
|
}
|
||||||
|
basketInfo.nodeIndex = newNodeIndex;
|
||||||
basketInfo.count++;
|
basketInfo.count++;
|
||||||
return newNodeIndex;
|
return newNodeIndex;
|
||||||
}
|
}
|
||||||
@ -143,9 +143,9 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
Resize(_nodes.Length << 1);
|
Resize(_nodes.Length << 1);
|
||||||
}
|
}
|
||||||
int node = _recycledListLast;
|
int resultNode = _recycledListLast;
|
||||||
_recycledListLast = _nodes[node].prev;
|
_recycledListLast = _nodes[resultNode].prev;
|
||||||
return node;
|
return resultNode;
|
||||||
}
|
}
|
||||||
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
//private void Separate(int leftNodeIndex, int rightNodeIndex)
|
//private void Separate(int leftNodeIndex, int rightNodeIndex)
|
||||||
@ -254,6 +254,12 @@ namespace DCFApixels.DragonECS
|
|||||||
this.next = next;
|
this.next = next;
|
||||||
this.prev = prev;
|
this.prev = prev;
|
||||||
}
|
}
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public void Set_Value_Next(int value, int next)
|
||||||
|
{
|
||||||
|
this.value = value;
|
||||||
|
this.next = next;
|
||||||
|
}
|
||||||
public override string ToString() => $"node({prev}<>{next} v:{value})";
|
public override string ToString() => $"node({prev}<>{next} v:{value})";
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
Loading…
Reference in New Issue
Block a user