Class SenseSourceBase
A base class for creating ISenseSource implementations that boils an implementation down to primarily implementing the OnCalculate() function.
Implements
Inherited Members
Namespace: GoRogue.SenseMapping.Sources
Assembly: GoRogue.dll
Syntax
public abstract class SenseSourceBase : ISenseSource
Remarks
This class uses an ArrayView as the ResultView, in order to enable common functions efficiently. Use cases for a custom view here should be relatively limited, as the view must be settable and resizable; if a custom implementation is needed, you may implement ISenseSource directly.
Constructors
View SourceSenseSourceBase(Point, double, Distance, double)
Creates a source which spreads outwards in all directions.
Declaration
protected SenseSourceBase(Point position, double radius, Distance distanceCalc, double intensity = 1)
Parameters
Type | Name | Description |
---|---|---|
Point | position | The position on a map that the source is located at. |
double | radius | The maximum radius of the source -- this is the maximum distance the source values will emanate, provided the area is completely unobstructed. |
Distance | distanceCalc | The distance calculation used to determine what shape the radius has (or a type implicitly convertible to Distance, such as Radius). |
double | intensity | The starting intensity value of the source. Defaults to 1.0. |
SenseSourceBase(Point, double, Distance, double, double, double)
Constructor. Creates a source which spreads only in a cone defined by the given angle and span.
Declaration
protected SenseSourceBase(Point position, double radius, Distance distanceCalc, double angle, double span, double intensity = 1)
Parameters
Type | Name | Description |
---|---|---|
Point | position | The position on a map that the source is located at. |
double | radius | The maximum radius of the source -- this is the maximum distance the source values will emanate, provided the area is completely unobstructed. |
Distance | distanceCalc | The distance calculation used to determine what shape the radius has (or a type implicitly convertible to Distance, such as Radius). |
double | angle | The angle in degrees that specifies the outermost center point of the cone formed by the source's values. 0 degrees points right. |
double | span | The angle, in degrees, that specifies the full arc contained in the cone formed by the source's values --
|
double | intensity | The starting intensity value of the source. Defaults to 1.0. |
SenseSourceBase(int, int, double, Distance, double)
Creates a source which spreads outwards in all directions.
Declaration
protected SenseSourceBase(int positionX, int positionY, double radius, Distance distanceCalc, double intensity = 1)
Parameters
Type | Name | Description |
---|---|---|
int | positionX | The X-value of the position on a map that the source is located at. |
int | positionY | The Y-value of the position on a map that the source is located at. |
double | radius | The maximum radius of the source -- this is the maximum distance the source values will emanate, provided the area is completely unobstructed. |
Distance | distanceCalc | The distance calculation used to determine what shape the radius has (or a type implicitly convertible to Distance, such as Radius). |
double | intensity | The starting intensity value of the source. Defaults to 1.0. |
SenseSourceBase(int, int, double, Distance, double, double, double)
Constructor. Creates a source which spreads only in a cone defined by the given angle and span.
Declaration
protected SenseSourceBase(int positionX, int positionY, double radius, Distance distanceCalc, double angle, double span, double intensity = 1)
Parameters
Type | Name | Description |
---|---|---|
int | positionX | The x-value for the position on a map that the source is located at. |
int | positionY | The y-value for the position on a map that the source is located at. |
double | radius | The maximum radius of the source -- this is the maximum distance the source values will emanate, provided the area is completely unobstructed. |
Distance | distanceCalc | The distance calculation used to determine what shape the radius has (or a type implicitly convertible to Distance, such as Radius). |
double | angle | The angle in degrees that specifies the outermost center point of the cone formed by the source's values. 0 degrees points right. |
double | span | The angle, in degrees, that specifies the full arc contained in the cone formed by the source's values --
|
double | intensity | The starting intensity value of the source. Defaults to 1.0. |
Fields
View SourceAngleInternal
The Angle value, but offset 90 degrees clockwise; ie, 0 points right instead of up. This value typically works better for actual light calculations (as the definition more closely matches the unit circle).
Declaration
protected double AngleInternal
Field Value
Type | Description |
---|---|
double |
Center
The coordinate which will be the center point of the result view, ie. the center is (Center, Center).
Declaration
protected int Center
Field Value
Type | Description |
---|---|
int |
Remarks
This is equivalent to Size / 2; however is cached for performance and convenience since this calculation is performed frequently.
ResultViewBacking
The result view used to record results.
Declaration
protected ArrayView<double> ResultViewBacking
Field Value
Type | Description |
---|---|
ArrayView<double> |
Size
The size of the result view (eg. it's width and height); cached for efficiency and convenience.
Declaration
protected int Size
Field Value
Type | Description |
---|---|
int |
Properties
View SourceAngle
If IsAngleRestricted is true, the angle in degrees that represents a line from the source's start to the outermost center point of the cone formed by the source's calculated values. 0 degrees points up, and increases in angle move clockwise (like a compass). Otherwise, this will be 0.0 degrees.
Declaration
public double Angle { get; set; }
Property Value
Type | Description |
---|---|
double |
Decay
The amount of decrease in sense source value per unit of distance. Calculated automatically as a product of Intensity and Radius.
Declaration
public double Decay { get; }
Property Value
Type | Description |
---|---|
double |
DistanceCalc
The distance calculation used to determine what shape the radius has (or a type implicitly convertible to Distance, such as Radius).
Declaration
public Distance DistanceCalc { get; set; }
Property Value
Type | Description |
---|---|
Distance |
Enabled
Whether or not this source is enabled. If a source is disabled when Calculate() is called, the source does not calculate values and is effectively assumed to be "off".
Declaration
public bool Enabled { get; set; }
Property Value
Type | Description |
---|---|
bool |
Intensity
The starting value of the source to spread. Defaults to 1.0.
Declaration
public double Intensity { get; set; }
Property Value
Type | Description |
---|---|
double |
IsAngleRestricted
Whether or not the spreading of values from this source is restricted to an angle and span.
Declaration
public bool IsAngleRestricted { get; set; }
Property Value
Type | Description |
---|---|
bool |
Position
The position on a map that the source is located at.
Declaration
public ref Point Position { get; }
Property Value
Type | Description |
---|---|
Point |
Radius
The maximum radius of the source -- this is the maximum distance the source values will emanate, provided the area is completely unobstructed. Changing this will trigger resizing (re-allocation) of the underlying arrays.
Declaration
public double Radius { get; set; }
Property Value
Type | Description |
---|---|
double |
ResistanceView
The resistance map used to perform calculations.
Declaration
public IGridView<double>? ResistanceView { get; }
Property Value
Type | Description |
---|---|
IGridView<double> |
Remarks
Sense map implementations will set this to the sense map's resistance map prior to calculating. This can be set via SetResistanceMap(IGridView<double>?), but you shouldn't do this unless you're creating a custom sense map implementation.
ResultView
A grid view representing the result of a sense map calculation.
Declaration
public IGridView<double> ResultView { get; }
Property Value
Type | Description |
---|---|
IGridView<double> |
Span
If IsAngleRestricted is true, the angle in degrees that represents the full arc of the cone formed by the source's calculated values. Otherwise, it will be 360 degrees.
Declaration
public double Span { get; set; }
Property Value
Type | Description |
---|---|
double |
Methods
View SourceCalculateLight()
Perform the lighting calculations if the source is enabled, by first clearing results of the existing calculation, then re-calculating it by calling OnCalculate().
Declaration
public void CalculateLight()
OnCalculate()
Performs the actual spreading calculation.
Declaration
public abstract void OnCalculate()
Reset()
Resets calculation state so a new set of calculations can begin.
Declaration
protected virtual void Reset()
SetResistanceMap(IGridView<double>?)
Should ONLY be called from SenseMap or equivalent implementations. Sets the resistance map used by the source for calculations.
Declaration
public void SetResistanceMap(IGridView<double>? resMap)
Parameters
Type | Name | Description |
---|---|---|
IGridView<double> | resMap |
ToString()
Returns a string representation of the configuration of this SenseSource.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | A string representation of the configuration of this SenseSource. |
Overrides
Events
View SourceRadiusChanged
Fired when the radius of the source changes.
Declaration
public event EventHandler? RadiusChanged
Event Type
Type | Description |
---|---|
EventHandler |