Show / Hide Table of Contents

Class SenseMap

Class responsible for calculating a map for senses (sound, light, etc), or generally anything that can be modeled as sources propegating through a map that has degrees of resistance to spread.

Inheritance
System.Object
SenseMap
Implements
IReadOnlySenseMap
System.Collections.Generic.IEnumerable<System.Double>
System.Collections.IEnumerable
IMapView<System.Double>
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.SenseMapping
Assembly: GoRogue.dll
Syntax
public class SenseMap : IReadOnlySenseMap, IEnumerable<double>, IEnumerable, IMapView<double>
Remarks

Generally, this class can be used to model the result of applying ripple-like or shadowcasting-like "spreading" of values from one or more sources through a map. This can include modeling the spreading of light, sound, heat for a heatmap, etc. through a map. You create one or more SenseSource instances representing your various sources, add them to the SenseMap, and call Calculate() when you wish to re-calculate the SenseMap.

Like most GoRogue algorithm implementations, SenseMap takes as a construction parameter an IMapView that represents the map. Specifically, it takes an IMapView<T>, where the double value at each location represents the "resistance" that location has to the passing of source values through it. The values must be >= 0.0, where 0.0 means that a location has no resistance to spreading of source values, and greater values represent greater resistance. The scale of this resistance is arbitrary, and is related to the Intensity of your sources. As a source spreads through a given location, a value equal to the resistance value of that location is subtracted from the source's value (plus the normal fallof for distance).

The map can be calculated by calling the Calculate() function.

This class exposes the resulting sensory values values to you via indexers -- SenseMap implements IMapView<T>, where 0.0 indicates no sources were able to spread to the given location (eg, either it was stopped or fell off due to distance), and a value greater than 0.0 indicates the combined intensity of any sources that reached the given location.

Constructors

| Improve this Doc View Source

SenseMap(IMapView<Double>)

Constructor. Takes the resistance map to use for calculations.

Declaration
public SenseMap(IMapView<double> resMap)
Parameters
Type Name Description
IMapView<System.Double> resMap

The resistance map to use for calculations.

Properties

| Improve this Doc View Source

CurrentSenseMap

IEnumerable of only positions currently "in" the SenseMap, eg. all positions that have a value other than 0.0.

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

Height

Height of sense map.

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

Item[Coord]

Returns the "sensory value" for the given position.

Declaration
public double this[Coord pos] { get; }
Parameters
Type Name Description
Coord pos

The position to return the sensory value for.

Property Value
Type Description
System.Double

The sensory value for the given position.

| Improve this Doc View Source

Item[Int32]

Returns the "sensory value" for the given position.

Declaration
public double this[int index1D] { get; }
Parameters
Type Name Description
System.Int32 index1D

Position to return the sensory value for, as a 1d-index-style value.

Property Value
Type Description
System.Double

The sense-map value for the given position.

| Improve this Doc View Source

Item[Int32, Int32]

Returns the "sensory value" for the given position.

Declaration
public double this[int x, int y] { get; }
Parameters
Type Name Description
System.Int32 x

X-coordinate of the position to return the sensory value for.

System.Int32 y

Y-coordinate of the position to return the sensory value for.

Property Value
Type Description
System.Double

The sensory value for the given position.

| Improve this Doc View Source

NewlyInSenseMap

IEnumerable of positions that DO have a non-zero value in the sense map as of the most current Calculate() call, but DID NOT have a non-zero value after the previous time Calculate() was called.

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

NewlyOutOfSenseMap

IEnumerable of positions that DO NOT have a non-zero value in the sense map as of the most current Calculate() call, but DID have a non-zero value after the previous time Calculate() was called.

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

SenseSources

Read-only list of all sources currently considered part of the SenseMap. Some may have their Enabled flag set to false, so all of these may or may not be counted when Calculate() is called.

Declaration
public IReadOnlyList<SenseSource> SenseSources { get; }
Property Value
Type Description
System.Collections.Generic.IReadOnlyList<SenseSource>
| Improve this Doc View Source

Width

Width of the sense map.

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

Methods

| Improve this Doc View Source

AddSenseSource(SenseSource)

Adds the given source to the list of sources. If the source has its Enabled flag set when Calculate() is next called, then it will be counted as a source.

