public class FOV
extends java.lang.Object
implements java.io.Serializable
generateResistances(char[][])
method, which uses defaults for common chars used in SquidLib, but you may
also want to create a resistance map manually if a given char means something
very different in your game. This is easy enough to do by looping over all the
x,y positions in your char[][] map and running a switch statement on each char,
assigning a double to the same x,y position in a double[][]. The value should
be between 0.0 (unblocked) for things light passes through, 1.0 (blocked) for
things light can't pass at all, and possibly other values if you have
translucent obstacles. There's generateSimpleResistances(char[][])
as
well, which only returns 1.0 (fully blocked) or 0.0 (passable), and 3x3 subcell
variants, which produce a resistance map that is 3 times wider and 3 times
taller than the input map. The subcell variants have especially useful behavior
when using DungeonUtility.hashesToLines(char[][])
to draw a map with
box-drawing characters, since these 3x3 resistance maps will line up blocking
cells to where a box-drawing line is.
Modifier and Type | Field and Description |
---|---|
protected static Direction[] |
ccw |
protected static Direction[] |
ccw_full |
protected double[][] |
light
Data allocated in the previous calls to the public API, if any.
|
protected GreasedRegion |
nearLight
Data allocated in the previous calls to the public API, if any.
|
static int |
RIPPLE
Performs FOV by pushing values outwards from the source location.
|
static int |
RIPPLE_LOOSE
Performs FOV by pushing values outwards from the source location.
|
static int |
RIPPLE_TIGHT
Performs FOV by pushing values outwards from the source location.
|
static int |
RIPPLE_VERY_LOOSE
Performs FOV by pushing values outwards from the source location.
|
static int |
SHADOW
Uses Shadow Casting FOV algorithm.
|
Constructor and Description |
---|
FOV()
Creates a solver which will use the default SHADOW solver.
|
FOV(int type)
Creates a solver which will use the provided FOV solver type, typically one of
SHADOW (the default),
RIPPLE , RIPPLE_TIGHT , RIPPLE_LOOSE , or RIPPLE_VERY_LOOSE . |
Modifier and Type | Method and Description |
---|---|
static double[][] |
addFOVs(double[][]... maps)
Adds multiple FOV maps together in the simplest way possible; does not check line-of-sight between FOV maps.
|
static double[][] |
addFOVs(java.lang.Iterable<double[][]> maps)
Adds multiple FOV maps together in the simplest way possible; does not check line-of-sight between FOV maps.
|
static double[][] |
addFOVsInto(double[][] basis,
double[][]... maps)
Adds multiple FOV maps to basis cell-by-cell, modifying basis; does not check line-of-sight between FOV maps.
|
static double[][] |
addFOVsInto(double[][] basis,
double[][] addend)
Adds an FOV map to another in the simplest way possible; does not check line-of-sight between FOV maps.
|
static double[][] |
bouncingLine(double[][] resistanceMap,
double[][] light,
int startX,
int startY,
double distance,
double angle)
Reuses the existing light 2D array and fills it with a straight-line bouncing path of light that reflects its way
through the given resistanceMap from startX, startY until it uses up the given distance.
|
static double[][] |
calculateFOV(double[][] resistanceMap,
double[][] light,
int startx,
int starty)
Calculates the Field Of View for the provided map from the given x, y
coordinates.
|
double[][] |
calculateFOV(double[][] resistanceMap,
int startx,
int starty)
Calculates the Field Of View for the provided map from the given x, y
coordinates.
|
double[][] |
calculateFOV(double[][] resistanceMap,
int startx,
int starty,
double radius)
Calculates the Field Of View for the provided map from the given x, y
coordinates.
|
double[][] |
calculateFOV(double[][] resistanceMap,
int startX,
int startY,
double radius,
Radius radiusTechnique)
Calculates the Field Of View for the provided map from the given x, y
coordinates.
|
double[][] |
calculateFOV(double[][] resistanceMap,
int startX,
int startY,
double radius,
Radius radiusTechnique,
double angle,
double span)
Calculates the Field Of View for the provided map from the given x, y
coordinates.
|
double[][] |
calculateLOSMap(double[][] resistanceMap,
int startX,
int startY)
Calculates what cells are visible from (startX,startY) using the given resistanceMap; this can be given to
mixVisibleFOVs() to limit extra light sources to those visible from the starting point.
|
static double[][] |
generateResistances(char[][] map)
Given a char[][] for the map, produces a double[][] that can be used with most of the methods in FOV, like
reuseFOV(double[][], double[][], int, int, double) . |
static double[][] |
generateResistances3x3(char[][] map)
Given a char[][] for the map that should use box drawing characters (as produced by
DungeonUtility.hashesToLines(char[][], boolean) ), produces a double[][] with triple width and triple
height that can be used with FOV methods like reuseFOV(double[][], double[][], int, int, double) in
classes that use subcell lighting. |
static double[][] |
generateSimpleResistances(char[][] map)
Given a char[][] for the map, produces a double[][] that can be used with any FOV methods that expect a
resistance map (like
reuseFOV(double[][], double[][], int, int, double) ), but does not treat
any cells as partly transparent, only fully-blocking or fully-permitting light. |
static double[][] |
generateSimpleResistances3x3(char[][] map)
Given a char[][] for the map that should use box drawing characters (as produced by
DungeonUtility.hashesToLines(char[][], boolean) ), produces a double[][] with triple width and triple
height that can be used with FOV's methods that expect a resistance map (like
reuseFOV(double[][], double[][], int, int, double) ) in classes that use subcell lighting. |
static double[][] |
mixVisibleFOVs(double[][] losMap,
double[][]... maps)
Adds together multiple FOV maps, but only adds to a position if it is visible in the given LOS map.
|
static double[][] |
mixVisibleFOVs(double[][] losMap,
java.lang.Iterable<double[][]> maps)
Adds together multiple FOV maps, but only adds to a position if it is visible in the given LOS map.
|
static double[][] |
mixVisibleFOVsInto(double[][] losMap,
double[][] basis,
double[][]... maps)
Adds together multiple FOV maps, but only adds to a position if it is visible in the given LOS map.
|
static boolean |
reachable(int startX,
int startY,
int targetX,
int targetY,
double[][] resistanceMap)
Checks whether the starting point can see the target point, using the
maxLength and resistanceMap
to determine whether the line of sight is obstructed, without storing the line of points along the way. |
static boolean |
reachableOrtho(int startX,
int startY,
int targetX,
int targetY,
double[][] resistanceMap)
Checks whether the starting point can see the target point, using the
maxLength and resistanceMap
to determine whether the line of sight is obstructed, without storing the line of points along the way. |
static boolean |
reachablePermissive(int startX,
int startY,
int targetX,
int targetY,
double[][] resistanceMap) |
static double[][] |
reuseBurstFOV(double[][] resistanceMap,
double[][] light,
int rippleLooseness,
int x,
int y,
double radius,
Radius radiusTechnique) |
static double[][] |
reuseFOV(double[][] resistanceMap,
double[][] light,
int startx,
int starty)
Calculates the Field Of View for the provided map from the given x, y
coordinates.
|
static double[][] |
reuseFOV(double[][] resistanceMap,
double[][] light,
int startx,
int starty,
double radius)
Calculates the Field Of View for the provided map from the given x, y
coordinates.
|
static double[][] |
reuseFOV(double[][] resistanceMap,
double[][] light,
int startX,
int startY,
double radius,
Radius radiusTechnique)
Calculates the Field Of View for the provided map from the given x, y
coordinates.
|
static double[][] |
reuseFOV(double[][] resistanceMap,
double[][] light,
int startX,
int startY,
double radius,
Radius radiusTechnique,
double angle,
double span)
Calculates the Field Of View for the provided map from the given x, y
coordinates, lighting at the given angle in degrees and covering a span
centered on that angle, also in degrees.
|
static double[][] |
reuseFOV(double[][] resistanceMap,
double[][] light,
int startX,
int startY,
double radius,
Radius radiusTechnique,
double angle,
double forward,
double sideForward,
double side,
double sideBack,
double back)
Calculates the Field Of View for the provided map from the given x, y
coordinates, lighting with the view "pointed at" the given
angle in degrees,
extending to different ranges based on the direction the light is traveling. |
static double[][] |
reuseFOVLinear(double[][] resistanceMap,
double[][] light,
int startX,
int startY,
double radius,
Radius radiusTechnique,
LOS los) |
static double[][] |
reuseFOVSymmetrical(double[][] resistanceMap,
double[][] light,
int startX,
int startY,
double radius,
Radius radiusTechnique)
Calculates the symmetrical Field Of View for the provided resistanceMap from the given x, y viewer
coordinates.
|
static double[][] |
reuseLOS(double[][] resistanceMap,
double[][] light,
int startX,
int startY)
Calculates which cells have line of sight from the given x, y coordinates.
|
static double[][] |
reuseLOS(double[][] resistanceMap,
double[][] light,
int startX,
int startY,
int minX,
int minY,
int maxX,
int maxY)
Calculates which cells have line of sight from the given x, y coordinates.
|
static GreasedRegion |
reuseLOS(GreasedRegion blockingMap,
GreasedRegion light,
int startX,
int startY)
Calculates which cells have line of sight from the given x, y coordinates.
|
static GreasedRegion |
reuseLOS(GreasedRegion blockingMap,
GreasedRegion light,
int startX,
int startY,
int minX,
int minY,
int maxX,
int maxY)
Calculates which cells have line of sight from the given x, y coordinates.
|
static double[][] |
reuseRippleFOV(double[][] resistanceMap,
double[][] light,
int x,
int y,
double radius,
Radius radiusTechnique)
Like the
reuseFOV(double[][], double[][], int, int, double, Radius) method, but this uses Ripple FOV
with a tightness/looseness equal to 2. |
static double[][] |
reuseRippleFOV(double[][] resistanceMap,
double[][] light,
int rippleLooseness,
int x,
int y,
double radius,
Radius radiusTechnique)
Like the
reuseFOV(double[][], double[][], int, int, double, Radius) method, but this uses Ripple FOV
with a configurable tightness/looseness (between 1, tightest, and 6, loosest). |
static double[][] |
reuseRippleFOV(double[][] resistanceMap,
double[][] light,
int rippleLooseness,
int x,
int y,
double radius,
Radius radiusTechnique,
double angle,
double span)
Like the
reuseFOV(double[][], double[][], int, int, double, Radius, double, double) method, but this
uses Ripple FOV with a configurable tightness/looseness (between 1, tightest, and 6, loosest). |
public static final int RIPPLE
rippleLooseness
of 2 in reuseRippleFOV(double[][], double[][], int, int, int, double, Radius)
.public static final int RIPPLE_LOOSE
rippleLooseness
of 3
in reuseRippleFOV(double[][], double[][], int, int, int, double, Radius)
.public static final int RIPPLE_TIGHT
rippleLooseness
of 1 in reuseRippleFOV(double[][], double[][], int, int, int, double, Radius)
.public static final int RIPPLE_VERY_LOOSE
rippleLooseness
of 6 in reuseRippleFOV(double[][], double[][], int, int, int, double, Radius)
.public static final int SHADOW
protected double[][] light
protected GreasedRegion nearLight
protected static final Direction[] ccw
protected static final Direction[] ccw_full
public FOV()
public FOV(int type)
SHADOW
(the default),
RIPPLE
, RIPPLE_TIGHT
, RIPPLE_LOOSE
, or RIPPLE_VERY_LOOSE
.type
- public double[][] calculateFOV(double[][] resistanceMap, int startx, int starty)
resistanceMap
- the grid of cells to calculate on; the kind made by generateResistances(char[][])
startx
- the horizontal component of the starting locationstarty
- the vertical component of the starting locationpublic double[][] calculateFOV(double[][] resistanceMap, int startx, int starty, double radius)
resistanceMap
- the grid of cells to calculate on; the kind made by generateResistances(char[][])
startx
- the horizontal component of the starting locationstarty
- the vertical component of the starting locationradius
- the distance the light will extend topublic double[][] calculateFOV(double[][] resistanceMap, int startX, int startY, double radius, Radius radiusTechnique)
resistanceMap
- the grid of cells to calculate on; the kind made by generateResistances(char[][])
startX
- the horizontal component of the starting locationstartY
- the vertical component of the starting locationradius
- the distance the light will extend toradiusTechnique
- provides a means to calculate the radius as desiredpublic double[][] calculateFOV(double[][] resistanceMap, int startX, int startY, double radius, Radius radiusTechnique, double angle, double span)
resistanceMap
- the grid of cells to calculate on; the kind made by generateResistances(char[][])
startX
- the horizontal component of the starting locationstartY
- the vertical component of the starting locationradius
- the distance the light will extend toradiusTechnique
- provides a means to calculate the radius as desiredangle
- the angle in degrees that will be the center of the FOV cone, 0 points rightspan
- the angle in degrees that measures the full arc contained in the FOV conepublic static double[][] calculateFOV(double[][] resistanceMap, double[][] light, int startx, int starty)
light
parameter. The values in light are always cleared before
this is run, because prior state can make this give incorrect results.
reuseFOV(double[][], double[][], int, int)
,
but all of the overloads are called reuseFOV(), so this method name is discouraged for new code. Both delegate to
reuseFOV(double[][], double[][], int, int, double, Radius)
anyway.resistanceMap
- the grid of cells to calculate on; the kind made by generateResistances(char[][])
light
- a non-null 2D double array that will have its contents overwritten, modified, and returnedstartx
- the horizontal component of the starting locationstarty
- the vertical component of the starting locationlight
)public static double[][] reuseFOV(double[][] resistanceMap, double[][] light, int startx, int starty)
light
parameter. The values in light are always cleared before
this is run, because prior state can make this give incorrect results.
calculateFOV(double[][], double[][], int, int)
,
but all of the overloads are called reuseFOV(), so this method name is preferred in new code. Both delegate to
reuseFOV(double[][], double[][], int, int, double, Radius)
anyway.resistanceMap
- the grid of cells to calculate on; the kind made by generateResistances(char[][])
light
- a non-null 2D double array that will have its contents overwritten, modified, and returnedstartx
- the horizontal component of the starting locationstarty
- the vertical component of the starting locationlight
)public static double[][] reuseFOV(double[][] resistanceMap, double[][] light, int startx, int starty, double radius)
light
parameter. The values in light are always cleared before
this is run, because prior state can make this give incorrect results.
resistanceMap
- the grid of cells to calculate on; the kind made by generateResistances(char[][])
startx
- the horizontal component of the starting locationstarty
- the vertical component of the starting locationradius
- the distance the light will extend topublic static double[][] reuseFOV(double[][] resistanceMap, double[][] light, int startX, int startY, double radius, Radius radiusTechnique)
light
parameter. The values in light are always cleared before
this is run, because prior state can make this give incorrect results.
resistanceMap
- the grid of cells to calculate on; the kind made by generateResistances(char[][])
light
- the grid of cells to assign to; may have existing values, and 0.0 is used to mean "unlit"startX
- the horizontal component of the starting locationstartY
- the vertical component of the starting locationradius
- the distance the light will extend toradiusTechnique
- provides a means to calculate the radius as desiredlight
public static double[][] reuseFOVSymmetrical(double[][] resistanceMap, double[][] light, int startX, int startY, double radius, Radius radiusTechnique)
light
parameter. The values in light
are always cleared before this is run, because prior state can make this give incorrect results. This
evaluates if the viewer and target cell can mutually see each other using a mirrored call to
(simplified) single-octant Shadow FOV.
resistanceMap
- the grid of cells to calculate on; the kind made by generateResistances(char[][])
light
- the grid of cells to assign to; may have existing values, and 0.0 is used to mean "unlit"startX
- the horizontal component of the starting locationstartY
- the vertical component of the starting locationradius
- the distance the light will extend toradiusTechnique
- provides a means to calculate the radius as desiredlight
public static double[][] reuseFOVLinear(double[][] resistanceMap, double[][] light, int startX, int startY, double radius, Radius radiusTechnique, LOS los)
public static boolean reachable(int startX, int startY, int targetX, int targetY, double[][] resistanceMap)
maxLength
and resistanceMap
to determine whether the line of sight is obstructed, without storing the line of points along the way.
resistanceMap
must not be null; it can be initialized in the same way as FOV's resistance maps can with
DungeonUtility.generateResistances(char[][])
or DungeonUtility.generateSimpleResistances(char[][])
. If the starting
point can see the target point, this returns true; otherwise this returns false.startX
- the x-coordinate of the starting pointstartY
- the y-coordinate of the starting pointtargetX
- the x-coordinate of the target pointtargetY
- the y-coordinate of the target pointresistanceMap
- a resistance map as produced by DungeonUtility.generateResistances(char[][])
; 0 is visible and 1 is blockedpublic static boolean reachablePermissive(int startX, int startY, int targetX, int targetY, double[][] resistanceMap)
public static boolean reachableOrtho(int startX, int startY, int targetX, int targetY, double[][] resistanceMap)
maxLength
and resistanceMap
to determine whether the line of sight is obstructed, without storing the line of points along the way.
resistanceMap
must not be null; it can be initialized in the same way as FOV's resistance maps can with
DungeonUtility.generateResistances(char[][])
or DungeonUtility.generateSimpleResistances(char[][])
. If the starting
point can see the target point, this returns true; otherwise this returns false.startX
- the x-coordinate of the starting pointstartY
- the y-coordinate of the starting pointtargetX
- the x-coordinate of the target pointtargetY
- the y-coordinate of the target pointresistanceMap
- a resistance map as produced by DungeonUtility.generateResistances(char[][])
; 0 is visible and 1 is blockedpublic static double[][] reuseLOS(double[][] resistanceMap, double[][] light, int startX, int startY)
light
parameter. The values in light
are always cleared before this is run, because prior state can make this give
incorrect results.
Radius.SQUARE
if it matters.resistanceMap
- the grid of cells to calculate on; the kind made by generateResistances(char[][])
light
- the grid of cells to assign to; may have existing values, and 0.0 is used to mean "no line"startX
- the horizontal component of the starting locationstartY
- the vertical component of the starting locationlight
public static double[][] reuseLOS(double[][] resistanceMap, double[][] light, int startX, int startY, int minX, int minY, int maxX, int maxY)
light
parameter. The values in light
are always cleared before this is run, because prior state can make this give
incorrect results.
Radius.SQUARE
if it matters.resistanceMap
- the grid of cells to calculate on; the kind made by generateResistances(char[][])
light
- the grid of cells to assign to; may have existing values, and 0.0 is used to mean "no line"startX
- the horizontal component of the starting locationstartY
- the vertical component of the starting locationlight
public static GreasedRegion reuseLOS(GreasedRegion blockingMap, GreasedRegion light, int startX, int startY)
light
parameter. The values in light
are always cleared before this is run, because prior state can make this give
incorrect results. The given blockingMap
only considers cells to
block light if they are true or "on".
blockingMap
- the grid of which cells block light ("on" cells are blocking)light
- the grid of cells to assign to; will be cleared before modifyingstartX
- the horizontal component of the starting locationstartY
- the vertical component of the starting locationlight
public static GreasedRegion reuseLOS(GreasedRegion blockingMap, GreasedRegion light, int startX, int startY, int minX, int minY, int maxX, int maxY)
light
parameter. The values in light
are always cleared before this is run, because prior state can make this give
incorrect results. The given blockingMap
only considers cells to
block light if they are true or "on".
blockingMap
- the grid of which cells block light ("on" cells are blocking)light
- the grid of cells to assign to; will be cleared before modifyingstartX
- the horizontal component of the starting locationstartY
- the vertical component of the starting locationminX
- inclusive lowest x position to assign to or process in light
minY
- inclusive lowest y position to assign to or process in light
maxX
- exclusive highest x position to assign to or process in light
maxY
- exclusive highest y position to assign to or process in light
light
public static double[][] reuseFOV(double[][] resistanceMap, double[][] light, int startX, int startY, double radius, Radius radiusTechnique, double angle, double span)
light
parameter. The values in light are cleared before
this is run, because prior state can make this give incorrect results.
resistanceMap
- the grid of cells to calculate on; the kind made by generateResistances(char[][])
light
- the grid of cells to assign to; may have existing values, and 0.0 is used to mean "unlit"startX
- the horizontal component of the starting locationstartY
- the vertical component of the starting locationradius
- the distance the light will extend toradiusTechnique
- provides a means to shape the FOV by changing distance calculation (circle, square, etc.)angle
- the angle in degrees that will be the center of the FOV cone, 0 points rightspan
- the angle in degrees that measures the full arc contained in the FOV conepublic static double[][] reuseRippleFOV(double[][] resistanceMap, double[][] light, int x, int y, double radius, Radius radiusTechnique)
reuseFOV(double[][], double[][], int, int, double, Radius)
method, but this uses Ripple FOV
with a tightness/looseness equal to 2. Other parameters are similar; you
can get a resistance map from generateResistances(char[][])
, light
will be modified and returned
(it will be overwritten, but its size should be the same as the resistance map), there's a starting x,y position,
a radius in cells, and a Radius
enum constant to choose the distance measurement.resistanceMap
- probably calculated with generateResistances(char[][])
; 1.0 blocks light, 0.0 allows itlight
- will be overwritten! Should be initialized with the same size as resistanceMap
x
- starting x position to look fromy
- starting y position to look fromradius
- the distance to extend from the starting x,y positionradiusTechnique
- how to measure distance; typically Radius.CIRCLE
.light
, after writing the FOV map into it; 1.0 is fully lit and 0.0 is unseenpublic static double[][] reuseRippleFOV(double[][] resistanceMap, double[][] light, int rippleLooseness, int x, int y, double radius, Radius radiusTechnique)
reuseFOV(double[][], double[][], int, int, double, Radius)
method, but this uses Ripple FOV
with a configurable tightness/looseness (between 1, tightest, and 6, loosest). Other parameters are similar; you
can get a resistance map from generateResistances(char[][])
, light
will be modified and returned
(it will be overwritten, but its size should be the same as the resistance map), there's a starting x,y position,
a radius in cells, and a Radius
enum constant to choose the distance measurement.resistanceMap
- probably calculated with generateResistances(char[][])
; 1.0 blocks light, 0.0 allows itlight
- will be overwritten! Should be initialized with the same size as resistanceMap
rippleLooseness
- affects spread; between 1 and 6, inclusive; 1 is tightest, 2 is normal, and 6 is loosestx
- starting x position to look fromy
- starting y position to look fromradius
- the distance to extend from the starting x,y positionradiusTechnique
- how to measure distance; typically Radius.CIRCLE
.light
, after writing the FOV map into it; 1.0 is fully lit and 0.0 is unseenpublic static double[][] reuseRippleFOV(double[][] resistanceMap, double[][] light, int rippleLooseness, int x, int y, double radius, Radius radiusTechnique, double angle, double span)
reuseFOV(double[][], double[][], int, int, double, Radius, double, double)
method, but this
uses Ripple FOV with a configurable tightness/looseness (between 1, tightest, and 6, loosest). Other parameters
are similar; you can get a resistance map from generateResistances(char[][])
, light
will be
modified and returned (it will be overwritten, but its size should be the same as the resistance map), there's
starting x,y position, a radius in cells, a Radius
enum constant to choose the distance measurement, and
the angle/span combination to specify a conical section of FOV (span is the total in degrees, centered on angle).resistanceMap
- probably calculated with generateResistances(char[][])
; 1.0 blocks light, 0.0 allows itlight
- will be overwritten! Should be initialized with the same size as resistanceMap
rippleLooseness
- affects spread; between 1 and 6, inclusive; 1 is tightest, 2 is normal, and 6 is loosestx
- starting x position to look fromy
- starting y position to look fromradius
- the distance to extend from the starting x,y positionradiusTechnique
- how to measure distance; typically Radius.CIRCLE
.angle
- the angle to center the conical FOV onspan
- the total span in degrees for the conical FOV to coverlight
, after writing the FOV map into it; 1.0 is fully lit and 0.0 is unseenpublic static double[][] bouncingLine(double[][] resistanceMap, double[][] light, int startX, int startY, double distance, double angle)
resistanceMap
- the grid of cells to calculate on; the kind made by generateResistances(char[][])
light
- the grid of cells to assign to; may have existing values, and 0.0 is used to mean "unlit"startX
- the horizontal component of the starting locationstartY
- the vertical component of the starting locationdistance
- the distance the light will extend toangle
- in degrees, the angle to start the path traveling inpublic static double[][] reuseFOV(double[][] resistanceMap, double[][] light, int startX, int startY, double radius, Radius radiusTechnique, double angle, double forward, double sideForward, double side, double sideBack, double back)
angle
in degrees,
extending to different ranges based on the direction the light is traveling.
The direction ranges are forward
, sideForward
, side
,
sideBack
, and back
; all are multiplied by radius
.
Assigns to, and returns, a light map where the values represent a percentage of fully
lit. The values in light are cleared before this is run, because prior state can make
this give incorrect results. You can use addFOVsInto(double[][], double[][]...)
if you want to mix FOV results, which works as an alternative to using the prior light state.
reuseFOV(double[][], double[][], int, int, double, Radius)
; otherwise
may produce conical shapes (potentially more than one, or overlapping ones).resistanceMap
- the grid of cells to calculate on; the kind made by generateResistances(char[][])
light
- the grid of cells to assign to; may have existing values, and 0.0 is used to mean "unlit"startX
- the horizontal component of the starting locationstartY
- the vertical component of the starting locationradius
- the distance the light will extend to (roughly); direction ranges will be multiplied by thisradiusTechnique
- provides a means to shape the FOV by changing distance calculation (circle, square, etc.)angle
- the angle in degrees that will be the center of the FOV cone, 0 points rightforward
- the range to extend when the light is within 22.5 degrees of angle; will be interpolated with sideForwardsideForward
- the range to extend when the light is between 22.5 and 67.5 degrees of angle; will be interpolated with forward or sideside
- the range to extend when the light is between 67.5 and 112.5 degrees of angle; will be interpolated with sideForward or sideBacksideBack
- the range to extend when the light is between 112.5 and 157.5 degrees of angle; will be interpolated with side or backback
- the range to extend when the light is more than 157.5 degrees away from angle; will be interpolated with sideBacklight
)public static double[][] addFOVsInto(double[][] basis, double[][] addend)
addFOVs(double[][][])
, which creates a new 2D array.basis
- a 2D double array, which can be empty or returned by calculateFOV() or reuseFOV(); modified!addend
- another 2D double array that will be added into basis; this one will not be modifiedpublic static double[][] addFOVs(double[][]... maps)
maps
- an array or vararg of 2D double arrays, each usually returned by calculateFOV()public static double[][] addFOVsInto(double[][] basis, double[][]... maps)
basis
- a 2D double array that will be modified by adding values in maps to it and clamping to 1.0 or lessmaps
- an array or vararg of 2D double arrays, each usually returned by calculateFOV()public static double[][] addFOVs(java.lang.Iterable<double[][]> maps)
maps
- an Iterable of 2D double arrays (most collections implement Iterable),
each usually returned by calculateFOV()public static double[][] mixVisibleFOVs(double[][] losMap, double[][]... maps)
reuseLOS(double[][], double[][], int, int)
, using the same resistance map used to
calculate the FOV maps. Clamps the highest value for any single position at 1.0.losMap
- an LOS map such as one generated by reuseLOS(double[][], double[][], int, int)
maps
- an array or vararg of 2D double arrays, each usually returned by calculateFOV()public static double[][] mixVisibleFOVsInto(double[][] losMap, double[][] basis, double[][]... maps)
reuseLOS(double[][], double[][], int, int)
, using the same resistance map used to
calculate the FOV maps. Clamps the highest value for any single position at 1.0.losMap
- an LOS map such as one generated by reuseLOS(double[][], double[][], int, int)
basis
- an existing 2D double array that should have matching width and height to losMap; will be modifiedmaps
- an array or vararg of 2D double arrays, each usually returned by calculateFOV()public static double[][] mixVisibleFOVs(double[][] losMap, java.lang.Iterable<double[][]> maps)
reuseLOS(double[][], double[][], int, int)
, using the same resistance map used to
calculate the FOV maps. Clamps the highest value for any single position at 1.0.losMap
- an LOS map such as one generated by reuseLOS(double[][], double[][], int, int)
maps
- an Iterable of 2D double arrays, each usually returned by calculateFOV()public double[][] calculateLOSMap(double[][] resistanceMap, int startX, int startY)
resistanceMap
- the grid of cells to calculate on; the kind made by generateResistances(char[][])
startX
- the center of the LOS map; typically the player's x-positionstartY
- the center of the LOS map; typically the player's y-positionpublic static double[][] generateResistances(char[][] map)
reuseFOV(double[][], double[][], int, int, double)
. It expects any doors to be represented by '+' if
closed or '/' if open (which can be caused by calling DungeonUtility.closeDoors(char[][])
), any walls to
be '#' or box drawing characters, and it doesn't care what other chars are used (only doors, including open ones,
and walls obscure light and thus have a resistance by default).map
- a dungeon, width by height, with any closed doors as '+' and open doors as '/' as per closeDoors()public static double[][] generateResistances3x3(char[][] map)
DungeonUtility.hashesToLines(char[][], boolean)
), produces a double[][] with triple width and triple
height that can be used with FOV methods like reuseFOV(double[][], double[][], int, int, double)
in
classes that use subcell lighting. Importantly, this only considers a "thin line" of wall to be blocking
(matching the box drawing character), instead of the whole 3x3 area. This expects any doors to be represented by
'+' if closed or '/' if open (which can be caused by calling DungeonUtility.closeDoors(char[][])
), thick
vegetation or other concealing obstructions to be '"', any normal walls to be box drawing characters, any cells
that block all subcells to be '#', and it doesn't care what other chars are used (only doors, including open
ones, vegetation, and walls obscure light and thus have a resistance normally).map
- a dungeon, width by height, with any closed doors as '+' and open doors as '/' as per closeDoors()public static double[][] generateSimpleResistances(char[][] map)
reuseFOV(double[][], double[][], int, int, double)
), but does not treat
any cells as partly transparent, only fully-blocking or fully-permitting light. This is mainly useful if you
expect the FOV radius to be very high or (effectively) infinite, since anything less than complete blockage would
be passed through by infinite-radius FOV. This expects any doors to be represented by '+' if closed or '/' if
open (most door placement defaults to a mix of '+' and '/', so by calling
DungeonUtility.closeDoors(char[][])
you can close all doors at the start), and any walls to be '#' or
box drawing characters. This will assign 1.0 resistance to walls and closed doors or 0.0 for any other cell.map
- a dungeon, width by height, with any closed doors as '+' and open doors as '/' as per closeDoors()public static double[][] generateSimpleResistances3x3(char[][] map)
DungeonUtility.hashesToLines(char[][], boolean)
), produces a double[][] with triple width and triple
height that can be used with FOV's methods that expect a resistance map (like
reuseFOV(double[][], double[][], int, int, double)
) in classes that use subcell lighting. This expects
any doors to be represented by '+' if closed or '/' if open (most door placement defaults to a mix of '+' and
'/', so by calling DungeonUtility.closeDoors(char[][])
you can close all doors at the start), any walls
to be box drawing characters, and any cells that block all subcells within their area to be '#'. This will assig
1.0 resistance to walls and closed doors where a line of the box drawing char would block light, or 0.0 for an
other subcell.map
- a dungeon, width by height, with any closed doors as '+' and open doors as '/' as per closeDoors()public static double[][] reuseBurstFOV(double[][] resistanceMap, double[][] light, int rippleLooseness, int x, int y, double radius, Radius radiusTechnique)
Copyright © Eben Howard 2012–2022. All rights reserved.