public class FOVCache extends FOV
has various utilities for operating on compressed data of this kind.
Created by Tommy Ettinger on 10/7/2015.
,
Serialized FormModifier and Type | Class and Description |
---|---|
protected class |
FOVCache.FOVUnit |
protected class |
FOVCache.LOSUnit |
protected class |
FOVCache.PerformanceUnit |
protected class |
FOVCache.QualityUnit |
protected class |
FOVCache.RefreshUnit |
protected class |
FOVCache.SymmetryUnit |
Modifier and Type | Field and Description |
---|---|
protected short[][] |
ALL_WALLS |
protected double[][] |
atan2Cache |
protected short[][][] |
cache |
protected boolean |
complete |
protected double |
decay |
protected double[][] |
directionAngles |
protected short[][] |
distanceCache |
protected FOV |
fov |
protected double |
fovPermissiveness |
protected FOV |
gradedFOV |
protected int |
height |
protected int[] |
lightBrightnesses |
protected LinkedHashMap<Coord,Integer> |
lights |
protected Coord[] |
lightSources |
protected int |
limit |
protected short[][] |
losCache |
protected int |
mapLimit |
protected int |
maxLOSRadius |
protected int |
maxRadius |
protected int |
NUM_THREADS |
protected boolean |
qualityComplete |
protected Radius |
radiusKind |
protected boolean |
refreshComplete |
protected double[][] |
resMap |
protected short[][][] |
tmpCache |
protected short[] |
wallMap |
protected Coord[][] |
waves |
protected int |
width |
RIPPLE, RIPPLE_LOOSE, RIPPLE_TIGHT, RIPPLE_VERY_LOOSE, SHADOW
Constructor and Description |
---|
FOVCache(char[][] map,
int maxRadius,
int maxLOSRadius,
Radius radiusKind,
int threadCount)
Create an FOVCache for a given map (as a char[][]), caching all FOV radii from 0 up to and including maxRadius,
using the given Radius enum to determine FOV shape.
|
FOVCache(char[][] map,
int maxRadius,
int maxLOSRadius,
Radius radiusKind,
int threadCount,
Map<Coord,Integer> lights)
Create an FOVCache for a given map (as a char[][]), caching all FOV radii from 0 up to and including maxRadius,
using the given Radius enum to determine FOV shape.
|
FOVCache(char[][] map,
int maxRadius,
Radius radiusKind)
Create an FOVCache for a given map (as a char[][]), caching all FOV radii from 0 up to and including maxRadius,
using the given Radius enum to determine FOV shape.
|
Modifier and Type | Method and Description |
---|---|
long |
approximateMemoryUsage() |
boolean |
awaitCache()
If FOV calculations from cacheAll() are being done on another thread, calling this method will make
the current thread wait for the FOV calculations' thread to finish, "freezing" the current thread until it does.
|
boolean |
awaitRefresh(char[][] newMap)
If FOV calculations from refreshCache() are being done on another thread, calling this method will make
the current thread wait for the FOV calculations' thread to finish, "freezing" the current thread until it does.
|
void |
cacheAll()
Runs FOV calculations on another thread, without interrupting this one, then performs additional quality tweaks
and adds any distant lights, if there were any in the constructor.
|
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 conical Field Of View for the provided map from the given
x, y coordinates.
|
Coord[] |
calculateLOS(int startX,
int startY,
int endX,
int endY)
Calculates an array of Coord positions that can be seen along the line from the given start point and end point.
|
short[] |
calculatePackedLOS(int viewerX,
int viewerY)
Packs FOV for the given viewer's X and Y as a center, and returns the packed data to be stored.
|
short[][] |
calculatePackedSlopeShadowFOV(int viewerX,
int viewerY)
Packs FOV for the given viewer's X and Y as a center, and returns the packed data to be stored.
|
short[][] |
calculatePackedWaveFOV(int viewerX,
int viewerY)
Packs FOV for the given viewer's X and Y as a center, and returns the packed data to be stored.
|
short[][] |
getCacheEntry(int x,
int y) |
short[] |
getCacheEntry(int x,
int y,
int radius) |
int |
getHeight() |
short[] |
getLOSEntry(int x,
int y) |
int |
getMaxRadius() |
Radius |
getRadiusKind() |
int |
getWidth() |
short[][] |
improveQuality(int viewerX,
int viewerY) |
boolean |
isCellVisible(int visionRange,
int viewerX,
int viewerY,
int targetX,
int targetY) |
double[][][] |
pathFOV(List<Coord> path,
int fovRange)
Given a path as a List of Coords (such as one produced by DijkstraMap.getPath()), this method will look up the
FOV for the given fovRange at each Coord, and returns an array of full FOV maps where each map is the union
of the FOV centered on a Coord in path with all FOVs centered on previous Coords in path.
|
short[][] |
pathFOVPacked(List<Coord> path,
int fovRange)
Given a path as a List of Coords (such as one produced by DijkstraMap.getPath()), this method will look up the
FOV for the given fovRange at each Coord, and returns an array of packed FOV maps where each map is the union
of the FOV centered on a Coord in path with all FOVs centered on previous Coords in path.
|
boolean |
queryCache(int visionRange,
int viewerX,
int viewerY,
int targetX,
int targetY) |
boolean |
queryLOS(int viewerX,
int viewerY,
int targetX,
int targetY) |
void |
refreshCache(char[][] newMap)
Runs FOV calculations for any cells that were changed as a result of newMap being different from the map passed
to the FOVCache constructor.
|
short[] |
removeWalls(short[] packed)
When you have some packed on/off data and want to make sure it does not include walls, you can use this.
|
byte[][] |
slopeShadowFOV(int viewerX,
int viewerY) |
Coord[] |
sortedLOS(int startX,
int startY,
int endX,
int endY)
Calculates an array of Coord positions that can be seen along the line from the given start point and end point.
|
protected long |
storeCellFOV(int index)
Packs FOV for a point as a center, and returns it to be stored.
|
protected long |
storeCellLOS(int index)
Packs FOV for a point as a center, and returns it to be stored.
|
protected long |
storeCellSymmetry(int index)
Uses previously cached FOV and makes it symmetrical.
|
double[][] |
teamFOV(Map<Coord,Integer> team)
In games that have multiple characters who should share one FOV map, this method should provide optimal
performance when collecting several cached FOV maps into one full map.
|
short[] |
teamFOVPacked(Map<Coord,Integer> team)
In games that have multiple characters who should share one FOV map, this method should provide optimal
performance when collecting several cached FOV maps into one packed map.
|
byte[][] |
waveFOV(int viewerX,
int viewerY) |
addFOVs, addFOVs, calculateLOSMap, mixVisibleFOVs, mixVisibleFOVs
protected int maxRadius
protected int maxLOSRadius
protected int width
protected int height
protected int mapLimit
protected int limit
protected double[][] resMap
protected Radius radiusKind
protected short[][][] cache
protected short[][][] tmpCache
protected short[][] losCache
protected boolean complete
protected boolean qualityComplete
protected boolean refreshComplete
protected short[][] ALL_WALLS
protected short[] wallMap
protected double[][] atan2Cache
protected double[][] directionAngles
protected short[][] distanceCache
protected final int NUM_THREADS
protected double fovPermissiveness
protected LinkedHashMap<Coord,Integer> lights
protected Coord[] lightSources
protected int[] lightBrightnesses
protected double decay
public FOVCache(char[][] map, int maxRadius, Radius radiusKind)
map
- a char[][] as returned by SquidLib's map generatorsmaxRadius
- the longest radius that will possibly need to be cached for FOV; LOS is separateradiusKind
- a Radius enum that determines the shape of each FOV areapublic FOVCache(char[][] map, int maxRadius, int maxLOSRadius, Radius radiusKind, int threadCount)
map
- a char[][] as returned by SquidLib's map generatorsmaxRadius
- the longest radius that will possibly need to be cached for FOV; LOS is separatemaxLOSRadius
- the longest radius that will possibly need to be cached for LOS, must be less than 63radiusKind
- a Radius enum that determines the shape of each FOV areathreadCount
- how many threads to use during the full-map calculationspublic FOVCache(char[][] map, int maxRadius, int maxLOSRadius, Radius radiusKind, int threadCount, Map<Coord,Integer> lights)
map
- a char[][] as returned by SquidLib's map generatorsmaxRadius
- the longest radius that will possibly need to be cached for FOV; LOS is separatemaxLOSRadius
- the longest radius that will possibly need to be cached for LOS, must be less than 63radiusKind
- a Radius enum that determines the shape of each FOV areathreadCount
- how many threads to use during the full-map calculationslights
- a Map of Coords (which should be walkable) to the radii they should light (not for moving lights)protected long storeCellFOV(int index)
index
- an int that stores the x,y center of FOV as calculated by: x + y * widthprotected long storeCellLOS(int index)
index
- an int that stores the x,y center of FOV as calculated by: x + y * widthprotected long storeCellSymmetry(int index)
index
- an int that stores the x,y center of FOV as calculated by: x + y * widthpublic short[] calculatePackedLOS(int viewerX, int viewerY)
viewerX
- an int less than 256 and less than widthviewerY
- an int less than 256 and less than heightpublic short[][] calculatePackedSlopeShadowFOV(int viewerX, int viewerY)
viewerX
- an int less than 256 and less than widthviewerY
- an int less than 256 and less than heightpublic short[][] calculatePackedWaveFOV(int viewerX, int viewerY)
viewerX
- an int less than 256 and less than widthviewerY
- an int less than 256 and less than heightpublic short[][] getCacheEntry(int x, int y)
public short[] getCacheEntry(int x, int y, int radius)
public short[] getLOSEntry(int x, int y)
public boolean queryCache(int visionRange, int viewerX, int viewerY, int targetX, int targetY)
public boolean isCellVisible(int visionRange, int viewerX, int viewerY, int targetX, int targetY)
public boolean queryLOS(int viewerX, int viewerY, int targetX, int targetY)
public long approximateMemoryUsage()
public byte[][] waveFOV(int viewerX, int viewerY)
public byte[][] slopeShadowFOV(int viewerX, int viewerY)
public short[][] improveQuality(int viewerX, int viewerY)
public void cacheAll()
public boolean awaitCache()
public void refreshCache(char[][] newMap)
public boolean awaitRefresh(char[][] newMap)
public double[][] calculateFOV(double[][] resistanceMap, int startx, int starty)
calculateFOV
in class FOV
resistanceMap
- the grid of cells to calculate onstartx
- the horizontal component of the starting locationstarty
- the vertical component of the starting locationpublic double[][] calculateFOV(double[][] resistanceMap, int startx, int starty, double radius)
calculateFOV
in class FOV
resistanceMap
- the grid of cells to calculate onstartx
- 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)
calculateFOV
in class FOV
resistanceMap
- the grid of cells to calculate onstartX
- 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)
calculateFOV
in class FOV
resistanceMap
- the grid of cells to calculate onstartX
- 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 Coord[] calculateLOS(int startX, int startY, int endX, int endY)
startX
- the x position of the starting point; must be within bounds of the mapstartY
- the y position of the starting point; must be within bounds of the mapendX
- the x position of the endpoint; does not need to be within bounds (will stop LOS at the edge)endY
- the y position of the endpoint; does not need to be within bounds (will stop LOS at the edge)public Coord[] sortedLOS(int startX, int startY, int endX, int endY)
startX
- the x position of the starting point; must be within bounds of the mapstartY
- the y position of the starting point; must be within bounds of the mapendX
- the x position of the endpoint; does not need to be within bounds (will stop LOS at the edge)endY
- the y position of the endpoint; does not need to be within bounds (will stop LOS at the edge)public short[][] pathFOVPacked(List<Coord> path, int fovRange)
path
- a List of Coords that will be added, in order, to multiple packed FOVs for the path so farfovRange
- the radius the creature or thing taking the path can see (or possibly light up).public double[][][] pathFOV(List<Coord> path, int fovRange)
path
- a List of Coords that will be added, in order, to multiple FOVs for the path so farfovRange
- the radius the creature or thing taking the path can see (or possibly light up).public short[] teamFOVPacked(Map<Coord,Integer> team)
team
- a Map of Coord keys for characters' positions to Integer values for the FOV range of each characterpublic double[][] teamFOV(Map<Coord,Integer> team)
team
- a Map of Coord keys for characters' positions to Integer values for the FOV range of each characterpublic short[] removeWalls(short[] packed)
packed
- a short[] produced by some CoordPacker method or obtained by getLOSEntry() or getCacheEntry().public int getMaxRadius()
public Radius getRadiusKind()
public int getWidth()
public int getHeight()
Copyright © 2012–2016. All rights reserved.