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
Implements
Inherited Members
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 SourceSenseMap(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 SourceCurrentSenseMap
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> |
Height
Height of sense map.
Declaration
public int Height { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
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. |
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. |
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. |
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> |
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> |
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> |
Width
Width of the sense map.
Declaration
public int Width { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
| Improve this Doc View SourceAddSenseSource(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. |
AsReadOnly()
Returns a read-only representation of the SenseMap.
Declaration
public IReadOnlySenseMap AsReadOnly()
Returns
Type | Description |
---|---|
IReadOnlySenseMap | This SenseMap object as IReadOnlySenseMap. |
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()
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). |
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.
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
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. |
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 SourceIEnumerable.GetEnumerator()
Generic enumerator.
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.IEnumerator | Enumerator for looping. |