public class ChunkSetPool
A class used with Pooling Chunk Managers to store chunk sets.
If creating a custom pooling manager, please take special care in reading the information
about each method, as there is a specific way
that the pool needs to be used in order to maximize efficiency.
public ChunkSetPool(int maxChunkSetsToPool, EqualityComparer<Cell> comparer)
Creates a new instance of the Chunk Set Pool.
Name | Type | Description |
---|---|---|
maxChunkSetsToPool | int |
The max number of chunk sets to store per Streamable Grid Cell |
comparer | EqualityComparer<Cell> |
Equality Comparerer to use to compare Streamable Grid Cells. |
public void DepositIntoPool(Cell streamableGridCell, List<object> chunks)
Deposits the chunks into the pool. You should check IsAtCapacity before calling this
method, to ensure that you don't
add too many chunk sets to the pool!
In order minimize garbage generation, you can retrieve the list to store the chunks
in using the
GetReusableListFromPool method.
Name | Type | Description |
---|---|---|
streamableGridCell | Cell |
The Streamable Grid Cell whose chunk set you wish to pool. You can get this value via WorldCell.CellOnStreamableGrid. |
chunks | List<object> |
The chunks to store for the Streamable Grid Cell. |
Type | Condition |
---|---|
InvalidOperationException | Thrown if you try to add a chunk set for a Streamable Grid Cell that is already at capacity. |
public bool DoesCellHavePooledChunks(Cell streamableGridCell)
Queries whether the Streamable Grid Cell has at least one chunk set in the pool.
Name | Type | Description |
---|---|---|
streamableGridCell | Cell |
The Streamable Grid Cell whose chunks you are inquring about. You can get this value via WorldCell.CellOnStreamableGrid. |
bool
True if chunks are being pooled, false otherwise.
public KeyEnumerable GetCellsWithChunkSets()
Can be used to retrieve an enumerable collection of the Streamable Grid Cells that have chunk sets in the pool. Useful for iterating over these cells in a garbage free manner.
KeyEnumerable
The enumerable object. Use in a foreach loop or call GetEnumerator.
public List<object> GetReusableListFromPool(int numChunks)
Gets a list with capacity equal to or greater than numChunks. The list comes from
an internal static pool that is reused between
all classes deriving from PoolingChunkManager. In order for the pooling of these lists
to work correctly, you need
to call ReturnReusableList whenever the list is no longer needed.
The typical use case for using this method is as follows:
1) Before detatching Asset Chunks from a World Cell and returning those chunks to
this pool, call this method to get a list that
the chunks can be stored in.
2) Detatch the Asset Chunks from the World Cell and add them to the list retrieved
in step 1.
3) Call DepositIntoPool to deposit the list of asset chunks into this pool.
Name | Type | Description |
---|---|---|
numChunks | int |
The number of chunks that will be stored in the list. |
List<object>
The reusable list.
public bool IsAtCapacity(Cell streamableGridCell)
Checks whether a particular Streamable Grid Cell is at capacity within the pool. That is, whether it already has x set of chunks (where x >= Max Chunk Sets in Pool) in the pool. This is used by the built in pooling logic to determine if a World Cell's chunk set should be pooled.
Name | Type | Description |
---|---|---|
streamableGridCell | Cell |
The Streamable Grid Cell whose capacity you are inquring about. You can get this value via WorldCell.CellOnStreamableGrid. |
bool
True if storage for the cell is at capacity, false otherwise. If true, you should
not deposit more chunk sets into the pool!
public bool IsEmpty()
Method that checks whether any chunk sets for any Streamable Grid Cells are being stored in the pool. If you want to know if a specific Streamable Grid Cell has chunk sets, use DoesCellHavePooledChunks instead.
bool
Returns true if pool is empty (no chunk sets present at all), or false otherwise.
public int NumberOfChunkSetsPooledForCell(Cell streamableGridCell)
Gets the number of chunk sets in the pool for the Streamable Grid Cell.
Name | Type | Description |
---|---|---|
streamableGridCell | Cell |
The Streamable Grid Cell whose chunks you are inquring about. You can get this value via WorldCell.CellOnStreamableGrid. |
int
The number of chunk sets currently in the pool for the Streamable Grid Cell.
public void ReturnReusableListToPool(List<object> list)
Returns a reusable list to the internal static pool. The pool is shared between all
classes that derive from
PoolingChunkManager, which cuts down on the number of new list objects needed.
This list should have been retrieved via the
WithdrawFromPool method.
The typical use case for using this method is as follows:
1) Call WithdrawFromPool
to get a list of Asset Chunks from this pool that can be attached to a World Cell.
2) Attach the Asset Chunks from the list to the World Cell.
3) Call this method to return the list to the internal list pool so that it can be
reused.
Name | Type | Description |
---|---|---|
list | List<object> |
The list to return to the pool. |
public List<object> WithdrawFromPool(Cell streamableGridCell)
Withdraws a set of chunk objects associated with a particular Streamable Grid Cell
from the pool. The list of chunks is removed from the pool,
however you will need to return the list object itself so that it can be reused internally
by calling the
ReturnReusableListToPool method. You should
do this onlya after you have attached all of the chunks from the list onto your World
Cell.
ReturnReusableListToPool will clear and pool the list object so that it can
be reused later by either this ChunkSetPool or another ChunkSetPool.
Name | Type | Description |
---|---|---|
streamableGridCell | Cell |
The Streamable Grid Cell whose chunks you wish to withdraw from the pool. You can get this value via WorldCell.CellOnStreamableGrid. |
List<object>
The withdrawn chunks.
Type | Condition |
---|---|
KeyNotFoundException | Thrown if there are no chunk sets stored for the Streamable Grid Cell indicated by flattenedStreamableGridCellIndex. |