This commit is contained in:
Mikhail 2024-02-01 01:17:06 +08:00
parent 777f4e9870
commit 3c79ea24e3
2 changed files with 48 additions and 12 deletions

View File

@ -226,10 +226,10 @@ namespace DCFApixels.DragonECS.Relations.Utils
// arc.ArcWorld.DelEntity(revereceRelEntitiy); // arc.ArcWorld.DelEntity(revereceRelEntitiy);
//} //}
//int endNodeIndex = _relNodesMapping[relEntityID].endNodeIndex;
arc.ArcWorld.DelEntity(relEntityID); arc.ArcWorld.DelEntity(relEntityID);
//if (!_isLoop) //if (_isLoop)
//{ //{
// int endNodeIndex = _relNodesMapping[relEntityID].endNodeIndex;
// int revereceRelEntitiy = _endBaskets.Get(endNodeIndex); // int revereceRelEntitiy = _endBaskets.Get(endNodeIndex);
// arc.ArcWorld.DelEntity(revereceRelEntitiy); // arc.ArcWorld.DelEntity(revereceRelEntitiy);
//} //}
@ -253,10 +253,10 @@ namespace DCFApixels.DragonECS.Relations.Utils
// arc.ArcWorld.DelEntity(revereceRelEntitiy); // arc.ArcWorld.DelEntity(revereceRelEntitiy);
//} //}
//int startNodeIndex = _relNodesMapping[relEntityID].startNodeIndex;
arc.ArcWorld.DelEntity(relEntityID); arc.ArcWorld.DelEntity(relEntityID);
//if (!_isLoop) //if (_isLoop)
//{ //{
// int startNodeIndex = _relNodesMapping[relEntityID].startNodeIndex;
// int revereceRelEntitiy = _startBaskets.Get(startNodeIndex); // int revereceRelEntitiy = _startBaskets.Get(startNodeIndex);
// arc.ArcWorld.DelEntity(revereceRelEntitiy); // arc.ArcWorld.DelEntity(revereceRelEntitiy);
//} //}

View File

@ -19,6 +19,7 @@ namespace DCFApixels.DragonECS
private readonly StartWorldHandler _startWorldHandler; private readonly StartWorldHandler _startWorldHandler;
private readonly ArcWorldHandler _arcWorldHandler; private readonly ArcWorldHandler _arcWorldHandler;
private readonly EndWorldHandler _endWorldHandler; private readonly EndWorldHandler _endWorldHandler;
private readonly LoopWorldHandler _loopWorldHandler;
private readonly SparseArray64<int> _relationsMatrix = new SparseArray64<int>(); private readonly SparseArray64<int> _relationsMatrix = new SparseArray64<int>();
@ -85,13 +86,19 @@ namespace DCFApixels.DragonECS
_relEntityInfos = new RelEntityInfo[arcWorld.Capacity]; _relEntityInfos = new RelEntityInfo[arcWorld.Capacity];
_startWorldHandler = new StartWorldHandler(this);
_arcWorldHandler = new ArcWorldHandler(this); _arcWorldHandler = new ArcWorldHandler(this);
if (!_isLoop)
if (_isLoop)
{ {
_loopWorldHandler = new LoopWorldHandler(this);
}
else
{
_startWorldHandler = new StartWorldHandler(this);
_endWorldHandler = new EndWorldHandler(this); _endWorldHandler = new EndWorldHandler(this);
} }
_relEntities = EcsGroup.New(_arcWorld); _relEntities = EcsGroup.New(_arcWorld);
_joinEntities = new EcsJoin(this); _joinEntities = new EcsJoin(this);
@ -100,12 +107,17 @@ namespace DCFApixels.DragonECS
} }
public void Destroy() public void Destroy()
{ {
_startWorldHandler.Destroy(); _arcWorldHandler.Destroy();
_arcWorldHandler.Destroy(); if (_isLoop)
if (!_isLoop)
{ {
_endWorldHandler.Destroy(); _loopWorldHandler.Destroy();
} }
else
{
_startWorldHandler.Destroy();
_endWorldHandler.Destroy();
}
} }
#endregion #endregion
@ -281,7 +293,6 @@ namespace DCFApixels.DragonECS
{ {
foreach (var startEntityID in startEntityBuffer) foreach (var startEntityID in startEntityBuffer)
{ {
//_arc._joinEntities.DelStart(startEntityID);
_arc._joinEntitiesFriend.DelStartAndDelRelEntities(startEntityID, _arc); _arc._joinEntitiesFriend.DelStartAndDelRelEntities(startEntityID, _arc);
} }
_arc._arcWorld.ReleaseDelEntityBuffer(startEntityBuffer.Length); _arc._arcWorld.ReleaseDelEntityBuffer(startEntityBuffer.Length);
@ -307,7 +318,6 @@ namespace DCFApixels.DragonECS
{ {
foreach (var endEntityID in endEntityBuffer) foreach (var endEntityID in endEntityBuffer)
{ {
//_arc._joinEntities.DelEnd(endEntityID);
_arc._joinEntitiesFriend.DelEndAndDelRelEntities(endEntityID, _arc); _arc._joinEntitiesFriend.DelEndAndDelRelEntities(endEntityID, _arc);
} }
_arc._arcWorld.ReleaseDelEntityBuffer(endEntityBuffer.Length); _arc._arcWorld.ReleaseDelEntityBuffer(endEntityBuffer.Length);
@ -316,6 +326,32 @@ namespace DCFApixels.DragonECS
public void OnWorldResize(int endWorldNewSize) { } public void OnWorldResize(int endWorldNewSize) { }
#endregion #endregion
} }
private class LoopWorldHandler : IEcsWorldEventListener
{
private readonly EcsArc _arc;
public LoopWorldHandler(EcsArc arc)
{
_arc = arc;
_arc.StartWorld.AddListener(this);
}
public void Destroy()
{
_arc.StartWorld.RemoveListener(this);
}
#region Callbacks
public void OnReleaseDelEntityBuffer(ReadOnlySpan<int> startEntityBuffer)
{
foreach (var startEntityID in startEntityBuffer)
{
_arc._joinEntitiesFriend.DelStartAndDelRelEntities(startEntityID, _arc);
_arc._joinEntitiesFriend.DelEndAndDelRelEntities(startEntityID, _arc);
}
_arc._arcWorld.ReleaseDelEntityBuffer(startEntityBuffer.Length);
}
public void OnWorldDestroy() { }
public void OnWorldResize(int startWorldNewSize) { }
#endregion
}
#endregion #endregion
} }
} }