Class LightingManagerRgb
java.lang.Object
com.github.yellowstonegames.grid.LightingManager
com.github.yellowstonegames.grid.LightingManagerRgb
- All Implemented Interfaces:
com.github.yellowstonegames.core.ISerializersNeeded
public class LightingManagerRgb
extends LightingManager
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 normal RGBA color space, like
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, either using LightingManager.addLight(int, int, Radiance) or
by directly putting keys and values into LightingManager.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 LightingManager.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 LightingManager.update() or
LightingManager.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
LightingManager.updateUI(Coord, Radiance), which is called after LightingManager.update() but before draw(int[][]).
This class uses the normal RGBA color space, like
DescriptiveColorRgb, for almost every place it deals with
color. The exception here is drawOklab(int[][]), which uses RGBA internally but converts the colors to OKlab
when it outputs them.
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 classes/interfaces inherited from class LightingManager
LightingManager.FovFunction, LightingManager.SymmetryMode -
Field Summary
Fields inherited from class LightingManager
backgroundColor, colorLighting, fovLightColors, fovResult, height, lightFromFOV, lightingStrength, lights, losResult, noticeable, radiusStrategy, resistances, symmetry, viewerRange, width -
Constructor Summary
ConstructorsConstructorDescriptionUnlikely to be used except during serialization; makes a LightingManager for a 20x20 fully visible level.LightingManagerRgb(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.LightingManagerRgb(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.LightingManagerRgb(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.LightingManagerRgb(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 TypeMethodDescriptionvoiddraw(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.intAn extension point for subclasses that don't use the Oklab color space; this subclass returnsDescriptiveColorRgb.WHITE.voidmixColoredLighting(float flare) EditsLightingManager.colorLightingby adding in and mixing the colors inLightingManager.fovLightColors, 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) EditsLightingManager.colorLightingby adding in and mixing the given color where the light strength inLightingManager.lightFromFOVis 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).toString()Methods inherited from class LightingManager
addLight, addLight, addLight, addLight, calculateFOV, calculateFOV, calculateFOV, calculateFOV, equals, generateDefaultFloatArray, get, get, get, get, get, getSymmetry, hashCode, lightCount, lightsAt, lightsAt, moveLight, moveLight, moveLight, moveLight, removeLight, removeLight, removeLight, removeLight, setSymmetry, update, updateAll, updateUI, updateUI
-
Constructor Details
-
LightingManagerRgb
public LightingManagerRgb()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. -
LightingManagerRgb
public LightingManagerRgb(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
-
LightingManagerRgb
public LightingManagerRgb(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
-
LightingManagerRgb
public LightingManagerRgb(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 an RGBA8888 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
-
LightingManagerRgb
public LightingManagerRgb(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 an RGBA8888 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
-
getNeutralColor
public int getNeutralColor()An extension point for subclasses that don't use the Oklab color space; this subclass returnsDescriptiveColorRgb.WHITE. There is no setter or field for the neutral color.- Overrides:
getNeutralColorin classLightingManager- Returns:
- in this subclass,
DescriptiveColorRgb.WHITE
-
mixColoredLighting
public void mixColoredLighting(float flare) EditsLightingManager.colorLightingby adding in and mixing the colors inLightingManager.fovLightColors, 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 byLightingManager.lightFromFOVand the colors of lights are determined byLightingManager.fovLightColors. 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 ofLightingManager.update(), but this method is meant for when multiple colors of FOV light need to be mixed at once.- Overrides:
mixColoredLightingin classLightingManager- Parameters:
flare- boosts the effective strength of lighting inLightingManager.fovLightColors; usually from 0 to 1
-
mixColoredLighting
public void mixColoredLighting(float flare, int color) EditsLightingManager.colorLightingby adding in and mixing the given color where the light strength inLightingManager.lightFromFOVis 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 fromLightingManager.lightingStrengthand its existing light colors fromLightingManager.colorLighting; it modifies both of these.
This has limited use outside this class, unless you are reimplementing part ofLightingManager.update()or something like it.- Overrides:
mixColoredLightingin classLightingManager- Parameters:
flare- boosts the effective strength of lighting inLightingManager.lightFromFOV; usually from 0 to 1color- the RGBA8888 int color to mix in where the light strength inLightingManager.lightFromFOVis greater than 0
-
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 callLightingManager.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). A common use for this in text-based games uses a GlyphMap's backgrounds field as the parameter. This always mixes the calculated lights inLightingManager.colorLightingwith theLightingManager.backgroundColor, usingLightingManager.lightingStrengthto determine how much the lights should affect the background color.
If this class is extended, this method should be considered as one to override.- Overrides:
drawin classLightingManager- 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 callLightingManager.update()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 inLightingManager.colorLightingwith theLightingManager.backgroundColor, usingLightingManager.lightingStrengthto determine how much the lights should affect the background color.
If this class is extended, this method should be considered as one to override.- Overrides:
drawOklabin classLightingManager- Parameters:
backgrounds- a 2D int array, which will be modified in-place; visible cells will receive Oklab colors
-
toString
- Overrides:
toStringin classLightingManager
-
getSerializersNeeded
- Specified by:
getSerializersNeededin interfacecom.github.yellowstonegames.core.ISerializersNeeded- Overrides:
getSerializersNeededin classLightingManager
-