Class FOV

java.lang.Object
com.github.yellowstonegames.grid.FOV

public final class FOV extends Object
This class provides methods for calculating Field of View in grids. Field of View (FOV) algorithms determine how much area surrounding a point can be seen. They return a 2D array of floats, representing the amount of view (typically sight, but perhaps sound, smell, etc.) which the origin has of each cell. In the returned 2D array, 1.0f is always "fully seen," while 0.0f is always "unseen." Values in between are much more common, and they enable this class to be used for lighting effects.
The input resistanceMap is considered the percent of opacity. This resistance is on top of the resistance applied from the light spreading out. You can obtain a resistance map easily with the generateResistances(char[][]) method, which uses defaults for common chars used in SquidSquad, 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 float to the same x,y position in a float[][]. The value should be between 0.0f (unblocked) for things light passes through, 1.0f (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.0f (fully blocked) or 0.0f (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 maps with box-drawing characters, since these 3x3 resistance maps will line up blocking cells to where a box-drawing line is.
The returned light map is considered the percent of light in the cells.
All implementations for FOV here (that is, Ripple FOV and Shadow FOV) provide percentage levels for partially-lit or partially-seen cells. This leads to a straightforward implementation of soft lighting using an FOV result -- just mix the background or floor color of a cell, however you represent it, with a very light color (like pastel yellow), with the percentage of the light color to mix in equal to the percent of light in the FOV map.
All solvers perform bounds checking so solid borders in the map are not required.
For calculating FOV maps, this class only provides static methods, which take a light 2D array as an argument and edit it in-place. The Ripple methods reuseRippleFOV(float[][], float[][], int, int, int, float, Radius) and reuseRippleFOV(float[][], float[][], int, int, int, float, Radius, float, float) use internal static state, resetting it on each call; this makes them ineligible for use in multithreaded code. The other methods use Shadow FOV, and are potentially usable in multithreaded code.
Static methods are provided to add together FOV maps in the simple way (disregarding visibility of distant FOV from a given cell), or the more practical way for roguelikes (where a cell needs to be within line-of-sight in the first place for a distant light to illuminate it). The second method relies on an LOS map, which is essentially the same as a very-high-radius FOV map and can be easily obtained with calculateLOSMap(). The simple way uses addFOVs(float[][]...) or addFOVsInto(float[][], float[][]...), while the way that respects LOS uses mixVisibleFOVs(float[][], float[][]...) or mixVisibleFOVsInto(float[][], float[][], float[][]...).
If you want to iterate through cells that are visible in a float[][] returned by FOV, you can pass that float[][] to cellsByDescendingValue(float[][]) and iterate over the returned map's ObjectFloatOrderedMap.entrySet() or ObjectFloatOrderedMap.order(). These approaches will start iteration at the highest-value cell and continue to lower and lower values. You can also reuse an existing CoordFloatOrderedMap using fillCellsByDescendingValue(float[][], CoordFloatOrderedMap), which is a better choice than cellsByDescendingValue() if you call it every frame.
  • Method Summary

    Modifier and Type
    Method
    Description
    static float[][]
    addFOVs(float[][]... grids)
    Adds multiple FOV grids together in the simplest way possible; does not check line-of-sight between FOV grids.
    static float[][]
    addFOVs(Iterable<float[][]> grids)
    Adds multiple FOV grids together in the simplest way possible; does not check line-of-sight between FOV grids.
    static float[][]
    addFOVsInto(float[][] basis, float[][] addend)
    Adds an FOV grid to another in the simplest way possible; does not check line-of-sight between FOV grids.
    static float[][]
    addFOVsInto(float[][] basis, float[][]... grids)
    Adds multiple FOV grids to basis cell-by-cell, modifying basis; does not check line-of-sight between FOV grids.
    static float[][]
    bouncingLine(float[][] resistanceMap, float[][] light, int startX, int startY, float distance, float 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.
    cellsByDescendingValue(float[][] fovGrid)
    Given a typical FOV grid produced by reuseFOV(float[][], float[][], int, int), reuseRippleFOV(float[][], float[][], int, int, float, Radius), or a similar method, this gets a CoordFloatOrderedMap containing only the visible Coord cells as keys, associated with their visibility levels, and ordered so the most-visible cell (typically where the viewer is) is first in the iteration order.
    fillCellsByDescendingValue(float[][] fovGrid, CoordFloatOrderedMap modifying)
    Given a typical FOV map produced by reuseFOV(float[][], float[][], int, int), reuseRippleFOV(float[][], float[][], int, int, float, Radius), or a similar method and a CoordFloatOrderedMap modifying to clear and reuse in-place, this fills modifying with only the visible Coord cells as keys, associated with their visibility levels, and ordered so the most-visible cell (typically where the viewer is) is first in the iteration order.
    static float[][]
    fillResistancesInto(char[][] grid, float[][] into)
    Given a char[][] for the local area and a float[][] with the same dimensions as the chars, fills the float[][] so it can be used with most of the methods in FOV, like reuseFOV(float[][], float[][], int, int, float).
    static float[][]
    fillSimpleResistancesInto(char[][] grid, float[][] into)
    Given a char[][] for the local area and a float[][] with the same dimensions as the chars, fills the float[][] so it can be used with most of the methods in FOV, like reuseFOV(float[][], float[][], int, int, float), but does not treat any cells as partly transparent, only fully-blocking or fully-permitting light.
    static float[][]
    generateResistances(char[][] map)
    Given a char[][] for the local area, produces a float[][] that can be used with most of the methods in FOV, like reuseFOV(float[][], float[][], int, int, float).
    static float[][]
    generateResistances3x3(char[][] grid)
    Given a char[][] for the local area that should use box drawing characters, produces a float[][] with triple width and triple height that can be used with FOV methods like reuseFOV(float[][], float[][], int, int, float) in classes that use subcell lighting.
    static float[][]
    Given a char[][] for the local area, produces a float[][] that can be used with any FOV methods that expect a resistance grid (like reuseFOV(float[][], float[][], int, int, float)), but does not treat any cells as partly transparent, only fully-blocking or fully-permitting light.
    static float[][]
    Given a char[][] for the local area that should use box drawing characters, produces a float[][] with triple width and triple height that can be used with FOV's methods that expect a resistance grid (like reuseFOV(float[][], float[][], int, int, float)) in classes that use subcell lighting.
    static float[][]
    generateSoundResistances(char[][] grid)
    Given a char[][] for the local area, produces a float[][] that can be used with the sound-related methods here, allowing sound to pass through thin-enough walls and doors.
    static float[][]
    mixVisibleFOVs(float[][] losGrid, float[][]... grids)
    Adds together multiple FOV grids, but only adds to a position if it is visible in the given LOS grid.
    static float[][]
    mixVisibleFOVs(float[][] losGrid, Iterable<float[][]> grids)
    Adds together multiple FOV grids, but only adds to a position if it is visible in the given LOS grid.
    static float[][]
    mixVisibleFOVsInto(float[][] losGrid, float[][] basis, float[][]... grids)
    Adds together multiple FOV grids, but only adds to a position if it is visible in the given LOS grid.
    static float
    resistance(char cell)
    Given a single char, returns what generateResistances(char[][]) or fillResistancesInto(char[][], float[][]) would consider as its light resistance value.
    static float[][]
    reuseFOV(float[][] resistanceMap, float[][] light, int startx, int starty)
    Calculates the Field Of View for the provided map from the given x, y coordinates.
    static float[][]
    reuseFOV(float[][] resistanceMap, float[][] light, int startx, int starty, float radius)
    Calculates the Field Of View for the provided map from the given x, y coordinates.
    static float[][]
    reuseFOV(float[][] resistanceMap, float[][] light, int startX, int startY, float radius, Radius radiusTechnique)
    Calculates the Field Of View for the provided map from the given x, y coordinates.
    static float[][]
    reuseFOV(float[][] resistanceMap, float[][] light, int startX, int startY, float radius, Radius radiusTechnique, float angle, float 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 float[][]
    reuseFOV(float[][] resistanceMap, float[][] light, int startX, int startY, float radius, Radius radiusTechnique, float angle, float forward, float sideForward, float side, float sideBack, float 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 float[][]
    reuseFOVDeg(float[][] resistanceMap, float[][] light, int startX, int startY, float radius, Radius radiusTechnique, float angle, float 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 float[][]
    reuseFOVDeg(float[][] resistanceMap, float[][] light, int startX, int startY, float radius, Radius radiusTechnique, float angle, float forward, float sideForward, float side, float sideBack, float 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 float[][]
    reuseFOVOrtho(float[][] resistanceMap, float[][] light, int startX, int startY, float radius, Radius radiusTechnique)
    Calculates the symmetrical Field Of View for the provided resistanceMap from the given x, y viewer coordinates.
    static float[][]
    reuseFOVRad(float[][] resistanceMap, float[][] light, int startX, int startY, float radius, Radius radiusTechnique, float angle, float span)
    Calculates the Field Of View for the provided map from the given x, y coordinates, lighting at the given angle in radians and covering a span centered on that angle, also in radians.
    static float[][]
    reuseFOVRad(float[][] resistanceMap, float[][] light, int startX, int startY, float radius, Radius radiusTechnique, float angle, float forward, float sideForward, float side, float sideBack, float 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 radians, extending to different ranges based on the direction the light is traveling.
    static float[][]
    reuseFOVSymmetrical(float[][] resistanceMap, float[][] light, int startX, int startY, float radius, Radius radiusTechnique)
    Calculates the symmetrical Field Of View for the provided resistanceMap from the given x, y viewer coordinates.
    static float[][]
    reuseFOVTurns(float[][] resistanceMap, float[][] light, int startX, int startY, float radius, Radius radiusTechnique, float angle, float span)
    Calculates the Field Of View for the provided map from the given x, y coordinates, lighting at the given angle in turns and covering a span centered on that angle, also in turns.
    static float[][]
    reuseFOVTurns(float[][] resistanceMap, float[][] light, int startX, int startY, float radius, Radius radiusTechnique, float angle, float forward, float sideForward, float side, float sideBack, float 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 turns, extending to different ranges based on the direction the light is traveling.
    static float[][]
    reuseLOS(float[][] resistanceMap, float[][] light, int startX, int startY)
    Calculates which cells have line of sight from the given x, y coordinates.
    static float[][]
    reuseLOS(float[][] resistanceMap, float[][] 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 Region
    reuseLOS(Region blockingMap, Region light, int startX, int startY)
    Calculates which cells have line of sight from the given x, y coordinates.
    static Region
    reuseLOS(Region blockingMap, Region 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 float[][]
    reuseRippleFOV(float[][] resistanceMap, float[][] light, int x, int y, float radius, Radius radiusTechnique)
    Like the reuseFOV(float[][], float[][], int, int, float, Radius) method, but this uses Ripple FOV with a tightness/looseness of 2.
    static float[][]
    reuseRippleFOV(float[][] resistanceMap, float[][] light, int rippleLooseness, int x, int y, float radius, Radius radiusTechnique)
    Like the reuseFOV(float[][], float[][], int, int, float, Radius) method, but this uses Ripple FOV with a configurable tightness/looseness (between 1, tightest, and 6, loosest).
    static float[][]
    reuseRippleFOV(float[][] resistanceMap, float[][] light, int rippleLooseness, int x, int y, float radius, Radius radiusTechnique, float angle, float span)
    Like the reuseFOV(float[][], float[][], int, int, float, Radius, float, float) method, but this uses Ripple FOV with a configurable tightness/looseness (between 1, tightest, and 6, loosest).
    static float[][]
    reuseSoundField(float[][] resistanceMap, float[][] sound, int x, int y, float radius, Radius radiusTechnique)
    Like the reuseFOV(float[][], float[][], int, int, float, Radius) method, but this is meant for sound rather than light, and so uses Ripple FOV with maximum looseness, and expects a sound resistance map rather than a light one.
    static float
    simpleResistance(char cell)
    Given a single char, returns what generateSimpleResistances(char[][]) or fillSimpleResistancesInto(char[][], float[][]) would consider as its light resistance value.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • reuseFOV

      public static float[][] reuseFOV(float[][] resistanceMap, float[][] light, int startx, int starty)
      Calculates the Field Of View for the provided map from the given x, y coordinates. Assigns to, and returns, a light map where the values represent a percentage of fully lit. Always uses Shadow FOV, which allows this method to be static since it doesn't need to keep any state around, and can reuse the state the user gives it via the light parameter. The values in light are always cleared before this is run, because prior state can make this give incorrect results.
      The starting point for the calculation is considered to be at the center of the origin cell. Radius determinations based on Euclidean calculations. The light will be treated as having infinite possible radius.
      Parameters:
      resistanceMap - the grid of cells to calculate on; the kind made by generateResistances(char[][])
      light - a non-null 2D float array that will have its contents overwritten, modified, and returned
      startx - the horizontal component of the starting location
      starty - the vertical component of the starting location
      Returns:
      the computed light grid (the same as light)
    • reuseFOV

      public static float[][] reuseFOV(float[][] resistanceMap, float[][] light, int startx, int starty, float radius)
      Calculates the Field Of View for the provided map from the given x, y coordinates. Assigns to, and returns, a light map where the values represent a percentage of fully lit. Always uses Shadow FOV, which allows this method to be static since it doesn't need to keep any state around, and can reuse the state the user gives it via the light parameter. The values in light are always cleared before this is run, because prior state can make this give incorrect results.
      The starting point for the calculation is considered to be at the center of the origin cell. Radius determinations based on Euclidean calculations.
      Parameters:
      resistanceMap - the grid of cells to calculate on; the kind made by generateResistances(char[][])
      startx - the horizontal component of the starting location
      starty - the vertical component of the starting location
      radius - the distance the light will extend to
      Returns:
      the computed light grid
    • reuseFOV

      public static float[][] reuseFOV(float[][] resistanceMap, float[][] light, int startX, int startY, float radius, Radius radiusTechnique)
      Calculates the Field Of View for the provided map from the given x, y coordinates. Assigns to, and returns, a light map where the values represent a percentage of fully lit. Always uses Shadow FOV, which allows this method to be static since it doesn't need to keep any state around, and can reuse the state the user gives it via the light parameter. The values in light are always cleared before this is run, because prior state can make this give incorrect results.
      The starting point for the calculation is considered to be at the center of the origin cell. Radius determinations are determined by the provided RadiusStrategy.
      Parameters:
      resistanceMap - the grid of cells to calculate on; the kind made by generateResistances(char[][])
      light - the grid of cells to assign to, which will be cleared; 0f means "unlit" and 1f means "fully lit"
      startX - the horizontal component of the starting location
      startY - the vertical component of the starting location
      radius - the distance the light will extend to
      radiusTechnique - a Radius enum constant, such as Radius.CIRCLE, that provides the shape of the FOV
      Returns:
      the computed light grid, which is the same 2D array as light
    • reuseFOVSymmetrical

      public static float[][] reuseFOVSymmetrical(float[][] resistanceMap, float[][] light, int startX, int startY, float radius, Radius radiusTechnique)
      Calculates the symmetrical Field Of View for the provided resistanceMap from the given x, y viewer coordinates. Assigns to, and returns, a light map where the values represent a percentage of fully lit. If any cell in the returned light map is greater than 0, then both the viewer can see that cell, and anyone in that cell can see the viewer (if they have sufficient viewing range). Always uses Shadow FOV, and can reuse the state the user gives it via the 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.
      The starting point for the calculation is considered to be at the center of the origin cell. Radius determinations are determined by the provided RadiusStrategy.
      Parameters:
      resistanceMap - the grid of cells to calculate on; the kind made by generateResistances(char[][])
      light - the grid of cells to assign to, which will be cleared; 0f means "unlit" and 1f means "fully lit"
      startX - the horizontal component of the starting location
      startY - the vertical component of the starting location
      radius - the distance the light will extend to
      radiusTechnique - a Radius enum constant, such as Radius.CIRCLE, that provides the shape of the FOV
      Returns:
      the computed light grid, which is the same 2D array as light
    • reuseLOS

      public static float[][] reuseLOS(float[][] resistanceMap, float[][] light, int startX, int startY)
      Calculates which cells have line of sight from the given x, y coordinates. Assigns to, and returns, a light map where the values are always either 0.0f for "not in line of sight" or 1.0f for "in line of sight," which doesn't mean a cell is actually visible if there's no light in that cell. Always uses Shadow FOV, which allows this method to be static since it doesn't need to keep any state around, and can reuse the state the user gives it via the light parameter. The values in light are always cleared before this is run, because prior state can make this give incorrect results. The given resistanceMap only considers cells to block light if they have values of 1.0f or greater.
      The starting point for the calculation is considered to be at the center of the origin cell. Radius determinations are pretty much irrelevant because the distance doesn't matter, only the presence of a clear line, but this uses Radius.SQUARE if it matters.
      Parameters:
      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.0f is used to mean "no line"
      startX - the horizontal component of the starting location
      startY - the vertical component of the starting location
      Returns:
      the computed light grid, which is the same 2D array as the value assigned to light
    • reuseLOS

      public static float[][] reuseLOS(float[][] resistanceMap, float[][] 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. Assigns to, and returns, a light map where the values are always either 0.0f for "not in line of sight" or 1.0f for "in line of sight," which doesn't mean a cell is actually visible if there's no light in that cell. Always uses Shadow FOV, which allows this method to be static since it doesn't need to keep any state around, and can reuse the state the user gives it via the light parameter. The values in light are always cleared before this is run, because prior state can make this give incorrect results. The given resistanceMap only considers cells to block light if they have values of 1.0f or greater.
      The starting point for the calculation is considered to be at the center of the origin cell. Radius determinations are pretty much irrelevant because the distance doesn't matter, only the presence of a clear line, but this uses Radius.SQUARE if it matters.
      Parameters:
      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.0f is used to mean "no line"
      startX - the horizontal component of the starting location
      startY - the vertical component of the starting location
      minX - 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
      Returns:
      the computed light grid, which is the same 2D array as the value assigned to light
    • reuseLOS

      public static Region reuseLOS(Region blockingMap, Region light, int startX, int startY)
      Calculates which cells have line of sight from the given x, y coordinates. Assigns to, and returns, a light Region where the false or "off" indicates "not in line of sight" and true or "on" indicated "in line of sight," though this doesn't mean a cell is actually visible if there's no light in that cell. Always uses Shadow FOV, which allows this method to be static since it doesn't need to keep any state around, and can reuse the state the user gives it via the 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".
      The starting point for the calculation is considered to be at the center of the origin cell.
      Parameters:
      blockingMap - the grid of which cells block light ("on" cells are blocking)
      light - the grid of cells to assign to; will be cleared before modifying
      startX - the horizontal component of the starting location
      startY - the vertical component of the starting location
      Returns:
      the computed light grid, which is the same 2D array as the value assigned to light
    • reuseLOS

      public static Region reuseLOS(Region blockingMap, Region 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. Assigns to, and returns, a light Region where the false or "off" indicates "not in line of sight" and true or "on" indicated "in line of sight," though this doesn't mean a cell is actually visible if there's no light in that cell. Always uses Shadow FOV, which allows this method to be static since it doesn't need to keep any state around, and can reuse the state the user gives it via the 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".
      The starting point for the calculation is considered to be at the center of the origin cell.
      Parameters:
      blockingMap - the grid of which cells block light ("on" cells are blocking)
      light - the grid of cells to assign to; will be cleared before modifying
      startX - the horizontal component of the starting location
      startY - the vertical component of the starting location
      minX - 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
      Returns:
      the computed light grid, which is the same 2D array as the value assigned to light
    • reuseFOV

      public static float[][] reuseFOV(float[][] resistanceMap, float[][] light, int startX, int startY, float radius, Radius radiusTechnique, float angle, float 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. Assigns to, and returns, a light map where the values represent a percentage of fully lit. Always uses Shadow FOV, which allows this method to be static since it doesn't need to keep any state around, and can reuse the state the user gives it via the light parameter. The values in light are cleared before this is run, because prior state can make this give incorrect results.
      The starting point for the calculation is considered to be at the center of the origin cell. Radius determinations are determined by the provided RadiusStrategy. A conical section of FOV is lit by this method if span is greater than 0.
      This is an alias for reuseFOVDeg(float[][], float[][], int, int, float, Radius, float, float).
      Parameters:
      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.0f is used to mean "unlit"
      startX - the horizontal component of the starting location
      startY - the vertical component of the starting location
      radius - the distance the light will extend to
      radiusTechnique - 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 right
      span - the angle in degrees that measures the full arc contained in the FOV cone
      Returns:
      the computed light grid
    • reuseFOVRad

      public static float[][] reuseFOVRad(float[][] resistanceMap, float[][] light, int startX, int startY, float radius, Radius radiusTechnique, float angle, float span)
      Calculates the Field Of View for the provided map from the given x, y coordinates, lighting at the given angle in radians and covering a span centered on that angle, also in radians. Assigns to, and returns, a light map where the values represent a percentage of fully lit. Always uses Shadow FOV, which allows this method to be static since it doesn't need to keep any state around, and can reuse the state the user gives it via the light parameter. The values in light are cleared before this is run, because prior state can make this give incorrect results.
      The starting point for the calculation is considered to be at the center of the origin cell. Radius determinations are determined by the provided RadiusStrategy. A conical section of FOV is lit by this method if span is greater than 0.
      Parameters:
      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.0f is used to mean "unlit"
      startX - the horizontal component of the starting location
      startY - the vertical component of the starting location
      radius - the distance the light will extend to
      radiusTechnique - provides a means to shape the FOV by changing distance calculation (circle, square, etc.)
      angle - the angle in radians that will be the center of the FOV cone, 0 points right
      span - the angle in radians that measures the full arc contained in the FOV cone
      Returns:
      the computed light grid
    • reuseFOVDeg

      public static float[][] reuseFOVDeg(float[][] resistanceMap, float[][] light, int startX, int startY, float radius, Radius radiusTechnique, float angle, float 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. Assigns to, and returns, a light map where the values represent a percentage of fully lit. Always uses Shadow FOV, which allows this method to be static since it doesn't need to keep any state around, and can reuse the state the user gives it via the light parameter. The values in light are cleared before this is run, because prior state can make this give incorrect results.
      The starting point for the calculation is considered to be at the center of the origin cell. Radius determinations are determined by the provided RadiusStrategy. A conical section of FOV is lit by this method if span is greater than 0.
      Parameters:
      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.0f is used to mean "unlit"
      startX - the horizontal component of the starting location
      startY - the vertical component of the starting location
      radius - the distance the light will extend to
      radiusTechnique - 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 right
      span - the angle in degrees that measures the full arc contained in the FOV cone
      Returns:
      the computed light grid
    • reuseFOVTurns

      public static float[][] reuseFOVTurns(float[][] resistanceMap, float[][] light, int startX, int startY, float radius, Radius radiusTechnique, float angle, float span)
      Calculates the Field Of View for the provided map from the given x, y coordinates, lighting at the given angle in turns and covering a span centered on that angle, also in turns. Assigns to, and returns, a light map where the values represent a percentage of fully lit. Always uses Shadow FOV, which allows this method to be static since it doesn't need to keep any state around, and can reuse the state the user gives it via the light parameter. The values in light are cleared before this is run, because prior state can make this give incorrect results.
      The starting point for the calculation is considered to be at the center of the origin cell. Radius determinations are determined by the provided RadiusStrategy. A conical section of FOV is lit by this method if span is greater than 0.
      Parameters:
      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.0f is used to mean "unlit"
      startX - the horizontal component of the starting location
      startY - the vertical component of the starting location
      radius - the distance the light will extend to
      radiusTechnique - provides a means to shape the FOV by changing distance calculation (circle, square, etc.)
      angle - the angle in turns that will be the center of the FOV cone, 0 points right
      span - the angle in turns that measures the full arc contained in the FOV cone
      Returns:
      the computed light grid
    • reuseRippleFOV

      public static float[][] reuseRippleFOV(float[][] resistanceMap, float[][] light, int x, int y, float radius, Radius radiusTechnique)
      Like the reuseFOV(float[][], float[][], int, int, float, Radius) method, but this uses Ripple FOV with a tightness/looseness of 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.
      This method should not be used from multiple threads; it uses internal static state. You can use the Shadow FOV methods instead if you need multi-threading.
      Ripple is a significantly slower algorithm than Shadow, typically by more than an order of magnitude. Still, unless you are making many FOV calls per frame rendered, it's unlikely to be a severe bottleneck, although this is possible. Radiance, which typically makes an FOV call once per frame per Radiance, should always use Shadow, but if you only calculate FOV for the player, or only when they move, then either Shadow or Ripple can be suitable.
      Parameters:
      resistanceMap - probably calculated with generateResistances(char[][]); 1.0f blocks light, 0.0f allows it
      light - will be overwritten! Should be initialized with the same size as resistanceMap
      x - starting x position to look from
      y - starting y position to look from
      radius - the distance to extend from the starting x,y position
      radiusTechnique - how to measure distance; typically Radius.CIRCLE.
      Returns:
      light, after writing the FOV map into it; 1.0f is fully lit and 0.0f is unseen
    • reuseRippleFOV

      public static float[][] reuseRippleFOV(float[][] resistanceMap, float[][] light, int rippleLooseness, int x, int y, float radius, Radius radiusTechnique)
      Like the reuseFOV(float[][], float[][], int, int, float, 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.
      This method should not be used from multiple threads; it uses internal static state. You can use the Shadow FOV methods instead if you need multi-threading.
      Ripple is a significantly slower algorithm than Shadow, typically by more than an order of magnitude. Still, unless you are making many FOV calls per frame rendered, it's unlikely to be a severe bottleneck, although this is possible. Radiance, which typically makes an FOV call once per frame per Radiance, should always use Shadow, but if you only calculate FOV for the player, or only when they move, then either Shadow or Ripple can be suitable.
      Parameters:
      resistanceMap - probably calculated with generateResistances(char[][]); 1.0f blocks light, 0.0f allows it
      light - 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 loosest
      x - starting x position to look from
      y - starting y position to look from
      radius - the distance to extend from the starting x,y position
      radiusTechnique - how to measure distance; typically Radius.CIRCLE.
      Returns:
      light, after writing the FOV map into it; 1.0f is fully lit and 0.0f is unseen
    • reuseSoundField

      public static float[][] reuseSoundField(float[][] resistanceMap, float[][] sound, int x, int y, float radius, Radius radiusTechnique)
      Like the reuseFOV(float[][], float[][], int, int, float, Radius) method, but this is meant for sound rather than light, and so uses Ripple FOV with maximum looseness, and expects a sound resistance map rather than a light one. Other parameters are similar; you can get a sound resistance map from generateSoundResistances(char[][]), sound 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 for the sound, a radius in cells, and a Radius enum constant to choose the distance measurement.
      If you have loud background noise in a map, you can simulate all other sounds being harder to hear by subtracting some value from all results in sound. With the default settings in generateSoundResistances(char[][]), thin walls (one cell thick) and doors will allow some sound through, while thick walls (two or more cells) will allow none.
      This method should not be used from multiple threads; it uses internal static state.
      Parameters:
      resistanceMap - probably calculated with generateSoundResistances(char[][]); 1.0f blocks sound, 0.0f allows it
      sound - will be overwritten! Should be initialized with the same size as resistanceMap
      x - starting x position to emit sound from
      y - starting y position to emit sound from
      radius - the maximum distance to extend from the starting x,y position
      radiusTechnique - how to measure distance; typically Radius.CIRCLE.
      Returns:
      sound, after writing the sound field into it; 1.0f is max volume and 0.0f is inaudible
    • reuseRippleFOV

      public static float[][] reuseRippleFOV(float[][] resistanceMap, float[][] light, int rippleLooseness, int x, int y, float radius, Radius radiusTechnique, float angle, float span)
      Like the reuseFOV(float[][], float[][], int, int, float, Radius, float, float) 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).
      This method should not be used from multiple threads; it uses internal static state. You can use the Shadow FOV methods instead if you need multi-threading.
      Ripple is a significantly slower algorithm than Shadow, typically by more than an order of magnitude. Still, unless you are making many FOV calls per frame rendered, it's unlikely to be a severe bottleneck, although this is possible. Radiance, which typically makes an FOV call once per frame per Radiance, should always use Shadow, but if you only calculate FOV for the player, or only when they move, then either Shadow or Ripple can be suitable.
      Parameters:
      resistanceMap - probably calculated with generateResistances(char[][]); 1.0f blocks light, 0.0f allows it
      light - 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 loosest
      x - starting x position to look from
      y - starting y position to look from
      radius - the distance to extend from the starting x,y position
      radiusTechnique - how to measure distance; typically Radius.CIRCLE.
      angle - the angle to center the conical FOV on
      span - the total span in degrees for the conical FOV to cover
      Returns:
      light, after writing the FOV map into it; 1.0f is fully lit and 0.0f is unseen
    • bouncingLine

      public static float[][] bouncingLine(float[][] resistanceMap, float[][] light, int startX, int startY, float distance, float 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. The angle the path takes is given in degrees, and the angle used can change as obstacles are hit (reflecting backwards if it hits a corner pointing directly into or away from its path). This can be used something like an LOS method, but because the path can be traveled back over, an array or Queue becomes somewhat more complex, and the decreasing numbers for a straight line that stack may make more sense for how this could be used (especially with visual effects). This currently allows the path to pass through single-cell wall-like obstacles without changing direction, e.g. it passes through pillars, but will bounce if it hits a bigger wall.
      Parameters:
      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.0f is used to mean "unlit"
      startX - the horizontal component of the starting location
      startY - the vertical component of the starting location
      distance - the distance the light will extend to
      angle - in degrees, the angle to start the path traveling in
      Returns:
      the given light parameter, after modifications
    • reuseFOV

      public static float[][] reuseFOV(float[][] resistanceMap, float[][] light, int startX, int startY, float radius, Radius radiusTechnique, float angle, float forward, float sideForward, float side, float sideBack, float 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. 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(float[][], float[][]...) if you want to mix FOV results, which works as an alternative to using the prior light state.
      The starting point for the calculation is considered to be at the center of the origin cell. Radius determinations are determined by the provided RadiusStrategy. If all direction ranges are the same, this acts like reuseFOV(float[][], float[][], int, int, float, Radius); otherwise may produce conical shapes (potentially more than one, or overlapping ones).
      This is an alias for reuseFOVDeg(float[][], float[][], int, int, float, Radius, float, float, float, float, float, float).
      Parameters:
      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.0f is used to mean "unlit"
      startX - the horizontal component of the starting location
      startY - the vertical component of the starting location
      radius - the distance the light will extend to (roughly); direction ranges will be multiplied by this
      radiusTechnique - 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 right
      forward - the portion of radius to extend when the light is within 22.5f degrees of angle; will be interpolated with sideForward
      sideForward - the portion of radius to extend when the light is between 22.5f and 67.5f degrees of angle; will be interpolated with forward or side
      side - the portion of radius to extend when the light is between 67.5f and 112.5f degrees of angle; will be interpolated with sideForward or sideBack
      sideBack - the portion of radius to extend when the light is between 112.5f and 157.5f degrees of angle; will be interpolated with side or back
      back - the portion of radius to extend when the light is more than 157.5f degrees away from angle; will be interpolated with sideBack
      Returns:
      the computed light grid (the same as light)
    • reuseFOVRad

      public static float[][] reuseFOVRad(float[][] resistanceMap, float[][] light, int startX, int startY, float radius, Radius radiusTechnique, float angle, float forward, float sideForward, float side, float sideBack, float 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 radians, 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(float[][], float[][]...) if you want to mix FOV results, which works as an alternative to using the prior light state.
      The starting point for the calculation is considered to be at the center of the origin cell. Radius determinations are determined by the provided RadiusStrategy. If all direction ranges are the same, this acts like reuseFOV(float[][], float[][], int, int, float, Radius); otherwise may produce conical shapes (potentially more than one, or overlapping ones).
      Parameters:
      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.0f is used to mean "unlit"
      startX - the horizontal component of the starting location
      startY - the vertical component of the starting location
      radius - the distance the light will extend to (roughly); direction ranges will be multiplied by this
      radiusTechnique - provides a means to shape the FOV by changing distance calculation (circle, square, etc.)
      angle - the angle in radians that will be the center of the FOV cone, 0 points right
      forward - the portion of radius to extend when the light is within PI/8 radians of angle; will be interpolated with sideForward
      sideForward - the portion of radius to extend when the light is between PI/8 and 3*PI/8 radians of angle; will be interpolated with forward or side
      side - the portion of radius to extend when the light is between 3*PI/8 and 5*PI/8 radians of angle; will be interpolated with sideForward or sideBack
      sideBack - the portion of radius to extend when the light is between 5*PI/8 and 7*PI/8 radians of angle; will be interpolated with side or back
      back - the portion of radius to extend when the light is more than 7*PI/8 radians away from angle; will be interpolated with sideBack
      Returns:
      the computed light grid (the same as light)
    • reuseFOVDeg

      public static float[][] reuseFOVDeg(float[][] resistanceMap, float[][] light, int startX, int startY, float radius, Radius radiusTechnique, float angle, float forward, float sideForward, float side, float sideBack, float 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. 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(float[][], float[][]...) if you want to mix FOV results, which works as an alternative to using the prior light state.
      The starting point for the calculation is considered to be at the center of the origin cell. Radius determinations are determined by the provided RadiusStrategy. If all direction ranges are the same, this acts like reuseFOV(float[][], float[][], int, int, float, Radius); otherwise may produce conical shapes (potentially more than one, or overlapping ones).
      Parameters:
      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.0f is used to mean "unlit"
      startX - the horizontal component of the starting location
      startY - the vertical component of the starting location
      radius - the distance the light will extend to (roughly); direction ranges will be multiplied by this
      radiusTechnique - 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 right
      forward - the portion of radius to extend when the light is within 22.5f degrees of angle; will be interpolated with sideForward
      sideForward - the portion of radius to extend when the light is between 22.5f and 67.5f degrees of angle; will be interpolated with forward or side
      side - the portion of radius to extend when the light is between 67.5f and 112.5f degrees of angle; will be interpolated with sideForward or sideBack
      sideBack - the portion of radius to extend when the light is between 112.5f and 157.5f degrees of angle; will be interpolated with side or back
      back - the portion of radius to extend when the light is more than 157.5f degrees away from angle; will be interpolated with sideBack
      Returns:
      the computed light grid (the same as light)
    • reuseFOVTurns

      public static float[][] reuseFOVTurns(float[][] resistanceMap, float[][] light, int startX, int startY, float radius, Radius radiusTechnique, float angle, float forward, float sideForward, float side, float sideBack, float 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 turns, 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(float[][], float[][]...) if you want to mix FOV results, which works as an alternative to using the prior light state.
      The starting point for the calculation is considered to be at the center of the origin cell. Radius determinations are determined by the provided RadiusStrategy. If all direction ranges are the same, this acts like reuseFOV(float[][], float[][], int, int, float, Radius); otherwise may produce conical shapes (potentially more than one, or overlapping ones).
      Parameters:
      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.0f is used to mean "unlit"
      startX - the horizontal component of the starting location
      startY - the vertical component of the starting location
      radius - the distance the light will extend to (roughly); direction ranges will be multiplied by this
      radiusTechnique - provides a means to shape the FOV by changing distance calculation (circle, square, etc.)
      angle - the angle in turns that will be the center of the FOV cone, 0 points right
      forward - the portion of radius to extend when the light is within 1/16f turns of angle; will be interpolated with sideForward
      sideForward - the portion of radius to extend when the light is between 1/16f and 3/16f turns of angle; will be interpolated with forward or side
      side - the portion of radius to extend when the light is between 3/16f and 5/16f turns of angle; will be interpolated with sideForward or sideBack
      sideBack - the portion of radius to extend when the light is between 5/16f and 7/16f turns of angle; will be interpolated with side or back
      back - the portion of radius to extend when the light is more than 7/16f turns away from angle; will be interpolated with sideBack
      Returns:
      the computed light grid (the same as light)
    • reuseFOVOrtho

      @Beta public static float[][] reuseFOVOrtho(float[][] resistanceMap, float[][] light, int startX, int startY, float radius, Radius radiusTechnique)
      Calculates the symmetrical Field Of View for the provided resistanceMap from the given x, y viewer coordinates. Assigns to, and returns, a light map where the values represent a percentage of fully lit. If any cell in the returned light map is greater than 0, then both the viewer can see that cell, and anyone in that cell can see the viewer (if they have sufficient viewing range). Always uses Shadow FOV, and can reuse the state the user gives it via the 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 OrthoLine.
      The starting point for the calculation is considered to be at the center of the origin cell. Radius determinations are determined by the provided RadiusStrategy.
      Parameters:
      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.0f is used to mean "unlit"
      startX - the horizontal component of the starting location
      startY - the vertical component of the starting location
      radius - the distance the light will extend to
      radiusTechnique - provides a means to calculate the radius as desired
      Returns:
      the computed light grid, which is the same 2D array as the value assigned to light
    • addFOVsInto

      public static float[][] addFOVsInto(float[][] basis, float[][] addend)
      Adds an FOV grid to another in the simplest way possible; does not check line-of-sight between FOV grids. Clamps the highest value for any single position at 1.0f. Modifies the basis parameter in-place and makes no allocations; this is different from addFOVs(float[][][]), which creates a new 2D array.
      Parameters:
      basis - a 2D float array, which can be empty or returned by calculateFOV() or reuseFOV(); modified!
      addend - another 2D float array that will be added into basis; this one will not be modified
      Returns:
      the sum of the 2D float arrays passed, using the dimensions of basis if they don't match
    • addFOVs

      public static float[][] addFOVs(float[][]... grids)
      Adds multiple FOV grids together in the simplest way possible; does not check line-of-sight between FOV grids. Clamps the highest value for any single position at 1.0f. Allocates a new 2D float array and returns it.
      Parameters:
      grids - an array or vararg of 2D float arrays, each usually returned by calculateFOV()
      Returns:
      the sum of all the 2D float arrays passed, using the dimensions of the first if they don't all match
    • addFOVsInto

      public static float[][] addFOVsInto(float[][] basis, float[][]... grids)
      Adds multiple FOV grids to basis cell-by-cell, modifying basis; does not check line-of-sight between FOV grids. Clamps the highest value for any single position at 1.0f. Returns basis without allocating new objects.
      Parameters:
      basis - a 2D float array that will be modified by adding values in grids to it and clamping to 1.0f or less
      grids - an array or vararg of 2D float arrays, each usually returned by calculateFOV()
      Returns:
      basis, with all elements in all grids added to the corresponding cells and clamped
    • addFOVs

      public static float[][] addFOVs(Iterable<float[][]> grids)
      Adds multiple FOV grids together in the simplest way possible; does not check line-of-sight between FOV grids. Clamps the highest value for any single position at 1.0f. Allocates a new 2D float array and returns it.
      Parameters:
      grids - an Iterable of 2D float arrays (most collections implement Iterable), each usually returned by calculateFOV()
      Returns:
      the sum of all the 2D float arrays passed, using the dimensions of the first if they don't all match
    • mixVisibleFOVs

      public static float[][] mixVisibleFOVs(float[][] losGrid, float[][]... grids)
      Adds together multiple FOV grids, but only adds to a position if it is visible in the given LOS grid. Useful if you want distant lighting to be visible only if the player has line-of-sight to a lit cell. Typically the LOS grid is calculated by reuseLOS(float[][], float[][], int, int), using the same resistance grid used to calculate the FOV grids. Clamps the highest value for any single position at 1.0f.
      Parameters:
      losGrid - an LOS grid such as one generated by reuseLOS(float[][], float[][], int, int)
      grids - an array or vararg of 2D float arrays, each usually returned by calculateFOV()
      Returns:
      the sum of all the 2D float arrays in grids where a cell was visible in losGrid
    • mixVisibleFOVsInto

      public static float[][] mixVisibleFOVsInto(float[][] losGrid, float[][] basis, float[][]... grids)
      Adds together multiple FOV grids, but only adds to a position if it is visible in the given LOS grid. Useful if you want distant lighting to be visible only if the player has line-of-sight to a lit cell. Typically, the LOS grid is calculated by reuseLOS(float[][], float[][], int, int), using the same resistance grid used to calculate the FOV grids. Clamps the highest value for any single position at 1.0f.
      Parameters:
      losGrid - an LOS grid such as one generated by reuseLOS(float[][], float[][], int, int)
      basis - an existing 2D float array that should have matching width and height to losGrid; will be modified
      grids - an array or vararg of 2D float arrays, each usually returned by calculateFOV()
      Returns:
      the sum of all the 2D float arrays in grids where a cell was visible in losGrid
    • mixVisibleFOVs

      public static float[][] mixVisibleFOVs(float[][] losGrid, Iterable<float[][]> grids)
      Adds together multiple FOV grids, but only adds to a position if it is visible in the given LOS grid. Useful if you want distant lighting to be visible only if the player has line-of-sight to a lit cell. Typically the LOS grid is calculated by reuseLOS(float[][], float[][], int, int), using the same resistance grid used to calculate the FOV grids. Clamps the highest value for any single position at 1.0f.
      Parameters:
      losGrid - an LOS grid such as one generated by reuseLOS(float[][], float[][], int, int)
      grids - an Iterable of 2D float arrays, each usually returned by calculateFOV()
      Returns:
      the sum of all the 2D float arrays in grids where a cell was visible in losGrid
    • resistance

      public static float resistance(char cell)
      Given a single char, returns what generateResistances(char[][]) or fillResistancesInto(char[][], float[][]) would consider as its light resistance value. This means that for a wall char ('#' or a box drawing character) or an impossible-to-see character (' '), this returns a resistance of 1f, for an open door ('/') this returns 0.15f, for a closed door ('+') this returns 0.95f, and for any other char, this returns 0f.
      Parameters:
      cell - a single char that uses the place-map conventions the rest of this class uses
      Returns:
      the light resistance value for a cell represented by cell
    • simpleResistance

      public static float simpleResistance(char cell)
      Given a single char, returns what generateSimpleResistances(char[][]) or fillSimpleResistancesInto(char[][], float[][]) would consider as its light resistance value. This means that for a wall char ('#' or a box drawing character), a closed door ('+'), or an impossible-to-see character (' '), this returns a resistance of 1f, and for any other char, this returns 0f.
      Parameters:
      cell - a single char that uses the place-map conventions the rest of this class uses
      Returns:
      the light resistance value for a cell represented by cell
    • generateResistances

      public static float[][] generateResistances(char[][] map)
      Given a char[][] for the local area, produces a float[][] that can be used with most of the methods in FOV, like reuseFOV(float[][], float[][], int, int, float). It expects any doors to be represented by '+' if closed or '/' if open, 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). Open doors slightly obscure light, closed doors obscure almost all light coming from the other side, walls block all light, and anything else does not obscure light.
      Parameters:
      map - a dungeon, width by height, with any closed doors as '+' and open doors as '/'
      Returns:
      a resistance map suitable for use with the FOV class, with clear cells assigned 0.0f and blocked ones 1.0f
      See Also:
    • fillResistancesInto

      public static float[][] fillResistancesInto(char[][] grid, float[][] into)
      Given a char[][] for the local area and a float[][] with the same dimensions as the chars, fills the float[][] so it can be used with most of the methods in FOV, like reuseFOV(float[][], float[][], int, int, float). It expects any doors to be represented by '+' if closed or '/' if open, 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). Open doors slightly obscure light, closed doors obscure almost all light coming from the other side, walls block all light, and anything else does not obscure light.
      Parameters:
      grid - a 2D char array, width by height, with any closed doors as '+' and open doors as '/'
      into - a 2D float array that should have the same dimensions as grid; will be modified completely
      Returns:
      into modified so it acts as a resistance grid, with clear cells assigned 0.0f and blocked ones 1.0f
    • generateResistances3x3

      public static float[][] generateResistances3x3(char[][] grid)
      Given a char[][] for the local area that should use box drawing characters, produces a float[][] with triple width and triple height that can be used with FOV methods like reuseFOV(float[][], float[][], int, int, float) 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, 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, and walls obscure light and thus have a resistance normally).
      Parameters:
      grid - a place grid as a 2D char array, width by height, with any closed doors as '+' and open doors as '/'
      Returns:
      a resistance grid suitable for use with the FOV class and subcell lighting, with triple width/height
    • generateSimpleResistances

      public static float[][] generateSimpleResistances(char[][] grid)
      Given a char[][] for the local area, produces a float[][] that can be used with any FOV methods that expect a resistance grid (like reuseFOV(float[][], float[][], int, int, float)), 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, and any walls to be '#' or box drawing characters. This will assign 1.0f resistance to walls and closed doors or 0.0f for any other cell.
      Parameters:
      grid - a place grid, width by height, with any closed doors as '+' and open doors as '/'
      Returns:
      a resistance grid suitable for use with the FOV class, but with no partially transparent cells
    • fillSimpleResistancesInto

      public static float[][] fillSimpleResistancesInto(char[][] grid, float[][] into)
      Given a char[][] for the local area and a float[][] with the same dimensions as the chars, fills the float[][] so it can be used with most of the methods in FOV, like reuseFOV(float[][], float[][], int, int, float), 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, and any walls to be '#' or box drawing characters. This will assign 1.0f resistance to walls and closed doors or 0.0f for any other cell.
      Parameters:
      grid - a 2D char array, width by height, with any closed doors as '+' and open doors as '/'
      into - a 2D float array that should have the same dimensions as grid; will be modified completely
      Returns:
      into modified so it acts as a resistance grid, with clear cells assigned 0.0f and blocked ones 1.0f
    • generateSimpleResistances3x3

      public static float[][] generateSimpleResistances3x3(char[][] grid)
      Given a char[][] for the local area that should use box drawing characters, produces a float[][] with triple width and triple height that can be used with FOV's methods that expect a resistance grid (like reuseFOV(float[][], float[][], int, int, float)) in classes that use subcell lighting. This expects any doors to be represented by '+' if closed or '/' if open, any walls to be box drawing characters, and any cells that block all subcells within their area to be '#'. This will assign 1.0f resistance to walls and closed doors where a line of the box drawing char would block light, or 0.0f for any other subcell.
      Parameters:
      grid - a dungeon, width by height, with any closed doors as '+' and open doors as '/'
      Returns:
      a resistance grid suitable for use with the FOV class and subcell lighting, with triple width/height
    • generateSoundResistances

      public static float[][] generateSoundResistances(char[][] grid)
      Given a char[][] for the local area, produces a float[][] that can be used with the sound-related methods here, allowing sound to pass through thin-enough walls and doors. It expects any doors to be represented by '+' if closed or '/' if open, any walls to be '#' or box drawing characters, anything that can't possibly let sound through to be ' ' or Unicode u0001, and lets everything else permit sound to pass freely. Open doors slightly obscure sound (by 5%), closed doors obscure 30% of sound coming from the other side, walls block 55% of the sound (making walls that are 2-cells-thick block all sound, but 1-cell-thick walls won't), the ' ' and Unicode 1 cells block all sound, and everything else lets sound through.
      Parameters:
      grid - a 2D char array, width by height, with any closed doors as '+' and open doors as '/'
      Returns:
      a resistance grid meant for sound resistance rather than light, with clear cells assigned 0.0f and fully-blocked ones 1.0f
    • cellsByDescendingValue

      public static CoordFloatOrderedMap cellsByDescendingValue(float[][] fovGrid)
      Given a typical FOV grid produced by reuseFOV(float[][], float[][], int, int), reuseRippleFOV(float[][], float[][], int, int, float, Radius), or a similar method, this gets a CoordFloatOrderedMap containing only the visible Coord cells as keys, associated with their visibility levels, and ordered so the most-visible cell (typically where the viewer is) is first in the iteration order. Lower visibility values will go later and later in the iteration order. This method allocates a new CoordFloatOrderedMap; if you want to reuse an existing one, use fillCellsByDescendingValue(float[][], CoordFloatOrderedMap) instead.
      Parameters:
      fovGrid - a rectangular 2D float array ideally containing values greater than 0 and less than or equal to 1
      Returns:
      a CoordFloatOrderedMap containing the non-zero values in fovGrid, ordered from the highest value to lowest
    • fillCellsByDescendingValue

      public static CoordFloatOrderedMap fillCellsByDescendingValue(float[][] fovGrid, CoordFloatOrderedMap modifying)
      Given a typical FOV map produced by reuseFOV(float[][], float[][], int, int), reuseRippleFOV(float[][], float[][], int, int, float, Radius), or a similar method and a CoordFloatOrderedMap modifying to clear and reuse in-place, this fills modifying with only the visible Coord cells as keys, associated with their visibility levels, and ordered so the most-visible cell (typically where the viewer is) is first in the iteration order. Lower visibility values will go later and later in the iteration order. This is meant to reuse a CoordFloatOrderedMap to avoid allocations, but if you don't have one, you could easily call cellsByDescendingValue(float[][]) to get a starting point.
      Parameters:
      fovGrid - a rectangular 2D float array ideally containing values greater than 0 and less than or equal to 1
      modifying - a CoordFloatOrderedMap that will have its contents cleared and then refilled by this
      Returns:
      modifying now containing the non-zero values in fovGrid, ordered from the highest value to lowest