Show / Hide Table of Contents

Class AdvancedLayeredSpatialMap<T>

A more complex version of LayeredSpatialMap<T> that does not require the items in it to implement IHasID, instead requiring the specification of a custom System.Collections.Generic.IEqualityComparer<T> to use for hashing and comparison of items.

Inheritance
System.Object
AdvancedLayeredSpatialMap<T>
LayeredSpatialMap<T>
Implements
ISpatialMap<T>
IReadOnlyLayeredSpatialMap<T>
IReadOnlySpatialMap<T>
System.Collections.Generic.IEnumerable<ISpatialTuple<T>>
System.Collections.IEnumerable
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: GoRogue
Assembly: GoRogue.dll
Syntax
public class AdvancedLayeredSpatialMap<T> : ISpatialMap<T>, IReadOnlyLayeredSpatialMap<T>, IReadOnlySpatialMap<T>, IEnumerable<ISpatialTuple<T>>, IEnumerable where T : IHasLayer
Type Parameters
Name Description
T

Type of items in the layers. Type T must implement IHasLayer, and its Layer value MUST NOT change while the item is in the AdvancedLayeredSpatialMap.

Remarks

This class is useful for cases where you do not want to implement IHasID. For simple cases, it is recommended to use LayeredSpatialMap<T> instead.

Be mindful of the efficiency of your hashing function specified in the System.Collections.Generic.IEqualityComparer<T> -- it will in large part determine the performance of AdvancedLayeredSpatialMap!

Constructors

| Improve this Doc View Source

AdvancedLayeredSpatialMap(IEqualityComparer<T>, Int32, Int32, UInt32)

Constructor.

Declaration
public AdvancedLayeredSpatialMap(IEqualityComparer<T> comparer, int numberOfLayers, int startingLayer = 0, uint layersSupportingMultipleItems = 0U)
Parameters
Type Name Description
System.Collections.Generic.IEqualityComparer<T> comparer

Equality comparer to use for comparison and hashing of type T. Be especially mindful of the efficiency of its GetHashCode function, as it will determine the efficiency of many AdvancedLayeredSpatialMap functions.

System.Int32 numberOfLayers

Number of layers to include.

System.Int32 startingLayer

Index to use for the first layer.

System.UInt32 layersSupportingMultipleItems

A layer mask indicating which layers should support multiple items residing at the same location on that layer. Defaults to no layers.

Properties

| Improve this Doc View Source

Count

See Count

