| | | 1 | | using GridForge.Spatial; |
| | | 2 | | using SwiftCollections; |
| | | 3 | | using SwiftCollections.Pool; |
| | | 4 | | |
| | | 5 | | namespace GridForge.Grids; |
| | | 6 | | |
| | | 7 | | internal static class Pools |
| | | 8 | | { |
| | | 9 | | #region Grid Pooling |
| | | 10 | | |
| | | 11 | | /// <summary> |
| | | 12 | | /// Object pool for reusing <see cref="VoxelGrid"/> instances. |
| | | 13 | | /// </summary> |
| | 1 | 14 | | public static readonly SwiftObjectPool<VoxelGrid> GridPool = new( |
| | 9 | 15 | | createFunc: () => new VoxelGrid(), |
| | 182 | 16 | | actionOnRelease: grid => grid.Reset() |
| | 1 | 17 | | ); |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// Object pool for reusing <see cref="Voxel"/> instances. |
| | | 21 | | /// </summary> |
| | 1 | 22 | | public static readonly SwiftObjectPool<Voxel> VoxelPool = new( |
| | 70876 | 23 | | createFunc: () => new Voxel(), |
| | 78143 | 24 | | actionOnRelease: voxel => voxel.Reset() |
| | 1 | 25 | | ); |
| | | 26 | | |
| | 1 | 27 | | public static readonly SwiftObjectPool<SwiftSparseMap<ScanCell>> ScanCellMapPool = new( |
| | 10 | 28 | | createFunc: () => new SwiftSparseMap<ScanCell>(), |
| | 186 | 29 | | actionOnRelease: map => map.Clear() |
| | 1 | 30 | | ); |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// Object pool for reusing <see cref="ScanCell"/> instances. |
| | | 34 | | /// </summary> |
| | 1 | 35 | | public static readonly SwiftObjectPool<ScanCell> ScanCellPool = new( |
| | 359 | 36 | | createFunc: () => new ScanCell(), |
| | 1255 | 37 | | actionOnRelease: cell => cell.Reset() |
| | 1 | 38 | | ); |
| | | 39 | | |
| | | 40 | | #endregion |
| | | 41 | | |
| | | 42 | | #region Node Pooling |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// Object pool for caching neighbor voxel arrays. |
| | | 46 | | /// </summary> |
| | 1 | 47 | | public static readonly SwiftArrayPool<Voxel> VoxelNeighborPool = new(); |
| | | 48 | | |
| | 1 | 49 | | public static readonly SwiftDictionaryPool<WorldVoxelIndex, SwiftBucket<IVoxelOccupant>> VoxelOccupantDictionaryPool |
| | | 50 | | |
| | 1 | 51 | | public static readonly SwiftObjectPool<SwiftBucket<IVoxelOccupant>> VoxelOccupantBucketPool = new( |
| | 67 | 52 | | createFunc: () => new SwiftBucket<IVoxelOccupant>(), |
| | 112 | 53 | | actionOnRelease: bucket => bucket.Clear() |
| | 1 | 54 | | ); |
| | | 55 | | |
| | | 56 | | #endregion |
| | | 57 | | |
| | | 58 | | public static void ClearPools() |
| | | 59 | | { |
| | 2 | 60 | | GridPool.Clear(); |
| | 2 | 61 | | VoxelPool.Clear(); |
| | 2 | 62 | | ScanCellMapPool.Clear(); |
| | 2 | 63 | | ScanCellPool.Clear(); |
| | 2 | 64 | | VoxelNeighborPool.Clear(); |
| | 2 | 65 | | VoxelOccupantDictionaryPool.Clear(); |
| | 2 | 66 | | VoxelOccupantBucketPool.Clear(); |
| | 2 | 67 | | } |
| | | 68 | | } |