Class FOVBase
Base class that is convenient for creating custom implementations of the IFOV interface.
Inherited Members
Namespace: GoRogue.FOV
Assembly: GoRogue.dll
Syntax
public abstract class FOVBase : IFOV, IReadOnlyFOV
Remarks
This class implements much of the boilerplate code required to implement IFOV properly, making sure that the implementer has to implement only the minimal subset of functions and properties.
An implementer should implement the OnCalculate overloads to perform their FOV calculation. Notably, these functions SHOULD NOT call Reset() nor perform any equivalent functionality, and SHOULD NOT fire the Recalculated or VisibilityReset events. All of this is taken care of by the Calculate and CalculateAppend functions, which call OnCalculate.
The implementation of OnCalculate, therefore, must not make any assumptions that squares start at a light level of 0, or any other light level. It should responsibly handle overlapping with other values, an assume that any value it does see at a location is a valid one. Therefore, the highest of the number currently present and the new number should always be kept.
Constructors
View SourceFOVBase(IGridView<bool>)
Constructor.
Declaration
protected FOVBase(IGridView<bool> transparencyView)
Parameters
Type | Name | Description |
---|---|---|
IGridView<bool> | transparencyView | The values used to calculate field of view. Values of true are considered non-blocking (transparent) to line of sight, while false values are considered to be blocking. |
Properties
View SourceBooleanResultView
A view of the calculation results in boolean form, where true indicates a location is in field of view, and false indicates it is not.
Declaration
public abstract IGridView<bool> BooleanResultView { get; }
Property Value
Type | Description |
---|---|
IGridView<bool> |
CalculationsPerformed
A list of the parameters passed to each call to Calculate/CalculateAppend that has been performed since the last reset, in the order in which they were called.
Declaration
public IReadOnlyList<FOVCalculateParameters> CalculationsPerformed { get; }
Property Value
Type | Description |
---|---|
IReadOnlyList<FOVCalculateParameters> |
CurrentFOV
IEnumerable of only positions currently in the field of view.
Declaration
public abstract IEnumerable<Point> CurrentFOV { get; }
Property Value
Type | Description |
---|---|
IEnumerable<Point> |
DoubleResultView
A view of the calculation results in double form, where a value greater than 0.0 indicates that the value is inside of FOV, and a value of 1.0 indicates the center point. All other values vary between 0.0 and 1.0, decreasing as positions get farther away from the center point.
Declaration
public abstract IGridView<double> DoubleResultView { get; }
Property Value
Type | Description |
---|---|
IGridView<double> |
NewlySeen
IEnumerable of positions that ARE in field of view as of the most current Calculate call, but were NOT in field of view after the previous time Calculate was called.
Declaration
public abstract IEnumerable<Point> NewlySeen { get; }
Property Value
Type | Description |
---|---|
IEnumerable<Point> |
NewlyUnseen
IEnumerable of positions that are NOT in field of view as of the most current Calculate call, but WERE in field of view after the previous time Calculate was called.
Declaration
public abstract IEnumerable<Point> NewlyUnseen { get; }
Property Value
Type | Description |
---|---|
IEnumerable<Point> |
TransparencyView
The values used to calculate field of view. Values of true are considered non-blocking (transparent) to line of sight, while false values are considered to be blocking.
Declaration
public IGridView<bool> TransparencyView { get; }
Property Value
Type | Description |
---|---|
IGridView<bool> |
Methods
View SourceAsReadOnly()
Returns a read-only representation of the field of view.
Declaration
public IReadOnlyFOV AsReadOnly()
Returns
Type | Description |
---|---|
IReadOnlyFOV | This FOV object, as an IReadOnlyFOV instance. |
Calculate(Point, double)
Calculates FOV given an origin point and a radius, overwriting the current FOV entirely. If no radius is specified, simply calculates with a radius of maximum integer value, which is effectively infinite. Radius is computed as a circle around the source (type Circle).
Declaration
public void Calculate(Point origin, double radius = 1.7976931348623157E+308)
Parameters
Type | Name | Description |
---|---|---|
Point | origin | Position of origin. |
double | radius | The maximum radius -- basically the maximum distance of the field of view if completely unobstructed. If no radius is specified, it is effectively infinite. |
Calculate(Point, double, Distance)
Calculates FOV given an origin point, a radius, and a radius shape, overwriting the current FOV entirely.
Declaration
public void Calculate(Point origin, double radius, Distance distanceCalc)
Parameters
Type | Name | Description |
---|---|---|
Point | origin | Coordinate of the origin. |
double | radius | The maximum radius -- basically the maximum distance of the field of view if completely unobstructed. |
Distance | distanceCalc | The distance calculation used to determine what shape the radius has (or a type implicitly convertible to Distance, eg. Radius). |
Calculate(Point, double, Distance, double, double)
Calculates FOV given an origin point, a radius, a radius shape, and the given field of view
restrictions angle
and span
. The current field of view will be
entirely overwritten with the new one. The resulting field of view,
if unobstructed, will be a cone defined by the angle and span given.
Declaration
public void Calculate(Point origin, double radius, Distance distanceCalc, double angle, double span)
Parameters
Type | Name | Description |
---|---|---|
Point | origin | Coordinate of the origin. |
double | radius | The maximum radius -- basically the maximum distance of the field of view if completely unobstructed. |
Distance | distanceCalc | The distance calculation used to determine what shape the radius has (or a type implicitly convertible to Distance, eg. Radius). |
double | angle | The angle in degrees that specifies the outermost center point of the field of view cone. 0 degrees points up, and angle increases result in the cone moving clockwise (like a compass). |
double | span | The angle, in degrees, that specifies the full arc contained in the field of view cone --
|
Calculate(int, int, double)
Calculates FOV given an origin point and a radius, overwriting the current FOV entirely. If no radius is specified, simply calculates with a radius of maximum integer value, which is effectively infinite. Radius is computed as a circle around the source (type Circle).
Declaration
public void Calculate(int originX, int originY, double radius = 1.7976931348623157E+308)
Parameters
Type | Name | Description |
---|---|---|
int | originX | Coordinate x-value of the origin. |
int | originY | Coordinate y-value of the origin. |
double | radius | The maximum radius -- basically the maximum distance of the field of view if completely unobstructed. If no radius is specified, it is effectively infinite. |
Calculate(int, int, double, Distance)
Calculates FOV given an origin point, a radius, and radius shape, overwriting the current FOV entirely.
Declaration
public void Calculate(int originX, int originY, double radius, Distance distanceCalc)
Parameters
Type | Name | Description |
---|---|---|
int | originX | Coordinate x-value of the origin. |
int | originY | Coordinate y-value of the origin. |
double | radius | The maximum radius -- basically the maximum distance of the field of view if completely unobstructed. |
Distance | distanceCalc | The distance calculation used to determine what shape the radius has (or a type implicitly convertible to Distance, eg. Radius). |
Calculate(int, int, double, Distance, double, double)
Calculates FOV given an origin point, a radius, a radius shape, and the given field of view
restrictions angle
and span
. The current field of view will be
entirely overwritten with the new one. The resulting field of view, if unobstructed, will be a cone defined
by the angle and span given.
Declaration
public void Calculate(int originX, int originY, double radius, Distance distanceCalc, double angle, double span)
Parameters
Type | Name | Description |
---|---|---|
int | originX | Coordinate x-value of the origin. |
int | originY | Coordinate y-value of the origin. |
double | radius | The maximum radius -- basically the maximum distance of the field of view if completely unobstructed. |
Distance | distanceCalc | The distance calculation used to determine what shape the radius has (or a type implicitly convertible to Distance, eg. Radius). |
double | angle | The angle in degrees that specifies the outermost center point of the field of view cone. 0 degrees points up, and angle increases result in the cone moving clockwise (like a compass). |
double | span | The angle, in degrees, that specifies the full arc contained in the field of view cone --
|
CalculateAppend(Point, double)
Calculates FOV given an origin point and a radius, adding the result onto the currently visible cells. If no radius is specified, simply calculates with a radius of maximum integer value, which is effectively infinite. Radius is computed as a circle around the source (type Circle).
Declaration
public void CalculateAppend(Point origin, double radius = 1.7976931348623157E+308)
Parameters
Type | Name | Description |
---|---|---|
Point | origin | Position of origin. |
double | radius | The maximum radius -- basically the maximum distance of the field of view if completely unobstructed. If no radius is specified, it is effectively infinite. |
CalculateAppend(Point, double, Distance)
Calculates FOV given an origin point, a radius, and a radius shape, , adding the result onto the currently visible cells.
Declaration
public void CalculateAppend(Point origin, double radius, Distance distanceCalc)
Parameters
Type | Name | Description |
---|---|---|
Point | origin | Coordinate of the origin. |
double | radius | The maximum radius -- basically the maximum distance of the field of view if completely unobstructed. |
Distance | distanceCalc | The distance calculation used to determine what shape the radius has (or a type implicitly convertible to Distance, eg. Radius). |
CalculateAppend(Point, double, Distance, double, double)
Calculates FOV given an origin point, a radius, a radius shape, and the given field of view
restrictions angle
and span
. The new field of view will be
added onto the current one. The resulting field of view, if unobstructed, will be a cone defined by the
angle and span given.
Declaration
public void CalculateAppend(Point origin, double radius, Distance distanceCalc, double angle, double span)
Parameters
Type | Name | Description |
---|---|---|
Point | origin | Coordinate of the origin. |
double | radius | The maximum radius -- basically the maximum distance of the field of view if completely unobstructed. |
Distance | distanceCalc | The distance calculation used to determine what shape the radius has (or a type implicitly convertible to Distance, eg. Radius). |
double | angle | The angle in degrees that specifies the outermost center point of the field of view cone. 0 degrees points up, and angle increases result in the cone moving clockwise (like a compass). |
double | span | The angle, in degrees, that specifies the full arc contained in the field of view cone --
|
CalculateAppend(int, int, double)
Calculates FOV given an origin point and a radius, adding the result onto the currently visible cells. If no radius is specified, simply calculates with a radius of maximum integer value, which is effectively infinite. Radius is computed as a circle around the source (type Circle).
Declaration
public void CalculateAppend(int originX, int originY, double radius = 1.7976931348623157E+308)
Parameters
Type | Name | Description |
---|---|---|
int | originX | Coordinate x-value of the origin. |
int | originY | Coordinate y-value of the origin. |
double | radius | The maximum radius -- basically the maximum distance of the field of view if completely unobstructed. If no radius is specified, it is effectively infinite. |
CalculateAppend(int, int, double, Distance)
Calculates FOV given an origin point, a radius, and radius shape, adding the result onto the currently visible cells.
Declaration
public void CalculateAppend(int originX, int originY, double radius, Distance distanceCalc)
Parameters
Type | Name | Description |
---|---|---|
int | originX | Coordinate x-value of the origin. |
int | originY | Coordinate y-value of the origin. |
double | radius | The maximum radius -- basically the maximum distance of the field of view if completely unobstructed. |
Distance | distanceCalc | The distance calculation used to determine what shape the radius has (or a type implicitly convertible to Distance, eg. Radius). |
CalculateAppend(int, int, double, Distance, double, double)
Calculates FOV given an origin point, a radius, a radius shape, and the given field of view
restrictions angle
and span
. The new field of view will be
added onto the current one. The resulting field of view, if unobstructed, will be a cone defined
by the angle and span given.
Declaration
public void CalculateAppend(int originX, int originY, double radius, Distance distanceCalc, double angle, double span)
Parameters
Type | Name | Description |
---|---|---|
int | originX | Coordinate x-value of the origin. |
int | originY | Coordinate y-value of the origin. |
double | radius | The maximum radius -- basically the maximum distance of the field of view if completely unobstructed. |
Distance | distanceCalc | The distance calculation used to determine what shape the radius has (or a type implicitly convertible to Distance, eg. Radius). |
double | angle | The angle in degrees that specifies the outermost center point of the field of view cone. 0 degrees points up, and angle increases result in the cone moving clockwise (like a compass). |
double | span | The angle, in degrees, that specifies the full arc contained in the field of view cone --
|
OnCalculate(int, int, double, Distance)
Calculates FOV given an origin point, a radius, and radius shape.
Declaration
protected abstract void OnCalculate(int originX, int originY, double radius, Distance distanceCalc)
Parameters
Type | Name | Description |
---|---|---|
int | originX | Coordinate x-value of the origin. |
int | originY | Coordinate y-value of the origin. |
double | radius | The maximum radius -- basically the maximum distance of the field of view if completely unobstructed. |
Distance | distanceCalc | The distance calculation used to determine what shape the radius has (or a type implicitly convertible to Distance, eg. Radius). |
Remarks
Custom implementations would implement this function to perform their calculation; the Calculate functions call this then fire relevant events.
OnCalculate(int, int, double, Distance, double, double)
Calculates FOV given an origin point, a radius, a radius shape, and the given field of view
restrictions angle
and span
. The resulting field of view,
if unobstructed, will be a cone defined by the angle and span given.
Declaration
protected abstract void OnCalculate(int originX, int originY, double radius, Distance distanceCalc, double angle, double span)
Parameters
Type | Name | Description |
---|---|---|
int | originX | Coordinate x-value of the origin. |
int | originY | Coordinate y-value of the origin. |
double | radius | The maximum radius -- basically the maximum distance of the field of view if completely unobstructed. |
Distance | distanceCalc | The distance calculation used to determine what shape the radius has (or a type implicitly convertible to Distance, eg. Radius). |
double | angle | The angle in degrees that specifies the outermost center point of the field of view cone. 0 degrees points up, and angle increases result in the cone moving clockwise (like a compass). |
double | span | The angle, in degrees, that specifies the full arc contained in the field of view cone --
|
Remarks
Custom implementations would implement this function to perform their calculation; the Calculate functions call this then fire relevant events.
OnReset()
Resets all cells to not visible, and cycles current FOV to previous FOV, allowing a fresh set of calculations to begin.
Declaration
protected abstract void OnReset()
Remarks
This is (indirectly) called automatically by all Calculate overloads. Custom implementations should implement this to reset their ResultView to all 0's in a way appropriate for their architecture, as well as cycle the current FOV to the previous FOV to prepare for a fresh FOV calculation. Reset() also calls this function, along with firing relevant events.
Reset()
Resets the given field of view to no tiles visible.
Declaration
public void Reset()
Remarks
After this function is called, any value in DoubleResultView will be 0, and any value in BooleanResultView will be false. Additionally, CurrentFOV will be blank.
ToString()
Returns a string representation of the map, where any location not in FOV is represented by a '-' character, and any position in FOV is represented by a '+'.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | A (multi-line) string representation of the FOV. |
Overrides
View SourceToString(char, char)
ToString overload that customizes the characters used to represent the map.
Declaration
public string ToString(char normal = '-', char sourceValue = '+')
Parameters
Type | Name | Description |
---|---|---|
char | normal | The character used for any location not in FOV. |
char | sourceValue | The character used for any location that is in FOV. |
Returns
Type | Description |
---|---|
string | The string representation of FOV, using the specified characters. |
ToString(int)
Returns a string representation of the map, with the actual values in the FOV, 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 FOV, rounded to the given number of decimal places. |
Events
View SourceRecalculated
Fired whenever the FOV is recalculated.
Declaration
public event EventHandler<FOVRecalculatedEventArgs>? Recalculated
Event Type
Type | Description |
---|---|
EventHandler<FOVRecalculatedEventArgs> |
VisibilityReset
Fired when the existing FOV is reset prior to calculating a new one.
Declaration
public event EventHandler? VisibilityReset
Event Type
Type | Description |
---|---|
EventHandler |