Class FOV
Implements the capability to calculate a grid-based field of view for a map.
Inheritance
Inherited Members
Namespace: GoRogue
Assembly: GoRogue.dll
Syntax
public class FOV : IReadOnlyFOV, IMapView<double>
Remarks
Generally, this class can be used to calculate and expose the results of a field of view calculation for a map. In includes many options pertaining to the shape and size of the field of view (including options for an infinite-radius field of view). As well, for non-infinite size fields of view, the result contains built-in linear distance falloff for the sake of creating lighting/color/fidelity differences based on distance from the center.
Like most GoRogue algorithms, FOV takes as a construction parameter an IMapView representing the map. Specifically, it takes an IMapView<T>, where true indicates that a tile should be considered transparent, eg. not blocking to line of sight, and false indicates that a tile should be considered opaque, eg. blocking to line of sight.
The field of view can then be calculated by calling one of the various Calculate overloads.
The result of the calculation is exposed in two different forms. First, the values are exposed to you via indexers -- the FOV class itself implements IMapView<T>, where a value of 1.0 represents the center of the field of view calculation, and 0.0 indicates a location that is not inside the resulting field of view at all. Values in between are representative of linear falloff based on distance from the source.
Alternatievly, if the distance from the source is irrelevant, FOV also provides the result of the calculation via BooleanFOV, which is an IMapView<T> where a value of true indicates that a location is within field of view, and a value of false indicates it is ouside of the field of view.
Constructors
| Improve this Doc View SourceFOV(IMapView<Boolean>)
Constructor.
Declaration
public FOV(IMapView<bool> fovMap)
Parameters
Type | Name | Description |
---|---|---|
IMapView<System.Boolean> | fovMap | 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
| Improve this Doc View SourceBooleanFOV
A view of the calculation results in boolean form, where true indicates a location is inside field of view, and false indicates it is not.
Declaration
public IMapView<bool> BooleanFOV { get; }
Property Value
Type | Description |
---|---|
IMapView<System.Boolean> |
CurrentFOV
IEnumerable of only positions that are currently inside field of view.
Declaration
public IEnumerable<Coord> CurrentFOV { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<Coord> |
Height
Height of the map view.
Declaration
public int Height { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Item[Coord]
Returns the field of view value for the given position.
Declaration
public double this[Coord position] { get; }
Parameters
Type | Name | Description |
---|---|---|
Coord | position | The position to return the field of view value for. |
Property Value
Type | Description |
---|---|
System.Double | The field of view value for the given position. |
Item[Int32]
Returns the field of view value for the given position.
Declaration
public double this[int index1D] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index1D | Position to return the field of view value for, as a 1D-index-style value. |
Property Value
Type | Description |
---|---|
System.Double | The field of view value for the given position. |
Item[Int32, Int32]
Returns the field of view 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 FOV value for. |
System.Int32 | y | Y-coordinate of the position to return the FOV value for. |
Property Value
Type | Description |
---|---|
System.Double | The field of view value for the given position. |
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 IEnumerable<Coord> NewlySeen { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<Coord> |
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 IEnumerable<Coord> NewlyUnseen { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<Coord> |
Width
Width of map view.
Declaration
public int Width { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
| Improve this Doc 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(Coord, Double)
Calculates FOV given an origin point and a radius. 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(Coord start, double radius = 1.7976931348623157E+308)
Parameters
Type | Name | Description |
---|---|---|
Coord | start | Position of origin. |
System.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(Coord, Double, Distance)
Calculates FOV given an origin point, a radius, and a radius shape.
Declaration
public void Calculate(Coord start, double radius, Distance distanceCalc)
Parameters
Type | Name | Description |
---|---|---|
Coord | start | Coordinate of the origin. |
System.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(Coord, 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
public void Calculate(Coord start, double radius, Distance distanceCalc, double angle, double span)
Parameters
Type | Name | Description |
---|---|---|
Coord | start | Coordinate of the origin. |
System.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). |
System.Double | angle | The angle in degrees that specifies the outermost center point of the field of view cone. 0 degrees points right. |
System.Double | span | The angle, in degrees, that specifies the full arc contained in the field of view cone --
|
Calculate(Int32, Int32, Double)
Calculates FOV given an origin point and a radius. 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 startX, int startY, double radius = 1.7976931348623157E+308)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | startX | Coordinate x-value of the origin. |
System.Int32 | startY | Coordinate y-value of the origin. |
System.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(Int32, Int32, Double, Distance)
Calculates FOV given an origin point, a radius, and radius shape.
Declaration
public void Calculate(int startX, int startY, double radius, Distance distanceCalc)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | startX | Coordinate x-value of the origin. |
System.Int32 | startY | Coordinate y-value of the origin. |
System.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(Int32, Int32, 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
public void Calculate(int startX, int startY, double radius, Distance distanceCalc, double angle, double span)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | startX | Coordinate x-value of the origin. |
System.Int32 | startY | Coordinate y-value of the origin. |
System.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). |
System.Double | angle | The angle in degrees that specifies the outermost center point of the field of view cone. 0 degrees points right. |
System.Double | span | The angle, in degrees, that specifies the full arc contained in the field of view cone --
|
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 |
---|---|
System.String | A (multi-line) string representation of the FOV. |
Overrides
ToString(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 |
---|---|---|
System.Char | normal | The character used for any location not in FOV. |
System.Char | sourceValue | The character used for any location that is in FOV. |
Returns
Type | Description |
---|---|
System.String | The string representation of FOV, using the specified characters. |
ToString(Int32)
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 |
---|---|---|
System.Int32 | decimalPlaces | The number of decimal places to round to. |
Returns
Type | Description |
---|---|
System.String | A string representation of FOV, rounded to the given number of decimal places. |