From 37bfe72d7eac68a22a38e7ddcd2cd05f41ba2a00 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Wed, 14 Feb 2024 17:05:41 +0800 Subject: [PATCH] fix IdDispenser --- src/EcsWorld.cs | 6 +++++- src/Internal/IdDispenser.cs | 25 +++++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/EcsWorld.cs b/src/EcsWorld.cs index 571e241..31a3c47 100644 --- a/src/EcsWorld.cs +++ b/src/EcsWorld.cs @@ -405,7 +405,11 @@ namespace DCFApixels.DragonECS unchecked { _gens[e]++; }//up gen _gens[e] |= DEATH_GEN_BIT; } -// _entityDispenser.Sort(); //уплотнение свободных айдишников + Densify(); + } + private void Densify() //уплотнение свободных айдишников + { + _entityDispenser.Sort(); } #endregion diff --git a/src/Internal/IdDispenser.cs b/src/Internal/IdDispenser.cs index 2508497..df19e0f 100644 --- a/src/Internal/IdDispenser.cs +++ b/src/Internal/IdDispenser.cs @@ -156,7 +156,7 @@ namespace DCFApixels.DragonECS.Internal { int usedIndex = 0; int freeIndex = _usedCount; - for (int i = 1; i < _size; i++) + for (int i = 0; i < _size; i++) { if (_sparse[i] < _usedCount) { @@ -193,7 +193,7 @@ namespace DCFApixels.DragonECS.Internal Swap(nullID, _usedCount++); } } - private bool IsValid() + internal bool IsValid() { for (int i = 0; i < _usedCount; i++) { @@ -328,7 +328,12 @@ namespace DCFApixels.DragonECS.Internal { Pair[] result = new Pair[_target.Size]; for (int i = 0; i < result.Length; i++) - result[i] = new Pair(_target._dense[i], _target._sparse[i]); + { + result[i] = new Pair( + _target._dense[i], + _target._sparse[i], + i < _target.Count); + } return result; } } @@ -356,12 +361,20 @@ namespace DCFApixels.DragonECS.Internal public ID(int id, string state) { this.id = id; this.state = state; } public override string ToString() => $"{id} - {state}"; } + [DebuggerDisplay("{Separator} -> {sparse} - {dense}")] internal readonly struct Pair { - public readonly int dense; public readonly int sparse; - public Pair(int dense, int sparse) { this.dense = dense; this.sparse = sparse; } - public override string ToString() => $"{dense} - {sparse}"; + public readonly int dense; + public readonly bool isSeparator; + public int Separator => isSeparator ? 1 : 0; + public Pair(int dense, int sparse, bool isSeparator) + { + this.dense = dense; + this.sparse = sparse; + this.isSeparator = isSeparator; + } + //public override string ToString() => $"{sparse} - {dense} { (isSeparator ? '>' : ' ') } "; } #endif }