public class LightingHandler
extends java.lang.Object
implements java.io.Serializable
char[][]
. After constructing a LightingHandler with the resistances for a
level, you should add all light sources with their positions, either using addLight(int, int, Radiance)
or
by directly putting keys and values into lights
. Then you can calculate the visible cells once lighting is
considered (which may include distant lit cells with unseen but unobstructing cells between the viewer and the light)
using calculateFOV(Coord)
, which should be called every time the viewer moves. You can update the flicker
and strobe effects on all Radiance objects, which is typically done every frame, using update()
or
updateAll()
(updateAll() is for when there is no viewer), and once that update() call has been made you can
call draw(SparseLayers)
to change the background colors of a SparseLayers, draw(SquidPanel)
to
change the colors of a SquidPanel (typically the background layer of a SquidLayers, as from
SquidLayers.getBackgroundLayer()
), or draw(float[][])
to change a 2D float array that holds packed
float colors (which may be used in some custom setup). To place user-interface lighting effects that don't affect the
actual FOV of creatures in the game, you can use updateUI(Coord, Radiance)
, which is called after
update()
but before draw(float[][])
.
Modifier and Type | Field and Description |
---|---|
float |
backgroundColor
The packed float color to mix background cells with when a cell has lighting and is within line-of-sight, but has
no background color to start with (its color is 0f as a packed float, or
SColor.TRANSPARENT ). |
float[][][] |
colorLighting
A pair of 2D float arrays with different usages;
colorLighting[0] is a 2D array that stores the strength
of light in each cell, and colorLighting[1] is a 2D array that stores the color of light in each cell, as
a packed float color. |
double[][] |
fovResult
What the "viewer" (as passed to
calculateFOV(Coord) ) can see either nearby without light or because an
area in line-of-sight has light in it. |
int |
height
Height of the 2D arrays used in this, as obtained from
resistances . |
squidpony.squidmath.OrderedMap<squidpony.squidmath.Coord,Radiance> |
lights
A mapping from positions as
Coord objects to Radiance objects that describe the color, lighting
radius, and changes over time of any in-game lights that should be shown on the map and change FOV. |
double[][] |
losResult
A 2D array of doubles that are either 0.0 if a cell has an obstruction between it and the viewer, or greater than
0.0 otherwise.
|
squidpony.squidmath.GreasedRegion |
noticeable
A GreasedRegion that stores any cells that are in line-of-sight or are close enough to a cell in line-of-sight to
potentially cast light into such a cell.
|
squidpony.squidgrid.Radius |
radiusStrategy
How light should spread; usually
Radius.CIRCLE unless gameplay reasons need it to be SQUARE or DIAMOND. |
double[][] |
resistances
The 2D array of light-resistance values from 0.0 to 1.0 for each cell on the map, as produced by
FOV.generateResistances(char[][]) . |
float[][][] |
tempColorLighting
Temporary storage array used for calculations involving
colorLighting ; it sometimes may make sense for
other code to use this as temporary storage as well. |
double[][] |
tempFOV
Temporary storage array used for calculations involving
fovResult ; it sometimes may make sense for other
code to use this as temporary storage as well. |
double |
viewerRange
How far the viewer can see without light; defaults to 4.0 cells, and you are encouraged to change this member
field if the vision range changes after construction.
|
int |
width
Width of the 2D arrays used in this, as obtained from
resistances . |
Constructor and Description |
---|
LightingHandler()
Unlikely to be used except during serialization; makes a LightingHandler for a 20x20 fully visible level.
|
LightingHandler(double[][] resistance)
Given a resistance array as produced by
FOV.generateResistances(char[][])
or FOV.generateSimpleResistances(char[][]) , makes a
LightingHandler that can have Radiance objects added to it in various locations. |
LightingHandler(double[][] resistance,
com.badlogic.gdx.graphics.Color backgroundColor,
squidpony.squidgrid.Radius radiusStrategy,
double viewerVisionRange)
Given a resistance array as produced by
FOV.generateResistances(char[][])
or FOV.generateSimpleResistances(char[][]) , makes a
LightingHandler that can have Radiance objects added to it in various locations. |
LightingHandler(double[][] resistance,
float backgroundColor,
squidpony.squidgrid.Radius radiusStrategy,
double viewerVisionRange)
Given a resistance array as produced by
FOV.generateResistances(char[][])
or FOV.generateSimpleResistances(char[][]) , makes a
LightingHandler that can have Radiance objects added to it in various locations. |
Modifier and Type | Method and Description |
---|---|
LightingHandler |
addLight(squidpony.squidmath.Coord position,
Radiance light)
Adds a Radiance as a light source at the given position.
|
LightingHandler |
addLight(int x,
int y,
Radiance light)
Adds a Radiance as a light source at the given position.
|
double[][] |
calculateFOV(squidpony.squidmath.Coord viewer)
Used to calculate what cells are visible as if any flicker or strobe effects were simply constant light sources.
|
double[][] |
calculateFOV(int viewerX,
int viewerY)
Used to calculate what cells are visible as if any flicker or strobe effects were simply constant light sources.
|
double[][] |
calculateFOV(int viewerX,
int viewerY,
int minX,
int minY,
int maxX,
int maxY)
Used to calculate what cells are visible as if any flicker or strobe effects were simply constant light sources.
|
void |
draw(float[][] backgrounds)
Given a 2D array of packed float colors, fills the 2D array with different colors based on what lights are
present in line of sight of the viewer and the various flicker or strobe effects that Radiance light sources can
do.
|
void |
draw(SparseLayers layers)
Given a SparseLayers, fills the SparseLayers with different colors based on what lights are present in line of
sight of the viewer and the various flicker or strobe effects that Radiance light sources can do.
|
void |
draw(SquidPanel background)
Given a SquidPanel that should be only solid blocks (such as the background of a SquidLayers) and a position for
the viewer (typically the player), fills the SquidPanel with different colors based on what lights are present in
line of sight of the viewer and the various flickering or pulsing effects that Radiance light sources can do.
|
Radiance |
get(squidpony.squidmath.Coord position)
Gets the Radiance at the given position, if present, or null if there is no light source there.
|
Radiance |
get(int x,
int y)
Gets the Radiance at the given position, if present, or null if there is no light source there.
|
void |
mixColoredLighting(float flare)
Edits
colorLighting by adding in and mixing the colors in tempColorLighting , with the strength
of light in tempColorLighting boosted by flare (which can be any finite float greater than -1f, but is usually
from 0f to 1f when increasing strength). |
void |
mixColoredLighting(float flare,
float color)
Edits
colorLighting by adding in and mixing the given color where the light strength in tempFOV
is greater than 0, with that strength boosted by flare (which can be any finite float greater than -1f, but is
usually from 0f to 1f when increasing strength). |
LightingHandler |
moveLight(squidpony.squidmath.Coord oldPosition,
squidpony.squidmath.Coord newPosition)
If a Radiance is present at oldPosition, this will move it to newPosition and overwrite any existing Radiance at
newPosition.
|
LightingHandler |
moveLight(int oldX,
int oldY,
int newX,
int newY)
If a Radiance is present at oldX,oldY, this will move it to newX,newY and overwrite any existing Radiance at
newX,newY.
|
LightingHandler |
removeLight(squidpony.squidmath.Coord position)
Removes a Radiance as a light source from the given position, if any is present.
|
LightingHandler |
removeLight(int x,
int y)
Removes a Radiance as a light source from the given position, if any is present.
|
void |
update()
Typically called every frame, this updates the flicker and strobe effects of Radiance objects and applies those
changes in lighting color and strength to the various fields of this LightingHandler.
|
void |
updateAll()
Typically called every frame when there isn't a single viewer, this updates the flicker and strobe effects of
Radiance objects and applies those changes in lighting color and strength to the various fields of this
LightingHandler.
|
void |
updateUI(squidpony.squidmath.Coord pos,
Radiance radiance)
Updates the flicker and strobe effects of a Radiance object and applies the lighting from just that Radiance to
just the
colorLighting field, without changing FOV. |
void |
updateUI(int lightX,
int lightY,
Radiance radiance)
Updates the flicker and strobe effects of a Radiance object and applies the lighting from just that Radiance to
just the
colorLighting field, without changing FOV. |
public squidpony.squidgrid.Radius radiusStrategy
Radius.CIRCLE
unless gameplay reasons need it to be SQUARE or DIAMOND.public double[][] resistances
FOV.generateResistances(char[][])
.public double[][] fovResult
calculateFOV(Coord)
) can see either nearby without light or because an
area in line-of-sight has light in it. Edited by calculateFOV(Coord)
and update()
, but
not updateUI(Coord, Radiance)
(which is meant for effects that are purely user-interface).public double[][] losResult
public double[][] tempFOV
fovResult
; it sometimes may make sense for other
code to use this as temporary storage as well.public float[][][] colorLighting
colorLighting[0]
is a 2D array that stores the strength
of light in each cell, and colorLighting[1]
is a 2D array that stores the color of light in each cell, as
a packed float color. Both 2D arrays are the size of the map, as defined by resistances
initially and
later available in width
and height
.public float[][][] tempColorLighting
colorLighting
; it sometimes may make sense for
other code to use this as temporary storage as well.public int width
resistances
.public int height
resistances
.public float backgroundColor
SColor.TRANSPARENT
).public double viewerRange
public squidpony.squidmath.OrderedMap<squidpony.squidmath.Coord,Radiance> lights
Coord
objects to Radiance
objects that describe the color, lighting
radius, and changes over time of any in-game lights that should be shown on the map and change FOV. You can edit
this manually or by using moveLight(int, int, int, int)
, addLight(int, int, Radiance)
, and
removeLight(int, int)
.public squidpony.squidmath.GreasedRegion noticeable
Radiance.range
in lights
.public LightingHandler()
public LightingHandler(double[][] resistance)
FOV.generateResistances(char[][])
or FOV.generateSimpleResistances(char[][])
, makes a
LightingHandler that can have Radiance
objects added to it in various locations. This will use a solid
black background when it casts light on cells without existing lighting. The viewer vision range will be 4.0, and
lights will use a circular shape.resistance
- a resistance array as produced by DungeonUtilitypublic LightingHandler(double[][] resistance, com.badlogic.gdx.graphics.Color backgroundColor, squidpony.squidgrid.Radius radiusStrategy, double viewerVisionRange)
FOV.generateResistances(char[][])
or FOV.generateSimpleResistances(char[][])
, makes a
LightingHandler that can have Radiance
objects added to it in various locations.resistance
- a resistance array as produced by DungeonUtilitybackgroundColor
- the background color to use, as a libGDX colorradiusStrategy
- the shape lights should take, typically Radius.CIRCLE
for "realistic" lights or one
of Radius.DIAMOND
or Radius.SQUARE
to match game rules for distanceviewerVisionRange
- how far the player can see without light, in cellspublic LightingHandler(double[][] resistance, float backgroundColor, squidpony.squidgrid.Radius radiusStrategy, double viewerVisionRange)
FOV.generateResistances(char[][])
or FOV.generateSimpleResistances(char[][])
, makes a
LightingHandler that can have Radiance
objects added to it in various locations.resistance
- a resistance array as produced by DungeonUtilitybackgroundColor
- the background color to use, as a packed float (produced by Color.toFloatBits()
)radiusStrategy
- the shape lights should take, typically Radius.CIRCLE
for "realistic" lights or one
of Radius.DIAMOND
or Radius.SQUARE
to match game rules for distanceviewerVisionRange
- how far the player can see without light, in cellspublic LightingHandler addLight(int x, int y, Radiance light)
x
- the x-position to add the Radiance aty
- the y-position to add the Radiance atlight
- a Radiance object that can have a changing radius, color, and various other effects on lightingpublic LightingHandler addLight(squidpony.squidmath.Coord position, Radiance light)
position
- the position to add the Radiance atlight
- a Radiance object that can have a changing radius, color, and various other effects on lightingpublic LightingHandler removeLight(int x, int y)
x
- the x-position to remove the Radiance fromy
- the y-position to remove the Radiance frompublic LightingHandler removeLight(squidpony.squidmath.Coord position)
position
- the position to remove the Radiance frompublic LightingHandler moveLight(int oldX, int oldY, int newX, int newY)
oldX
- the x-position to move a Radiance fromoldY
- the y-position to move a Radiance fromnewX
- the x-position to move a Radiance tonewY
- the y-position to move a Radiance topublic LightingHandler moveLight(squidpony.squidmath.Coord oldPosition, squidpony.squidmath.Coord newPosition)
oldPosition
- the Coord to move a Radiance fromnewPosition
- the Coord to move a Radiance topublic Radiance get(int x, int y)
x
- the x-position to look upy
- the y-position to look uppublic Radiance get(squidpony.squidmath.Coord position)
position
- the position to look uppublic void mixColoredLighting(float flare)
colorLighting
by adding in and mixing the colors in tempColorLighting
, with the strength
of light in tempColorLighting boosted by flare (which can be any finite float greater than -1f, but is usually
from 0f to 1f when increasing strength).
Primarily used internally, but exposed so outside code can do the same things this class can.flare
- boosts the effective strength of lighting in tempColorLighting
; usually from 0 to 1public void mixColoredLighting(float flare, float color)
colorLighting
by adding in and mixing the given color where the light strength in tempFOV
is greater than 0, with that strength boosted by flare (which can be any finite float greater than -1f, but is
usually from 0f to 1f when increasing strength).
Primarily used internally, but exposed so outside code can do the same things this class can.flare
- boosts the effective strength of lighting in tempColorLighting
; usually from 0 to 1public void update()
calculateFOV(Coord)
or calculateFOV(int, int)
was called during the last time the
viewer position changed; typically calculateFOV() only needs to be called once per move, while update() needs to
be called once per frame. This method is usually called before each call to draw(float[][])
, but other
code may be between the calls and may affect the lighting in customized ways.public void updateAll()
draw(float[][])
, but other code may
be between the calls and may affect the lighting in customized ways. This overload has no viewer, so all cells
are considered visible unless they are fully obstructed (solid cells behind walls, for example). Unlike update(),
this method does not need calculateFOV(Coord)
to be called for it to work properly.public void updateUI(squidpony.squidmath.Coord pos, Radiance radiance)
colorLighting
field, without changing FOV. This method is meant to be used for GUI effects that
aren't representative of something a character in the game could interact with. It is usually called after
update()
and before each call to draw(float[][])
, but other code may be between the calls
and may affect the lighting in customized ways.pos
- the position of the light effectradiance
- the Radiance to update standalone, which does not need to be already added to thispublic void updateUI(int lightX, int lightY, Radiance radiance)
colorLighting
field, without changing FOV. This method is meant to be used for GUI effects that
aren't representative of something a character in the game could interact with. It is usually called after
update()
and before each call to draw(float[][])
, but other code may be between the calls
and may affect the lighting in customized ways.lightX
- the x-position of the light effectlightY
- the y-position of the light effectradiance
- the Radiance to update standalone, which does not need to be already added to thispublic void draw(SparseLayers layers)
update()
before each call to draw(), but you may want to make custom changes to the
lighting in between those two calls (that is the only place those changes will be noticed).layers
- a SparseLayers that may have existing background colors (these will be mixed in)public void draw(SquidPanel background)
update()
before each call to draw(), but you may want to make custom changes to the lighting in between those two calls
(that is the only place those changes will be noticed).background
- a SquidPanel used as a background, such as the back Panel of a SquidLayerspublic void draw(float[][] backgrounds)
update()
before each call to draw(), but you may want to make custom
changes to the lighting in between those two calls (that is the only place those changes will be noticed).backgrounds
- a 2D float array, typically obtained from SquidPanel.colors
or SparseLayers.backgrounds
public double[][] calculateFOV(squidpony.squidmath.Coord viewer)
update()
gets called to change lighting at the new cell. This sets
important information on what lights might need to be calculated during each update(Coord) call; it does not need
to be called before updateAll()
(with no arguments) because that doesn't need a viewer. Sets
fovResult
, losResult
, and noticeable
based on the given viewer position and any lights
in lights
.viewer
- the position of the player or other viewerfovResult
public double[][] calculateFOV(int viewerX, int viewerY)
update()
gets called to change lighting at the new cell. This sets
important information on what lights might need to be calculated during each update(Coord) call; it does not need
to be called before updateAll()
(with no arguments) because that doesn't need a viewer. Sets
fovResult
, losResult
, and noticeable
based on the given viewer position and any lights
in lights
.viewerX
- the x-position of the player or other viewerviewerY
- the y-position of the player or other viewerfovResult
public double[][] calculateFOV(int viewerX, int viewerY, int minX, int minY, int maxX, int maxY)
update()
gets called to change lighting at the new cell. This sets
important information on what lights might need to be calculated during each update(Coord) call; it does not need
to be called before updateAll()
(with no arguments) because that doesn't need a viewer. This overload
allows the area this processes to be restricted to a rectangle between minX
and maxX
and between
minY
and maxY
, ignoring any lights outside that area (typically because they are a long way out
from the map's shown area). Sets fovResult
, losResult
, and noticeable
based on the
given viewer position and any lights in lights
.viewerX
- the x-position of the player or other viewerviewerY
- the y-position of the player or other viewerminX
- inclusive lower bound on x to calculateminY
- inclusive lower bound on y to calculatemaxX
- exclusive upper bound on x to calculatemaxY
- exclusive upper bound on y to calculatefovResult
Copyright © Eben Howard 2012–2022. All rights reserved.