Show / Hide Table of Contents

Class SenseMapBase

Base class that is convenient for creating custom implementations of the ISenseMap interface.

Inheritance
object
SenseMapBase
SenseMap
Implements
ISenseMap
IReadOnlySenseMap
Inherited Members
object.GetType()
object.MemberwiseClone()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: GoRogue.SenseMapping
Assembly: GoRogue.dll
Syntax
public abstract class SenseMapBase : ISenseMap, IReadOnlySenseMap
Remarks

This class implements much of the boilerplate code required to implement ISenseMap properly, making sure that the implementer has to implement only the minimal subset of functions and properties.

An implementer should implement OnCalculate() to perform the spread calculation for all sense sources and aggregate it into ResultView. Notably, the implementer SHOULD NOT call Reset() nor perform any equivalent functionality, and SHOULD NOT fire the Recalculated or SenseMapReset events. All of this is taken care of the the Calculate() function, which calls OnCalculate.

Implementers may specify a custom grid view to use a a result, and must also supply a resizing function in the constructor. This allows the sense map to resize the result view if the transparency view changes sizes. Typically, an array view along with a ArrayViewResizer(int, int, ISettableGridView<double>) as the resizer is sufficient.

Finally, the implementer must implement the CurrentSenseMap, NewlyInSenseMap, and NewlyOutOfSenseMap enumerables. This allows the implementer to control the method of tracking it.

Constructors

View Source

SenseMapBase(IGridView<double>, CustomResultViewWithResize?)

Constructor.

Declaration
protected SenseMapBase(IGridView<double> resistanceView, CustomResultViewWithResize? resultViewAndResizer = null)
Parameters
Type Name Description
IGridView<double> resistanceView

The resistance map to use for calculations.

CustomResultViewWithResize? resultViewAndResizer

The view in which SenseMap calculation results are stored, along with a method to use to resize it as needed.

If unspecified, an ArrayView will be used for the result view, and the resize function will allocate a new ArrayView of the appropriate size as needed. This should be sufficient for most use cases.

This function must return a view with all of its values set to 0.0, which has the given width and height.

Fields

View Source

ResultViewBacking

The actual grid view which is used to record results. Exposed publicly in a read-only fashion via ResultView.

Declaration
protected ISettableGridView<double> ResultViewBacking
Field Value
Type Description
ISettableGridView<double>
View Source

ResultViewResizer

The function to use to resize the ResultView if the resistance view changes sizes between calculate calls. The function should perform any necessary operations and return a grid view which is of the appropriate size.

The function must return a view with all values set to 0.0, which has the width and height given.

Declaration
protected Func<int, int, ISettableGridView<double>, ISettableGridView<double>> ResultViewResizer
Field Value
Type Description
Func<int, int, ISettableGridView<double>, ISettableGridView<double>>

Properties

View Source

CurrentSenseMap

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

Declaration
public abstract IEnumerable<Point> CurrentSenseMap { get; }
Property Value
Type Description
IEnumerable<Point>
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 abstract IEnumerable<Point> NewlyInSenseMap { get; }
Property Value
Type Description
IEnumerable<Point>
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 abstract IEnumerable<Point> NewlyOutOfSenseMap { get; }
Property Value
Type Description
IEnumerable<Point>
View Source

ResistanceView

The resistance map used to perform calculations.

Declaration
public IGridView<double> ResistanceView { get; }
Property Value
Type Description
IGridView<double>
View Source

ResultView

A view of the sense map's calculation results.

Declaration
public IGridView<double> ResultView { get; }
Property Value
Type Description
IGridView<double>
View Source

SenseSources

Read-only list of all sources currently considered part of the sense map. 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<ISenseSource> SenseSources { get; }
Property Value
Type Description
IReadOnlyList<ISenseSource>

Methods

View Source

AddSenseSource(ISenseSource)

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(ISenseSource senseSource)
Parameters
Type Name Description
ISenseSource senseSource

The source to add.

View Source

AsReadOnly()

Returns a read-only representation of the sensory map.

Declaration
public IReadOnlySenseMap AsReadOnly()
Returns
Type Description
IReadOnlySenseMap

This sensory map object as IReadOnlySenseMap.

View Source

Calculate()

Calculates 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()
View Source

OnCalculate()

Performs CalculateLight() on all sources, and aggregates their results into ResultViewBacking.

Declaration
protected abstract void OnCalculate()
Remarks

Custom implementations should implement this function to perform their calculation; the Calculate function calls reset first, then calls this, automatically firing relevant events.

View Source

RemoveSenseSource(ISenseSource)

Removes the given source from the list of sources. Generally, 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(ISenseSource senseSource)
Parameters
Type Name Description
ISenseSource 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.

View Source

Reset()

Resets the given sense map by erasing the current recorded result values.

Declaration
public virtual void Reset()
Remarks

After this function is called, any value in ResultView will be 0. Additionally,CurrentSenseMap will be blank.

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
string

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

Overrides
object.ToString()
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
char normal

The character used for any location not in the SenseMap.

char center

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

char sourceValue

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

Returns
Type Description
string

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

View Source

ToString(int)

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
int decimalPlaces

The number of decimal places to round to.

Returns
Type Description
string

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

Events

View Source

Recalculated

Fired whenever the SenseMap is recalculated.

Declaration
public event EventHandler? Recalculated
Event Type
Type Description
EventHandler
View Source

SenseMapReset

Fired when the existing SenseMap is reset prior to calculating a new one.

Declaration
public event EventHandler? SenseMapReset
Event Type
Type Description
EventHandler

Implements

ISenseMap
IReadOnlySenseMap

Extension Methods

Utility.Yield<T>(T)
  • View Source
In this article
Back to top Generated by DocFX