Declaration
public void AddSenseSource(SenseSource senseSource)
Parameters
Type Name Description
SenseSource senseSource

The source to add.

| Improve this Doc View Source

AsReadOnly()

Returns a read-only representation of the SenseMap.

Declaration
public IReadOnlySenseMap AsReadOnly()
Returns
Type Description
IReadOnlySenseMap

This SenseMap object as IReadOnlySenseMap.

| Improve this Doc View Source

Calculate()

Calcuates the map. For each enabled source in the source list, it calculates the source's spreading, and puts them all together in the sense map's output.

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

GetEnumerator()

Enumerator, in case you want to use this as a list of doubles.

Declaration
public IEnumerator<double> GetEnumerator()
Returns
Type Description
System.Collections.Generic.IEnumerator<System.Double>

Enumerable of doubles (the sensory values).

| Improve this Doc View Source

RemoveSenseSource(SenseSource)

Removes the given source from the list of sources. Genearlly, use this if a source is permanently removed from a map. For temporary disabling, you should generally use the Enabled flag.

Declaration
public void RemoveSenseSource(SenseSource senseSource)
Parameters
Type Name Description
SenseSource senseSource

The source to remove.

Remarks

The source values that this sense source was responsible for are NOT removed from the sensory output values until Calculate() is next called.

| Improve this Doc View Source

ToString()

Returns a string representation of the map, where any location not in the SenseMap is represented by a '-' character, any position that is the center of some source is represented by a 'C' character, and any position that has a non-zero value but is not a center is represented by an 'S'.

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

A (multi-line) string representation of the SenseMap.

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

ToString(Char, Char, Char)

ToString that customizes the characters used to represent the map.

Declaration
public string ToString(char normal = '-', char center = 'C', char sourceValue = 'S')
Parameters
Type Name Description
System.Char normal

The character used for any location not in the SenseMap.

System.Char center

The character used for any location that is the center-point of a source.

System.Char sourceValue

The character used for any location that is in range of a source, but not a center point.

Returns
Type Description
System.String

The string representation of the SenseMap, using the specified characters.

| Improve this Doc View Source

ToString(Int32)

Returns a string representation of the map, with the actual values in the SenseMap, rounded to the given number of decimal places.

Declaration
public string ToString(int decimalPlaces)
Parameters
Type Name Description
System.Int32 decimalPlaces

The number of decimal places to round to.

Returns
Type Description
System.String

A string representation of the map, rounded to the given number of decimal places.

Explicit Interface Implementations

| Improve this Doc View Source

IEnumerable.GetEnumerator()

Generic enumerator.

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

Enumerator for looping.

Implements

IReadOnlySenseMap
System.Collections.Generic.IEnumerable<T>
System.Collections.IEnumerable
IMapView<T>

Extension Methods

Utility.ExtendToString<T>(IEnumerable<T>, String, Func<T, String>, String, String)
Utility.Yield<T>(T)
IMapViewExtensions.Bounds<T>(IMapView<T>)
IMapViewExtensions.Contains<T>(IMapView<T>, Int32, Int32)
IMapViewExtensions.Contains<T>(IMapView<T>, Coord)
IMapViewExtensions.ExtendToString<T>(IMapView<T>, String, String, Func<T, String>, String, String, String, String)
IMapViewExtensions.ExtendToString<T>(IMapView<T>, Int32, String, String, Func<T, String>, String, String, String, String)
IMapViewExtensions.Positions<T>(IMapView<T>)
IMapViewExtensions.RandomItem<T>(IMapView<T>, IGenerator)
IMapViewExtensions.RandomItem<T>(IMapView<T>, Func<Coord, T, Boolean>, IGenerator)
IMapViewExtensions.RandomPosition<T>(IMapView<T>, T, IGenerator)
IMapViewExtensions.RandomPosition<T>(IMapView<T>, IEnumerable<T>, IGenerator)
IMapViewExtensions.RandomPosition<T>(IMapView<T>, HashSet<T>, IGenerator)
IMapViewExtensions.RandomPosition<T>(IMapView<T>, IGenerator, T[])
IMapViewExtensions.RandomPosition<T>(IMapView<T>, Func<Coord, T, Boolean>, IGenerator)
IMapViewExtensions.RandomPosition<T>(IMapView<T>, IGenerator)
  • Improve this Doc
  • View Source
Back to top Generated by DocFX