private static void Generate() { #region Pooling; no need to create all those nodes again if (Grid != null) { int min = Grid.Length; CachedGridNodes.EnsureCapacity(min); for (int i = min - 1; i >= 0; i--) { if (LockstepManager.PoolingEnabled) { CachedGridNodes.Add(Grid[i]); } } } if (ScanGrid != null) { int min = ScanGrid.Length; CachedScanNodes.EnsureCapacity(min); for (int i = min - 1; i >= 0; i--) { if (LockstepManager.PoolingEnabled) { CachedScanNodes.Add(ScanGrid[i]); } } } #endregion long startMem = System.GC.GetTotalMemory(true); ScanGrid = new ScanNode[ScanGridSize]; for (int i = ScanWidth - 1; i >= 0; i--) { for (int j = ScanHeight - 1; j >= 0; j--) { ScanNode node = CachedScanNodes.Count > 0 ? CachedScanNodes.Pop() : new ScanNode(); node.Setup(i, j); ScanGrid[GetScanIndex(i, j)] = node; } } Grid = new GridNode[GridSize]; for (int i = Width - 1; i >= 0; i--) { for (int j = Height - 1; j >= 0; j--) { GridNode node = CachedGridNodes.Count > 0 ? CachedGridNodes.Pop() : new GridNode(); node.Setup(i, j); Grid[GetGridIndex(i, j)] = node; } } long usedMem = System.GC.GetTotalMemory(true) - startMem; //Debug.Log ("Grid generated using " + usedMem + " Bytes!"); }
private static void Generate() { #region Pooling; no need to create all those nodes again if (Grid != null) { int min = Grid.Length; CachedGridNodes.EnsureCapacity(min); for (int i = min - 1; i >= 0; i--) { if (LockstepManager.PoolingEnabled) { CachedGridNodes.Add(Grid[i]); } } } if (ScanGrid != null) { int min = ScanGrid.Length; CachedScanNodes.EnsureCapacity(min); for (int i = min - 1; i >= 0; i--) { if (LockstepManager.PoolingEnabled) { ; } CachedScanNodes.Add(ScanGrid[i]); } } #endregion ScanGrid = new ScanNode[ScanGridSize]; for (int i = ScanWidth - 1; i >= 0; i--) { for (int j = ScanHeight - 1; j >= 0; j--) { ScanNode node = CachedScanNodes.Count > 0 ? CachedScanNodes.Pop() : new ScanNode(); node.Setup(i, j); ScanGrid [GetScanIndex(i, j)] = node; } } Grid = new GridNode[GridSize]; for (int i = Width - 1; i >= 0; i--) { for (int j = Height - 1; j >= 0; j--) { GridNode node = CachedGridNodes.Count > 0 ? CachedGridNodes.Pop() : new GridNode(); node.Setup(i, j); Grid [GetGridIndex(i, j)] = node; } } }