Class LayeredSpatialMap<T>
ISpatialMap<T> implementation that can be used to efficiently represent multiple "layers" of objects, with each layer represented as an ISpatialMap<T> instance. It provides the regular spatial map functionality, as well as adds layer masking functionality that allow functions to operate on specific layers only.
Implements
Inherited Members
Namespace: SadRogue.Primitives.SpatialMaps
Assembly: TheSadRogue.Primitives.dll
Syntax
public sealed class LayeredSpatialMap<T> : AdvancedLayeredSpatialMap<T>, ISpatialMap<T>, IReadOnlyLayeredSpatialMap<T>, IReadOnlySpatialMap<T>, IEnumerable<ItemPositionPair<T>>, IEnumerable where T : class, IHasLayer, IHasID
Type Parameters
Name | Description |
---|---|
T | Type of items stored in the layers. Type T must implement IHasID and IHasLayer, must be a reference type, and its Layer value MUST NOT change while the item is in the spatial map. |
Remarks
See the ISpatialMap<T> for documentation on the practical purpose of spatial maps. The objects stored in a LayeredSpatialMap must be reference types and implement both IHasID and IHasLayer. Each object in a spatial map is presumed to have a "layer", which is assumed to remain constant once the item is added to the layer mask.
Constructors
LayeredSpatialMap(Int32, Func<Int32, IListPool<T>>, IEqualityComparer<Point>, Int32, UInt32)
Constructor.
Declaration
public LayeredSpatialMap(int numberOfLayers, Func<int, IListPool<T>> customListPoolCreator = null, IEqualityComparer<Point> pointComparer = null, int startingLayer = 0, uint layersSupportingMultipleItems = 0U)
Parameters
Type | Name | Description |
---|---|---|
Int32 | numberOfLayers | Number of layers to include. |
Func<Int32, IListPool<T>> | customListPoolCreator | A function used to determine the list pool implementation used for the spatial maps which support multiple items in a location (if any). The function takes the layer it is creating the pool for as a parameter. If no custom creator is specified, a ListPool is used. |
IEqualityComparer<Point> | pointComparer | Equality comparer to use for comparison and hashing of points, as object are added to/removed from/moved around the spatial map. Be especially mindful of the efficiency of its GetHashCode function, as it will determine the efficiency of many LayeredSpatialMap functions. Defaults to the default equality comparer for Point, which uses a fairly efficient generalized hashing algorithm. |
Int32 | startingLayer | Index to use for the first layer. |
UInt32 | layersSupportingMultipleItems | A layer mask indicating which layers should support multiple items residing at the same location on that layer. Defaults to no layers. Generate this layer mask via Default. |
Remarks
This class allows you to specify the starting index for layers in order to make it easy to
combine with other structures in a map which may represent other layers. For example, if a
startingLayer
of 0 is specified, layers in the spatial map will have numbers
in range[0, numberOfLayers - 1]. If 1 is specified, layers will have numbers in range [1-numberOfLayers],
and anything to do with layer 0 will be ignored. For example, If a layer-mask that includes layers 0,
2, and 3 is passed to a function, only layers 2 and 3 are considered (since they are the only ones that would
be included in the spatial map.