Declaration
public int Count { get; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

Items

See Items.

Declaration
public IEnumerable<T> Items { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<T>
| Improve this Doc View Source

LayerMasker

Object used to get layer masks as they pertain to this spatial map.

Declaration
public LayerMasker LayerMasker { get; }
Property Value
Type Description
LayerMasker
| Improve this Doc View Source

Layers

Gets read-only spatial maps representing each layer. To access a specific layer, instead use GetLayer(Int32).

Declaration
public IEnumerable<IReadOnlySpatialMap<T>> Layers { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<IReadOnlySpatialMap<T>>
| Improve this Doc View Source

NumberOfLayers

Gets the number of layers contained in the spatial map.

Declaration
public int NumberOfLayers { get; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

Positions

Gets all positions that have items for each layer. No positions are duplicated if multiple layers have an item at a position.

Declaration
public IEnumerable<Coord> Positions { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<Coord>
| Improve this Doc View Source

StartingLayer

Starting index for layers contained in this spatial map.

Declaration
public int StartingLayer { get; }
Property Value
Type Description
System.Int32

Methods

| Improve this Doc View Source

Add(T, Coord)

Adds the given item at the given position. Item is automatically added to correct layer.

Declaration
public bool Add(T newItem, Coord position)
Parameters
Type Name Description
T newItem

Item to add.

Coord position

Position to add item at.

Returns
Type Description
System.Boolean

True if the item was successfully added -- false otherwise.

| Improve this Doc View Source

Add(T, Int32, Int32)

Adds the given item at the given position, or returns false if the item cannot be added. Item is automatically added to correct layer.

Declaration
public bool Add(T newItem, int x, int y)
Parameters
Type Name Description
T newItem

Item to add.

System.Int32 x

X-value of position to add item at.

System.Int32 y

Y-value of position to add item at.

Returns
Type Description
System.Boolean

True if the item was successfully added, false otherwise.

| Improve this Doc View Source

AsReadOnly()

See AsReadOnly().

Declaration
public IReadOnlyLayeredSpatialMap<T> AsReadOnly()
Returns
Type Description
IReadOnlyLayeredSpatialMap<T>

The current data structure, as a "read-only" reference.

| Improve this Doc View Source

Clear()

See Clear().

Declaration
public void Clear()
| Improve this Doc View Source

Contains(T)

See Contains(T).

Declaration
public bool Contains(T item)
Parameters
Type Name Description
T item
Returns
Type Description
System.Boolean
| Improve this Doc View Source

Contains(Coord, UInt32)

See Contains(Coord, UInt32).

Declaration
public bool Contains(Coord position, uint layerMask = 4294967295U)
Parameters
Type Name Description
Coord position
System.UInt32 layerMask
Returns
Type Description
System.Boolean
| Improve this Doc View Source

Contains(Int32, Int32, UInt32)

See Contains(Int32, Int32, UInt32).

Declaration
public bool Contains(int x, int y, uint layerMask = 4294967295U)
Parameters
Type Name Description
System.Int32 x
System.Int32 y
System.UInt32 layerMask
Returns
Type Description
System.Boolean
| Improve this Doc View Source

GetEnumerator()

Used by foreach loop, so that the class will give ISpatialTuple objects when used in a foreach loop. Generally should never be called explicitly.

Declaration
public IEnumerator<ISpatialTuple<T>> GetEnumerator()
Returns
Type Description
System.Collections.Generic.IEnumerator<ISpatialTuple<T>>

An enumerator for the spatial map

| Improve this Doc View Source

GetItems(Coord, UInt32)

See GetItems(Coord, UInt32).

Declaration
public IEnumerable<T> GetItems(Coord position, uint layerMask = 4294967295U)
Parameters
Type Name Description
Coord position
System.UInt32 layerMask
Returns
Type Description
System.Collections.Generic.IEnumerable<T>
| Improve this Doc View Source

GetItems(Int32, Int32, UInt32)

See GetItems(Int32, Int32, UInt32).

Declaration
public IEnumerable<T> GetItems(int x, int y, uint layerMask = 4294967295U)
Parameters
Type Name Description
System.Int32 x
System.Int32 y
System.UInt32 layerMask
Returns
Type Description
System.Collections.Generic.IEnumerable<T>
| Improve this Doc View Source

GetLayer(Int32)

Gets a read-only spatial map representing the layer given.

Declaration
public IReadOnlySpatialMap<T> GetLayer(int layer)
Parameters
Type Name Description
System.Int32 layer

The layer to retrieve.

Returns
Type Description
IReadOnlySpatialMap<T>

The IReadOnlySpatialMap that represents the given layer.

| Improve this Doc View Source

GetLayers(UInt32)

Returns read-only spatial maps that represent each layer included in the given layer mask. Defaults to all layers.

Declaration
public IEnumerable<IReadOnlySpatialMap<T>> GetLayers(uint layerMask = 4294967295U)
Parameters
Type Name Description
System.UInt32 layerMask

Layer mask indicating which layers to return. Defaults to all layers.

Returns
Type Description
System.Collections.Generic.IEnumerable<IReadOnlySpatialMap<T>>

Read-only spatial maps representing each layer in the given layer mask.

| Improve this Doc View Source

GetPosition(T)

See GetPosition(T).

Declaration
public Coord GetPosition(T item)
Parameters
Type Name Description
T item
Returns
Type Description
Coord
| Improve this Doc View Source

Move(T, Coord)

Moves the given item to the given position, or returns false if the item cannot be moved. The move could fail if either the item given isn't in the spatial map, or if the layer that the item resides on is configured to allow only one item per location at any given time and there is already an item at the target.

Declaration
public bool Move(T item, Coord target)
Parameters
Type Name Description
T item

Item to move.

Coord target

Position to move the given item to.

Returns
Type Description
System.Boolean

True if the item was successfully moved, false if the move failed.

| Improve this Doc View Source

Move(T, Int32, Int32)

Moves the given item to the given position, or returns false if the item cannot be moved. The move could fail if either the item given isn't in the spatial map, or if the layer that the item resides on is configured to allow only one item per location at any given time and there is already an item at the target position.

Declaration
public bool Move(T item, int targetX, int targetY)
Parameters
Type Name Description
T item

Item to move.

System.Int32 targetX

X-value of position to move the given item to.

System.Int32 targetY

Y-value of position to move the given item to.

Returns
Type Description
System.Boolean

True if the item was successfully moved, false otherwise.

| Improve this Doc View Source

Move(Coord, Coord, UInt32)

Moves all items at the given position, that are on any layer specified by the given layer mask, to the new position. If no layer mask is specified, defaults to all layers.

Declaration
public IEnumerable<T> Move(Coord current, Coord target, uint layerMask = 4294967295U)
Parameters
Type Name Description
Coord current

Position to move all items from.

Coord target

Position to move all items to.

System.UInt32 layerMask

Layer mask specifying which layers to search for items on. Defaults to all layers.

Returns
Type Description
System.Collections.Generic.IEnumerable<T>

All items moved.

| Improve this Doc View Source

Move(Int32, Int32, Int32, Int32, UInt32)

Moves all items at the given position, that are on any layer specified by the given layer mask, to the new position. If no layer mask is specified, defaults to all layers.

Declaration
public IEnumerable<T> Move(int currentX, int currentY, int targetX, int targetY, uint layerMask = 4294967295U)
Parameters
Type Name Description
System.Int32 currentX

X-value of the position to move items from.

System.Int32 currentY

Y-value of the position to move items from.

System.Int32 targetX

X-value of the position to move items to.

System.Int32 targetY

Y-value of the position to move itesm from.

System.UInt32 layerMask

Layer mask specifying which layers to search for items on. Defaults to all layers.

Returns
Type Description
System.Collections.Generic.IEnumerable<T>

All items moved.

| Improve this Doc View Source

Remove(T)

See Remove(T).

Declaration
public bool Remove(T item)
Parameters
Type Name Description
T item
Returns
Type Description
System.Boolean
| Improve this Doc View Source

Remove(Coord, UInt32)

Removes all items at the specified location that are on any layer included in the given layer mask from the spatial map. Returns any items that were removed. Defaults to searching for items on all layers.

Declaration
public IEnumerable<T> Remove(Coord position, uint layerMask = 4294967295U)
Parameters
Type Name Description
Coord position

Position to remove items from.

System.UInt32 layerMask

The layer mask indicating which layers to search for items. Defaults to all layers.

Returns
Type Description
System.Collections.Generic.IEnumerable<T>

Any items that were removed, or nothing if no items were removed.

| Improve this Doc View Source

Remove(Int32, Int32, UInt32)

Removes all items at the specified location that are on any layer included in the given layer mask from the spatial map. Returns any items that were removed. Defaults to searching for items on all layers.

Declaration
public IEnumerable<T> Remove(int x, int y, uint layerMask = 4294967295U)
Parameters
Type Name Description
System.Int32 x

X-value of the position to remove items from.

System.Int32 y

Y-value of the position to remove items from.

System.UInt32 layerMask

The layer mask indicating which layers to search for items. Defaults to all layers.

Returns
Type Description
System.Collections.Generic.IEnumerable<T>

Any items that were removed, or nothing if no items were removed.

| Improve this Doc View Source

ToString()

Returns a string representation of each layer in the spatial map.

Declaration
public override string ToString()
Returns
Type Description
System.String

A string representing each layer of the LayeredSpatialMap

Overrides
System.Object.ToString()
| Improve this Doc View Source

ToString(Func<T, String>)

Returns a string representation of each item in the spatial map, with elements displayed in the specified way.

Declaration
public string ToString(Func<T, string> elementStringifier)
Parameters
Type Name Description
System.Func<T, System.String> elementStringifier

A function that takes an element of type T and produces the string that should represent it in the output.

Returns
Type Description
System.String

A string representing each layer in the spatial map, with each element displayed in the specified way.

Events

| Improve this Doc View Source

ItemAdded

See ItemAdded.

Declaration
public event EventHandler<ItemEventArgs<T>> ItemAdded
Event Type
Type Description
System.EventHandler<ItemEventArgs<T>>
| Improve this Doc View Source

ItemMoved

See ItemMoved.

Declaration
public event EventHandler<ItemMovedEventArgs<T>> ItemMoved
Event Type
Type Description
System.EventHandler<ItemMovedEventArgs<T>>
| Improve this Doc View Source

ItemRemoved

See ItemRemoved.

Declaration
public event EventHandler<ItemEventArgs<T>> ItemRemoved
Event Type
Type Description
System.EventHandler<ItemEventArgs<T>>

Explicit Interface Implementations

| Improve this Doc View Source

IReadOnlySpatialMap<T>.AsReadOnly()

See AsReadOnly().

Declaration
IReadOnlySpatialMap<T> IReadOnlySpatialMap<T>.AsReadOnly()
Returns
Type Description
IReadOnlySpatialMap<T>
| Improve this Doc View Source

IReadOnlySpatialMap<T>.Contains(Coord)

See Contains(Coord).

Declaration
bool IReadOnlySpatialMap<T>.Contains(Coord position)
Parameters
Type Name Description
Coord position
Returns
Type Description
System.Boolean
| Improve this Doc View Source

IReadOnlySpatialMap<T>.Contains(Int32, Int32)

See Contains(Int32, Int32).

Declaration
bool IReadOnlySpatialMap<T>.Contains(int x, int y)
Parameters
Type Name Description
System.Int32 x
System.Int32 y
Returns
Type Description
System.Boolean
| Improve this Doc View Source

IReadOnlySpatialMap<T>.GetItems(Coord)

GetItems(Coord).

Declaration
IEnumerable<T> IReadOnlySpatialMap<T>.GetItems(Coord position)
Parameters
Type Name Description
Coord position
Returns
Type Description
System.Collections.Generic.IEnumerable<T>
| Improve this Doc View Source

IReadOnlySpatialMap<T>.GetItems(Int32, Int32)

See GetItems(Int32, Int32).

Declaration
IEnumerable<T> IReadOnlySpatialMap<T>.GetItems(int x, int y)
Parameters
Type Name Description
System.Int32 x
System.Int32 y
Returns
Type Description
System.Collections.Generic.IEnumerable<T>
| Improve this Doc View Source

ISpatialMap<T>.Move(Coord, Coord)

Moves all items on all layers at the given position to the new position.

Declaration
IEnumerable<T> ISpatialMap<T>.Move(Coord current, Coord target)
Parameters
Type Name Description
Coord current

Position to move items from.

Coord target

Position to move items to

Returns
Type Description
System.Collections.Generic.IEnumerable<T>

All items moved.

| Improve this Doc View Source

ISpatialMap<T>.Move(Int32, Int32, Int32, Int32)

Moves all items on all layers at the given position to the new position.

Declaration
IEnumerable<T> ISpatialMap<T>.Move(int currentX, int currentY, int targetX, int targetY)
Parameters
Type Name Description
System.Int32 currentX

X-value of the position to move items from.

System.Int32 currentY

Y-value of the position to move items from.

System.Int32 targetX

X-value of the position to move items to.

System.Int32 targetY

Y-value of the position to move itesm from.

Returns
Type Description
System.Collections.Generic.IEnumerable<T>

All items moved.

| Improve this Doc View Source

ISpatialMap<T>.Remove(Coord)

See Remove(Coord).

Declaration
IEnumerable<T> ISpatialMap<T>.Remove(Coord position)
Parameters
Type Name Description
Coord position
Returns
Type Description
System.Collections.Generic.IEnumerable<T>
| Improve this Doc View Source

ISpatialMap<T>.Remove(Int32, Int32)

See Remove(Int32, Int32).

Declaration
IEnumerable<T> ISpatialMap<T>.Remove(int x, int y)
Parameters
Type Name Description
System.Int32 x
System.Int32 y
Returns
Type Description
System.Collections.Generic.IEnumerable<T>
| Improve this Doc View Source

IEnumerable.GetEnumerator()

Generic iterator used internally by foreach loops.

Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type Description
System.Collections.IEnumerator

Enumerator to ISpatialTuple instances.

Implements

ISpatialMap<T>
IReadOnlyLayeredSpatialMap<T>
IReadOnlySpatialMap<T>
System.Collections.Generic.IEnumerable<T>
System.Collections.IEnumerable

Extension Methods

Utility.ExtendToString<T>(IEnumerable<T>, String, Func<T, String>, String, String)
Utility.Yield<T>(T)
  • Improve this Doc
  • View Source
Back to top Generated by DocFX