From 3c79ea24e39143e638f1cc186a3c02164914734e Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Thu, 1 Feb 2024 01:17:06 +0800 Subject: [PATCH] fixes --- src/Collections/EcsJoin.cs | 8 +++--- src/EcsArc.cs | 52 ++++++++++++++++++++++++++++++++------ 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/Collections/EcsJoin.cs b/src/Collections/EcsJoin.cs index 9faaf1a..fef327a 100644 --- a/src/Collections/EcsJoin.cs +++ b/src/Collections/EcsJoin.cs @@ -226,10 +226,10 @@ namespace DCFApixels.DragonECS.Relations.Utils // arc.ArcWorld.DelEntity(revereceRelEntitiy); //} - //int endNodeIndex = _relNodesMapping[relEntityID].endNodeIndex; arc.ArcWorld.DelEntity(relEntityID); - //if (!_isLoop) + //if (_isLoop) //{ + // int endNodeIndex = _relNodesMapping[relEntityID].endNodeIndex; // int revereceRelEntitiy = _endBaskets.Get(endNodeIndex); // arc.ArcWorld.DelEntity(revereceRelEntitiy); //} @@ -253,10 +253,10 @@ namespace DCFApixels.DragonECS.Relations.Utils // arc.ArcWorld.DelEntity(revereceRelEntitiy); //} - //int startNodeIndex = _relNodesMapping[relEntityID].startNodeIndex; arc.ArcWorld.DelEntity(relEntityID); - //if (!_isLoop) + //if (_isLoop) //{ + // int startNodeIndex = _relNodesMapping[relEntityID].startNodeIndex; // int revereceRelEntitiy = _startBaskets.Get(startNodeIndex); // arc.ArcWorld.DelEntity(revereceRelEntitiy); //} diff --git a/src/EcsArc.cs b/src/EcsArc.cs index 0b9aa34..3a44d80 100644 --- a/src/EcsArc.cs +++ b/src/EcsArc.cs @@ -19,6 +19,7 @@ namespace DCFApixels.DragonECS private readonly StartWorldHandler _startWorldHandler; private readonly ArcWorldHandler _arcWorldHandler; private readonly EndWorldHandler _endWorldHandler; + private readonly LoopWorldHandler _loopWorldHandler; private readonly SparseArray64 _relationsMatrix = new SparseArray64(); @@ -85,13 +86,19 @@ namespace DCFApixels.DragonECS _relEntityInfos = new RelEntityInfo[arcWorld.Capacity]; - _startWorldHandler = new StartWorldHandler(this); _arcWorldHandler = new ArcWorldHandler(this); - if (!_isLoop) + + if (_isLoop) { + _loopWorldHandler = new LoopWorldHandler(this); + } + else + { + _startWorldHandler = new StartWorldHandler(this); _endWorldHandler = new EndWorldHandler(this); } + _relEntities = EcsGroup.New(_arcWorld); _joinEntities = new EcsJoin(this); @@ -100,12 +107,17 @@ namespace DCFApixels.DragonECS } public void Destroy() { - _startWorldHandler.Destroy(); - _arcWorldHandler.Destroy(); - if (!_isLoop) + _arcWorldHandler.Destroy(); + if (_isLoop) { - _endWorldHandler.Destroy(); + _loopWorldHandler.Destroy(); } + else + { + _startWorldHandler.Destroy(); + _endWorldHandler.Destroy(); + } + } #endregion @@ -281,7 +293,6 @@ namespace DCFApixels.DragonECS { foreach (var startEntityID in startEntityBuffer) { - //_arc._joinEntities.DelStart(startEntityID); _arc._joinEntitiesFriend.DelStartAndDelRelEntities(startEntityID, _arc); } _arc._arcWorld.ReleaseDelEntityBuffer(startEntityBuffer.Length); @@ -307,7 +318,6 @@ namespace DCFApixels.DragonECS { foreach (var endEntityID in endEntityBuffer) { - //_arc._joinEntities.DelEnd(endEntityID); _arc._joinEntitiesFriend.DelEndAndDelRelEntities(endEntityID, _arc); } _arc._arcWorld.ReleaseDelEntityBuffer(endEntityBuffer.Length); @@ -316,6 +326,32 @@ namespace DCFApixels.DragonECS public void OnWorldResize(int endWorldNewSize) { } #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 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 } } \ No newline at end of file