public void ReleaseState(ref TState state) { //UnityEngine.Debug.LogWarning(UnityEngine.Time.frameCount + " Release state: " + state.tick); state.entityId = default; state.tick = default; PoolClass <TState> .Recycle(ref state); }
void IPoolableRecycle.OnRecycle() { PoolClass <ArchetypeEntities> .Recycle(ref this.archetypes); if (this.list != null) { PoolRefList <Entity> .Recycle(ref this.list); } this.freeze = false; }
public void Do(int iterationCounter) { // Sort circles based on the distance to center var instance = PoolClass <Circle.CirclesComparer> .Spawn(); instance.center = this.mPackingCenter; System.Array.Sort(this.circles.innerArray.arr, 0, this.circles.Count, instance); PoolClass <Circle.CirclesComparer> .Recycle(ref instance); for (int k = 0; k < iterationCounter; ++k) { var minSeparationSq = this.mMinSeparation * this.mMinSeparation; for (var i = 0; i < this.circles.Count - 1; i++) { for (var j = i + 1; j < this.circles.Count; j++) { if (i == j) { continue; } FLOAT2 AB = this.circles[j].mCenter - this.circles[i].mCenter; float r = this.circles[i].mRadius + this.circles[j].mRadius; // Length squared = (dx * dx) + (dy * dy); var d = AB.sqrMagnitude - minSeparationSq; float minSepSq = System.Math.Min(d, minSeparationSq); d -= minSepSq; if (d < r * r - 0.01f) { AB.Normalize(); AB *= (float)((r - System.Math.Sqrt(d)) * 0.5f); this.circles[j].mCenter += AB; this.circles[i].mCenter -= AB; } } } var damping = 0.1f / (float)iterationCounter; for (var i = 0; i < this.circles.Count; i++) { var v = this.circles[i].mCenter - this.mPackingCenter; v *= damping; this.circles[i].mCenter -= v; } } }