Class LightingManager
java.lang.Object
com.github.yellowstonegames.grid.LightingManager
- All Implemented Interfaces:
com.github.yellowstonegames.core.ISerializersNeeded
- Direct Known Subclasses:
LightingManagerRgb
public class LightingManager
extends Object
implements com.github.yellowstonegames.core.ISerializersNeeded
A convenience class that makes dealing with multiple colored light sources easier.
All fields are public and documented to encourage their use alongside the API methods. The typical usage case for
this class is when a game has complex lighting needs that should be consolidated into one LightingManager per level,
where a level corresponds to a
This class uses the same Oklab color space that
Honestly, this class is quite complex, and you should really take a look at a demo that uses it to see how the different parts fit together. If you have the SquidSquad test sources, LightingTest in squidglyph provides a relatively simple example using many colors of light.
char[][]. After constructing a LightingManager with the resistances for a
level, you should add all light sources with their positions, such as by using addLight(int, int, Radiance)
to create a LightSource with a specific Radiance at a position, 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 light sources, 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(int[][]) to change a 2D int array that holds packed int colors (such as the backgrounds in a
GlyphMap). To place user-interface lighting effects that don't affect the in-game-world lights, you can use
updateUI(Coord, Radiance), which is called after update() but before draw(int[][]).
This class uses the same Oklab color space that
DescriptiveColor uses for almost every place it deals with
color. The exception here is draw(int[][]), which uses Oklab internally but converts the colors to RGBA8888
when it outputs them. You can use the alternative class LightingManagerRgb if you want to use RGBA colors
throughout the lighting code.
Honestly, this class is quite complex, and you should really take a look at a demo that uses it to see how the different parts fit together. If you have the SquidSquad test sources, LightingTest in squidglyph provides a relatively simple example using many colors of light.
VisionFramework also can be used to handle much of the
boilerplate associated with vision and lighting.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static interfaceA functional interface that is really only meant to be one of two functions:FOV.reuseFOV(float[][], float[][], int, int, float, Radius)orFOV.reuseFOVSymmetrical(float[][], float[][], int, int, float, Radius).static enumUsed to choose whether FOV calculations should be done as quickly as possible (without symmetry guarantees) or more precisely (and more slowly, but with a symmetry guarantee). -
Field Summary
FieldsModifier and TypeFieldDescriptionintThe packed Oklab int 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.int[][]A 2D array that stores the color of light in each cell, as a packed Oklab int color.int[][]Represents the Oklab int colors associated with lights inlightFromFOV.float[][]What the "viewer" (as passed tocalculateFOV(Coord)) can see either nearby without light or because an area in line-of-sight has light in it.intHeight of the 2D arrays used in this, as obtained fromresistances.float[][]Used for calculations involvingfovResult, generally with each colored light individually updating this 2D array and then having this array wiped clean.float[][]Used to determine the lighting power, but not colors, of all lights in the scene.com.github.tommyettinger.ds.ObjectDeque<LightSource> float[][]A 2D array of floats that are either 0.0f if a cell has an obstruction between it and the viewer, or greater than 0.0f otherwise.A Region 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.How light should spread; usuallyRadius.CIRCLEunless gameplay reasons need it to be SQUARE or DIAMOND.float[][]The 2D array of light-resistance values from 0.0f to 1.0f for each cell on the map, as produced byFOV.generateResistances(char[][])orFOV.generateSimpleResistances(char[][]).floatHow far the viewer can see without light; defaults to 4.0f cells, and you are encouraged to change this member field if the vision range changes after construction.intWidth of the 2D arrays used in this, as obtained fromresistances. -
Constructor Summary
ConstructorsConstructorDescriptionUnlikely to be used except during serialization; makes a LightingManager for a 20x20 fully visible level.LightingManager(float[][] resistance) Given a resistance array as produced byFOV.generateResistances(char[][])orFOV.generateSimpleResistances(char[][]), makes a LightingManager that can haveRadianceobjects added to it in various locations.LightingManager(float[][] resistance, int backgroundColor, Radius radiusStrategy, float viewerVisionRange) Given a resistance array as produced byFOV.generateResistances(char[][])orFOV.generateSimpleResistances(char[][]), makes a LightingManager that can haveRadianceobjects added to it in various locations.LightingManager(float[][] resistance, int backgroundColor, Radius radiusStrategy, float viewerVisionRange, LightingManager.SymmetryMode symmetry) Given a resistance array as produced byFOV.generateResistances(char[][])orFOV.generateSimpleResistances(char[][]), makes a LightingManager that can haveRadianceobjects added to it in various locations.LightingManager(float[][] resistance, String backgroundColor, Radius radiusStrategy, float viewerVisionRange) Given a resistance array as produced byFOV.generateResistances(char[][])orFOV.generateSimpleResistances(char[][]), makes a LightingManager that can haveRadianceobjects added to it in various locations. -
Method Summary
Modifier and TypeMethodDescriptionAdds a Radiance as a LightSource at the given position.Adds a Radiance as a LightSource at the given position.Adds a LightSource using the given Radiance at the given position.addLight(LightSource light) Adds a LightSource to the collection this has for lights.float[][]calculateFOV(int viewerX, int viewerY) Used to calculate what cells are visible as if any flicker or strobe effects were simply constant light sources.float[][]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.float[][]calculateFOV(com.github.tommyettinger.ds.ObjectFloatMap<Coord> viewers, 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.float[][]calculateFOV(Coord viewer) Used to calculate what cells are visible as if any flicker or strobe effects were simply constant light sources.voiddraw(int[][] backgrounds) Given a 2D array that should hold RGBA int colors, fills the 2D array with different RGBA 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.voiddrawOklab(int[][] backgrounds) Given a 2D array that will hold Oklab int colors, fills the 2D array with different Oklab 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.booleanprotected static float[][]get(int index) Gets the nth LightSource at any position, where n isindex.get(int x, int y) Gets the first LightSource at the given position, if present, or null if there is no LightSource there.get(int x, int y, int index) Gets the nth LightSource at the given position, where n isindex, or null if there is no LightSource there.Gets the first LightSource at the given position, if present, or null if there is no LightSource there.Gets the nth LightSource at the given position, where n isindex, or null if there is no LightSource there.intAn extension point for subclasses that don't use the Oklab color space; this defaults to returningDescriptiveColor.WHITE.inthashCode()intlightCount(Coord position) Returns how many LightSources are at the givenposition.com.github.tommyettinger.ds.ObjectList<LightSource> Finds all LightSources this has with the givenpositionand adds them to a newly-allocated ObjectList, which this returns.lightsAt(Collection<LightSource> buffer, Coord position) Finds all LightSources this has with the givenpositionand appends them tobuffer.voidmixColoredLighting(float flare) EditscolorLightingby adding in and mixing the colors infovLightColors, with the strength of light in fovLightColors boosted by flare (which can be any finite float greater than -1f, but is usually from 0f to 1f when increasing strength).voidmixColoredLighting(float flare, int color) EditscolorLightingby adding in and mixing the given color where the light strength inlightFromFOVis 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).booleanmoveLight(int oldX, int oldY, int newX, int newY) If at least one LightSource is present at oldX,oldY, this will move the first LightSource to newX,newY.booleanmoveLight(int oldX, int oldY, int newX, int newY, int index) If at least one LightSource is present at oldX,oldY, this will move the nth LightSource at oldX,oldY, where n isindex, to newX,newY.booleanIf at least one LightSource is present at oldPosition, this will move the first LightSource to newPosition.booleanIf at least one LightSource is present at oldPosition, this will move the nth LightSource at oldPosition, where n isindex, to newPosition.booleanremoveLight(int x, int y) Removes the first encountered LightSource with the given position, if any is present.booleanremoveLight(int x, int y, int index) Removes the nth encountered LightSource with the given position, where n isindex, if any is present.booleanremoveLight(Coord position) Removes the first encountered LightSource with the given position, if any is present.booleanremoveLight(Coord position, int index) Removes the nth encountered LightSource with the given position, where n isindex, if any is present.voidsetSymmetry(LightingManager.SymmetryMode symmetry) toString()voidupdate()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 LightingManager.voidTypically 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 LightingManager.voidUpdates the flicker and strobe effects of a Radiance object and applies the lighting from just that Radiance to just thecolorLightingfield, without changing FOV.voidUpdates the flicker and strobe effects of a Radiance object and applies the lighting from just that Radiance to just thecolorLightingfield, without changing FOV.
-
Field Details
-
radiusStrategy
How light should spread; usuallyRadius.CIRCLEunless gameplay reasons need it to be SQUARE or DIAMOND. -
resistances
public float[][] resistancesThe 2D array of light-resistance values from 0.0f to 1.0f for each cell on the map, as produced byFOV.generateResistances(char[][])orFOV.generateSimpleResistances(char[][]). -
fovResult
public float[][] fovResultWhat the "viewer" (as passed tocalculateFOV(Coord)) can see either nearby without light or because an area in line-of-sight has light in it. Edited bycalculateFOV(Coord)andupdate(), but notupdateUI(Coord, Radiance)(which is meant for effects that are purely user-interface). -
losResult
public float[][] losResultA 2D array of floats that are either 0.0f if a cell has an obstruction between it and the viewer, or greater than 0.0f otherwise. -
lightFromFOV
public float[][] lightFromFOVUsed for calculations involvingfovResult, generally with each colored light individually updating this 2D array and then having this array wiped clean. This serves as an intermediate storage step between the update methods andmixColoredLighting(float, int); the latter depends on this to be set by an update method or bycalculateFOV(Coord). -
lightingStrength
public float[][] lightingStrengthUsed to determine the lighting power, but not colors, of all lights in the scene. This is set in the update methods and used inmixColoredLighting(float)anddraw(int[][]). -
colorLighting
public int[][] colorLightingA 2D array that stores the color of light in each cell, as a packed Oklab int color. This 2D array is the size of the map, as defined byresistancesinitially and later available inwidthandheight. -
fovLightColors
public int[][] fovLightColorsRepresents the Oklab int colors associated with lights inlightFromFOV. To make effective use of this field, you will probably need to be reading the source for LightingManager. -
width
public int widthWidth of the 2D arrays used in this, as obtained fromresistances. -
height
public int heightHeight of the 2D arrays used in this, as obtained fromresistances. -
backgroundColor
public int backgroundColorThe packed Oklab int 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 defaults to the (RGBA or Oklab int)0, which is always transparent. -
viewerRange
public float viewerRangeHow far the viewer can see without light; defaults to 4.0f cells, and you are encouraged to change this member field if the vision range changes after construction. -
lights
A mapping from positions asCoordobjects toRadianceobjects 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 usingmoveLight(int, int, int, int),addLight(int, int, Radiance), andremoveLight(int, int). -
noticeable
A Region 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. Depends on the highestRadiance.rangeinlights. -
symmetry
-
-
Constructor Details
-
LightingManager
public LightingManager()Unlikely to be used except during serialization; makes a LightingManager for a 20x20 fully visible level. The viewer vision range will be 4.0f, and lights will use a circular shape. -
LightingManager
public LightingManager(float[][] resistance) Given a resistance array as produced byFOV.generateResistances(char[][])orFOV.generateSimpleResistances(char[][]), makes a LightingManager that can haveRadianceobjects 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.0f, and lights will use a circular shape.- Parameters:
resistance- a resistance array as produced by DungeonUtility
-
LightingManager
public LightingManager(float[][] resistance, String backgroundColor, Radius radiusStrategy, float viewerVisionRange) Given a resistance array as produced byFOV.generateResistances(char[][])orFOV.generateSimpleResistances(char[][]), makes a LightingManager that can haveRadianceobjects added to it in various locations.- Parameters:
resistance- a resistance array as produced by DungeonUtilitybackgroundColor- the background color to use, as a color descriptionradiusStrategy- the shape lights should take, typicallyRadius.CIRCLEfor "realistic" lights or one ofRadius.DIAMONDorRadius.SQUAREto match game rules for distanceviewerVisionRange- how far the player can see without light, in cells
-
LightingManager
public LightingManager(float[][] resistance, int backgroundColor, Radius radiusStrategy, float viewerVisionRange) Given a resistance array as produced byFOV.generateResistances(char[][])orFOV.generateSimpleResistances(char[][]), makes a LightingManager that can haveRadianceobjects added to it in various locations.- Parameters:
resistance- a resistance array as produced by DungeonUtilitybackgroundColor- the background color to use, as a packed Oklab intradiusStrategy- the shape lights should take, typicallyRadius.CIRCLEfor "realistic" lights or one ofRadius.DIAMONDorRadius.SQUAREto match game rules for distanceviewerVisionRange- how far the player can see without light, in cells
-
LightingManager
public LightingManager(float[][] resistance, int backgroundColor, Radius radiusStrategy, float viewerVisionRange, LightingManager.SymmetryMode symmetry) Given a resistance array as produced byFOV.generateResistances(char[][])orFOV.generateSimpleResistances(char[][]), makes a LightingManager that can haveRadianceobjects added to it in various locations.- Parameters:
resistance- a resistance array as produced by DungeonUtilitybackgroundColor- the background color to use, as a packed Oklab intradiusStrategy- the shape lights should take, typicallyRadius.CIRCLEfor "realistic" lights or one ofRadius.DIAMONDorRadius.SQUAREto match game rules for distanceviewerVisionRange- how far the player can see without light, in cells
-
-
Method Details
-
generateDefaultFloatArray
protected static float[][] generateDefaultFloatArray() -
getSymmetry
-
setSymmetry
-
getNeutralColor
public int getNeutralColor()An extension point for subclasses that don't use the Oklab color space; this defaults to returningDescriptiveColor.WHITE. There is no setter or field for the neutral color.- Returns:
- if not overridden,
DescriptiveColor.WHITE
-
lightCount
Returns how many LightSources are at the givenposition.- Parameters:
position- the position to count at- Returns:
- a non-negative int, at least 0 and less than
lights.size
-
addLight
Adds a Radiance as a LightSource at the given position. The LightSource will spread light in all directions.- Parameters:
x- the x-position to add the LightSource aty- the y-position to add the LightSource atlight- a Radiance object that can have a changing radius, color, and various other effects on lighting- Returns:
- this for chaining
-
addLight
Adds a Radiance as a LightSource at the given position. The LightSource will spread light in all directions.- Parameters:
position- the position to add the LightSource atlight- a Radiance object that can have a changing radius, color, and various other effects on lighting- Returns:
- this for chaining
-
addLight
Adds a LightSource using the given Radiance at the given position. This also restricts the lit span tospanTurns(between 0 and 1) and sets the initial direction of the light toangleTurns(also between 0 and 1).- Parameters:
position- the position to add the Radiance atlight- a Radiance object that can have a changing radius, color, and various other effects on lightingspanTurns- how wide of an arc the LightSource will cover, measured in turnsangleTurns- what direction the LightSource will point towards, measured in turns- Returns:
- this for chaining
-
addLight
Adds a LightSource to the collection this has for lights. This is largely irrelevant, since you can just callObjectDeque.add(Object)onlights.- Parameters:
light- an existing LightSource, with a position and Radiance, to add- Returns:
- this for chaining
-
removeLight
public boolean removeLight(int x, int y) Removes the first encountered LightSource with the given position, if any is present.- Parameters:
x- the x-position to remove the LightSource fromy- the y-position to remove the LightSource from- Returns:
- true if any light was removed, false otherwise
-
removeLight
public boolean removeLight(int x, int y, int index) Removes the nth encountered LightSource with the given position, where n isindex, if any is present.- Parameters:
x- the x-position to remove the LightSource fromy- the y-position to remove the LightSource fromindex- which of the possible lights at x,y to remove- Returns:
- true if any light was removed, false otherwise
-
removeLight
Removes the first encountered LightSource with the given position, if any is present.- Parameters:
position- the position to remove the LightSource from- Returns:
- true if any light was removed, false otherwise
-
removeLight
Removes the nth encountered LightSource with the given position, where n isindex, if any is present.- Parameters:
position- the position to remove the LightSource fromindex- which of the possible lights at position to remove- Returns:
- true if any light was removed, false otherwise
-
moveLight
public boolean moveLight(int oldX, int oldY, int newX, int newY) If at least one LightSource is present at oldX,oldY, this will move the first LightSource to newX,newY. If no LightSource is present at oldX,oldY, this does nothing. This will not remove any LightSource already present at newX,newY.- Parameters:
oldX- the x-position to move a LightSource fromoldY- the y-position to move a LightSource fromnewX- the x-position to move a LightSource tonewY- the y-position to move a LightSource to- Returns:
- true if any light was moved, or false otherwise
-
moveLight
public boolean moveLight(int oldX, int oldY, int newX, int newY, int index) If at least one LightSource is present at oldX,oldY, this will move the nth LightSource at oldX,oldY, where n isindex, to newX,newY. If no LightSource is present at oldX,oldY, this does nothing. This also does nothing if index is greater than or equal to the number of lights at oldX,oldY. This will not remove any LightSource already present at newX,newY.- Parameters:
oldX- the x-position to move a LightSource fromoldY- the y-position to move a LightSource fromnewX- the x-position to move a LightSource tonewY- the y-position to move a LightSource toindex- which of the possible lights at oldPosition to move- Returns:
- true if any light was moved, or false otherwise
-
moveLight
If at least one LightSource is present at oldPosition, this will move the first LightSource to newPosition. If no LightSource is present at oldPosition, this does nothing. This will not remove any LightSource already present at newPosition.- Parameters:
oldPosition- the Coord to move a LightSource fromnewPosition- the Coord to move a LightSource to- Returns:
- true if any light was moved, or false otherwise
-
moveLight
If at least one LightSource is present at oldPosition, this will move the nth LightSource at oldPosition, where n isindex, to newPosition. If no LightSource is present at oldPosition, this does nothing. This also does nothing if index is greater than or equal to the number of lights at oldPosition. This will not remove any LightSource already present at newPosition.- Parameters:
oldPosition- the Coord to move a LightSource fromnewPosition- the Coord to move a LightSource toindex- which of the possible lights at oldPosition to move- Returns:
- true if any light was moved, or false otherwise
-
get
Gets the nth LightSource at any position, where n isindex. This is largely unnecessary because you can callObjectDeque.get(int)onlights. The only difference here is that this method returns null ifindexis out-of-bounds, while ObjectQueue.get(int) throws an Exception then.- Parameters:
index- which LightSource index to get- Returns:
- the LightSource with the given index across all positions, or null if index if out of bounds.
-
get
Gets the first LightSource at the given position, if present, or null if there is no LightSource there.- Parameters:
x- the x-position to look upy- the y-position to look up- Returns:
- the first LightSource at the given position, or null if none is present there
-
get
Gets the nth LightSource at the given position, where n isindex, or null if there is no LightSource there.- Parameters:
x- the x-position to look upy- the y-position to look upindex- which LightSource to get from the given position- Returns:
- the nth LightSource at the given position, or null if none is present there
-
get
Gets the first LightSource at the given position, if present, or null if there is no LightSource there.- Parameters:
position- the position to look up- Returns:
- the first LightSource at the given position, or null if none is present there
-
get
Gets the nth LightSource at the given position, where n isindex, or null if there is no LightSource there.- Parameters:
position- the position to look upindex- which LightSource to get from the given position- Returns:
- the nth LightSource at the given position, or null if none is present there
-
lightsAt
Finds all LightSources this has with the givenpositionand adds them to a newly-allocated ObjectList, which this returns.- Parameters:
position- the position to look up LightSources at- Returns:
- a newly-allocated ObjectList that may have LightSource items which were found at position
-
lightsAt
Finds all LightSources this has with the givenpositionand appends them tobuffer.- Parameters:
buffer- any modifiable Collection of LightSource items; may be modifiedposition- the position to look up LightSources at- Returns:
- buffer, potentially after modification
-
mixColoredLighting
public void mixColoredLighting(float flare) EditscolorLightingby adding in and mixing the colors infovLightColors, with the strength of light in fovLightColors boosted by flare (which can be any finite float greater than -1f, but is usually from 0f to 1f when increasing strength). The strengths of each colored light is determined bylightFromFOVand the colors of lights are determined byfovLightColors. If a color of light is fully transparent, this skips that light.
This is very limited-use; the related methodmixColoredLighting(float, int)is used as part ofupdate(), but this method is meant for when multiple colors of FOV light need to be mixed at once.- Parameters:
flare- boosts the effective strength of lighting infovLightColors; usually from 0 to 1
-
mixColoredLighting
public void mixColoredLighting(float flare, int color) EditscolorLightingby adding in and mixing the given color where the light strength inlightFromFOVis 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). This draws its existing lighting strength fromlightingStrengthand its existing light colors fromcolorLighting; it modifies both of these.
This has limited use outside this class, unless you are reimplementing part ofupdate()or something like it.- Parameters:
flare- boosts the effective strength of lighting inlightFromFOV; usually from 0 to 1color- the Oklab color to mix in where the light strength inlightFromFOVis greater than 0
-
update
public 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 LightingManager. This will only have an effect ifcalculateFOV(Coord)orcalculateFOV(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 todraw(int[][]), but other code may be between the calls and may affect the lighting in customized ways. -
updateAll
public 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 LightingManager. This method is usually called before each call todraw(int[][]), 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 needcalculateFOV(Coord)to be called for it to work properly. -
updateUI
Updates the flicker and strobe effects of a Radiance object and applies the lighting from just that Radiance to just thecolorLightingfield, 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 afterupdate()and before each call todraw(int[][]), but other code may be between the calls and may affect the lighting in customized ways.- Parameters:
pos- the position of the light effectradiance- the Radiance to update standalone, which does not need to be already added to this
-
updateUI
Updates the flicker and strobe effects of a Radiance object and applies the lighting from just that Radiance to just thecolorLightingfield, 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 afterupdate()and before each call todraw(int[][]), but other code may be between the calls and may affect the lighting in customized ways.- Parameters:
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 this
-
draw
public void draw(int[][] backgrounds) Given a 2D array that should hold RGBA int colors, fills the 2D array with different RGBA 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. You should usually callupdate()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). A common use for this in text-based games uses a GlyphMap's backgrounds field as the parameter. This always mixes the calculated lights incolorLightingwith thebackgroundColor, usinglightingStrengthto determine how much the lights should affect the background color.
If this class is extended, this method should be considered as one to override.- Parameters:
backgrounds- a 2D int array, which will be modified in-place; visible cells will receive RGBA8888 colors
-
drawOklab
public void drawOklab(int[][] backgrounds) Given a 2D array that will hold Oklab int colors, fills the 2D array with different Oklab 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. You should usually callupdate()before each call to drawOklab(), 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). A common use for this in text-based games uses a GlyphMap's backgrounds field as the parameter. This always mixes the calculated lights incolorLightingwith thebackgroundColor, usinglightingStrengthto determine how much the lights should affect the background color.
If this class is extended, this method should be considered as one to override.- Parameters:
backgrounds- a 2D int array, which will be modified in-place; visible cells will receive Oklab colors
-
calculateFOV
Used to calculate what cells are visible as if any flicker or strobe effects were simply constant light sources. Runs part of the calculations to draw lighting as if all radii are at their widest, but does no actual drawing. This should be called any time the viewer moves to a different cell, and it is critical that this is called (at least) once after a move but beforeupdate()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 beforeupdateAll()(with no arguments) because that doesn't need a viewer. SetsfovResult,losResult, andnoticeablebased on the given viewer position and any lights inlights.- Parameters:
viewer- the position of the player or other viewer- Returns:
- the calculated FOV 2D array, which is also stored in
fovResult
-
calculateFOV
public float[][] calculateFOV(int viewerX, int viewerY) Used to calculate what cells are visible as if any flicker or strobe effects were simply constant light sources. Runs part of the calculations to draw lighting as if all radii are at their widest, but does no actual drawing. This should be called any time the viewer moves to a different cell, and it is critical that this is called (at least) once after a move but beforeupdate()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 beforeupdateAll()(with no arguments) because that doesn't need a viewer. SetsfovResult,losResult, andnoticeablebased on the given viewer position and any lights inlights.- Parameters:
viewerX- the x-position of the player or other viewerviewerY- the y-position of the player or other viewer- Returns:
- the calculated FOV 2D array, which is also stored in
fovResult
-
calculateFOV
public float[][] 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. Runs part of the calculations to draw lighting as if all radii are at their widest, but does no actual drawing. This should be called any time the viewer moves to a different cell, and it is critical that this is called (at least) once after a move but beforeupdate()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 beforeupdateAll()(with no arguments) because that doesn't need a viewer. This overload allows the area this processes to be restricted to a rectangle betweenminXandmaxXand betweenminYandmaxY, ignoring any lights outside that area (typically because they are a long way out from the map's shown area). SetsfovResult,losResult, andnoticeablebased on the given viewer position and any lights inlights.- Parameters:
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 calculate- Returns:
- the calculated FOV 2D array, which is also stored in
fovResult
-
calculateFOV
public float[][] calculateFOV(com.github.tommyettinger.ds.ObjectFloatMap<Coord> viewers, 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. Runs part of the calculations to draw lighting as if all radii are at their widest, but does no actual drawing. This should be called any time the viewer moves to a different cell, and it is critical that this is called (at least) once after a move but beforeupdate()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 beforeupdateAll()(with no arguments) because that doesn't need a viewer. This overload allows the area this processes to be restricted to a rectangle betweenminXandmaxXand betweenminYandmaxY, ignoring any lights outside that area (typically because they are a long way out from the map's shown area). SetsfovResult,losResult, andnoticeablebased on the given viewer position and any lights inlights.- Parameters:
viewers- an ObjectFloatMap with Coord keys representing viewer positions and float values for their vision ranges; often aCoordFloatOrderedMapminX- 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 calculate- Returns:
- the calculated FOV 2D array, which is also stored in
fovResult
-
equals
-
hashCode
-
toString
-
getSerializersNeeded
-