This commit is contained in:
Mikhail 2024-02-04 01:16:58 +08:00
parent 2473c5dc78
commit 653a798af7
3 changed files with 39 additions and 87 deletions

View File

@ -153,23 +153,25 @@ namespace DCFApixels.DragonECS
#endregion
#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)
{
var (startEntityID, endEntityID) = _source.GetRelationInfo(relEntityID);
ref RelNodesInfo arcInfo = ref _relNodesMapping[relEntityID];
arcInfo.startNodeIndex = _startBaskets.AddToBasket(startEntityID, relEntityID);
arcInfo.endNodeIndex = _endBaskets.AddToBasket(endEntityID, relEntityID);
_relNodesMapping[relEntityID] = new RelNodesInfo(
_startBaskets.AddToBasket(startEntityID, relEntityID),
_endBaskets.AddToBasket(endEntityID, relEntityID));
}
public void Del(int relEntityID)
{
var (startEntityID, endEntityID) = _source.GetRelationInfo(relEntityID);
var (startEntityID, _) = _source.GetRelationInfo(relEntityID);
ref RelNodesInfo relInfo = ref _relNodesMapping[relEntityID];
_startBaskets.RemoveFromBasket(startEntityID, relInfo.startNodeIndex);
if (!_isLoop)
{
//_startBaskets.RemoveFromBasket(endEntityID, relInfo.endNodeIndex);
}
}
public void DelStart(int startEntityID)
{
@ -315,11 +317,16 @@ namespace DCFApixels.DragonECS
#endregion
#region ArcInfo
private struct RelNodesInfo : IEquatable<RelNodesInfo>
private readonly struct RelNodesInfo : IEquatable<RelNodesInfo>
{
public readonly static RelNodesInfo Empty = default;
public int startNodeIndex;
public int endNodeIndex;
public readonly int startNodeIndex;
public readonly int endNodeIndex;
public RelNodesInfo(int startNodeIndex, int endNodeIndex)
{
this.startNodeIndex = startNodeIndex;
this.endNodeIndex = endNodeIndex;
}
#region Object
public override bool Equals(object obj)

View File

@ -124,72 +124,24 @@ namespace DCFApixels.DragonECS
#region New/Del
public int NewRelation(int startEntityID, int endEntityID)
{
//if (HasRelation(startEntityID, endEntityID))
//{
// Throw.RelationAlreadyExists();
//}
int relEntity = _arcWorld.NewEntity();
//_relationsMatrix.Add(startEntityID, endEntityID, relEntity);
_relEntityInfos[relEntity] = new RelEntityInfo(startEntityID, endEntityID);
_relEntities.Add(relEntity);
_entitiesGraph.Add(relEntity);
_relEntities.AddUnchecked(relEntity);
_entitiesGraph.Add(startEntityID, endEntityID, 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)
{
_arcWorld.DelEntity(relEntityID);
}
public void ClearRelation_Internal(int relEntityID)
private void ClearRelation_Internal(int relEntityID)
{
_relEntities.Remove(relEntityID);
_entitiesGraph.Del(relEntityID);
_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
#region ArcEntityInfo
@ -221,19 +173,6 @@ namespace DCFApixels.DragonECS
{
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
#region Other

View File

@ -119,18 +119,18 @@ namespace DCFApixels.DragonECS
int newNodeIndex = TakeRecycledNode();
if (basketInfo.count == 0)
{
basketInfo.nodeIndex = newNodeIndex;
_nodes[newNodeIndex].Set(value, 0, 0);
//_nodes[newNodeIndex].Set(value, 0, 0);
_nodes[newNodeIndex].value = value;
}
else
{
int nodeIndex = basketInfo.nodeIndex;
ref Node nextNode = ref _nodes[nodeIndex];
_nodes[newNodeIndex].Set(value, nextNode.prev, nodeIndex);
basketInfo.nodeIndex = newNodeIndex;
nextNode.prev = newNodeIndex;
// int nextNodeIndex = basketInfo.nodeIndex;
// //_nodes[newNodeIndex].Set(value, 0, nextNodeIndex);
// _nodes[newNodeIndex].Set_Value_Next(value, nextNodeIndex);
// //_nodes[nextNodeIndex].prev = newNodeIndex;
_nodes[newNodeIndex].Set_Value_Next(value, basketInfo.nodeIndex);
}
basketInfo.nodeIndex = newNodeIndex;
basketInfo.count++;
return newNodeIndex;
}
@ -143,9 +143,9 @@ namespace DCFApixels.DragonECS
{
Resize(_nodes.Length << 1);
}
int node = _recycledListLast;
_recycledListLast = _nodes[node].prev;
return node;
int resultNode = _recycledListLast;
_recycledListLast = _nodes[resultNode].prev;
return resultNode;
}
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
//private void Separate(int leftNodeIndex, int rightNodeIndex)
@ -254,6 +254,12 @@ namespace DCFApixels.DragonECS
this.next = next;
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})";
}
#endregion