|
ASW Lib
A.D.S. Games SDL Wrapper Library. A library targeted at Allegro4 users who want to switch to SDL3 and use modern c++.
|
Light that spreads across a grid of tiles and stops at solid tiles. More...
#include <lighting.h>
Classes | |
| struct | Source |
Public Member Functions | |
| TileLight (int width, int height, float tile_size) | |
| Create a grid with no solid tiles and no lights. | |
| void | set_solid (int x, int y, bool solid) |
| Set whether a tile blocks light. A solid tile is lit, but does not pass light on. | |
| bool | is_solid (int x, int y) const |
| Get whether a tile blocks light. Tiles off the grid are solid. | |
| void | set_falloff (float amount) |
| Set how much light is lost per tile, from 0 to 1. | |
| void | clear_lights () |
| Remove all lights. | |
| void | add_light (int x, int y, const asw::Color &color) |
| Add a light at a tile. | |
| void | compute () |
| Spread the lights and update the texture. Call after lights or solid tiles change. | |
| asw::Color | get (int x, int y) const |
| Get the light at a tile after compute(). | |
| const asw::Texture & | get_texture () const |
| Get the texture, with one pixel per tile. Empty before compute(). | |
| asw::Vec2< float > | get_size () const |
| Get the size of the grid in pixels. | |
Private Member Functions | |
| bool | in_grid (int x, int y) const |
| void | upload () |
Private Attributes | |
| int | width |
| int | height |
| float | tile_size |
| float | falloff { 0.1F } |
| std::vector< uint8_t > | solid |
| std::vector< Source > | sources |
| std::vector< float > | light |
| asw::Texture | texture |
| std::vector< float > | level |
| std::vector< std::size_t > | open |
| std::vector< uint8_t > | pixels |
Light that spreads across a grid of tiles and stops at solid tiles.
Lighting is worked out on the CPU in compute(), then kept in a texture with one pixel per tile. The texture is drawn with smooth scaling, so light blends between tiles. Add it to a LightMap with add_tiles().
Definition at line 121 of file lighting.h.
| asw::lighting::TileLight::TileLight | ( | int | width, |
| int | height, | ||
| float | tile_size ) |
Create a grid with no solid tiles and no lights.
| width | Width in tiles. |
| height | Height in tiles. |
| tile_size | Size of a tile in pixels. |
Definition at line 169 of file lighting.cpp.
| void asw::lighting::TileLight::add_light | ( | int | x, |
| int | y, | ||
| const asw::Color & | color ) |
Add a light at a tile.
| x | Tile x. |
| y | Tile y. |
| color | Colour at the tile. It fades as it spreads. |
Definition at line 206 of file lighting.cpp.
| void asw::lighting::TileLight::clear_lights | ( | ) |
Remove all lights.
Definition at line 201 of file lighting.cpp.
| void asw::lighting::TileLight::compute | ( | ) |
Spread the lights and update the texture. Call after lights or solid tiles change.
Definition at line 213 of file lighting.cpp.
| asw::Color asw::lighting::TileLight::get | ( | int | x, |
| int | y ) const |
Get the light at a tile after compute().
Definition at line 318 of file lighting.cpp.
| asw::Vec2< float > asw::lighting::TileLight::get_size | ( | ) | const |
Get the size of the grid in pixels.
Definition at line 333 of file lighting.cpp.
| const asw::Texture & asw::lighting::TileLight::get_texture | ( | ) | const |
Get the texture, with one pixel per tile. Empty before compute().
Definition at line 328 of file lighting.cpp.
|
private |
Definition at line 179 of file lighting.cpp.
| bool asw::lighting::TileLight::is_solid | ( | int | x, |
| int | y ) const |
Get whether a tile blocks light. Tiles off the grid are solid.
Definition at line 191 of file lighting.cpp.
| void asw::lighting::TileLight::set_falloff | ( | float | amount | ) |
Set how much light is lost per tile, from 0 to 1.
Definition at line 196 of file lighting.cpp.
| void asw::lighting::TileLight::set_solid | ( | int | x, |
| int | y, | ||
| bool | solid ) |
Set whether a tile blocks light. A solid tile is lit, but does not pass light on.
Definition at line 184 of file lighting.cpp.
|
private |
Definition at line 284 of file lighting.cpp.
|
private |
Definition at line 186 of file lighting.h.
|
private |
Definition at line 184 of file lighting.h.
|
private |
Definition at line 193 of file lighting.h.
|
private |
Definition at line 189 of file lighting.h.
|
private |
Definition at line 194 of file lighting.h.
|
private |
Definition at line 195 of file lighting.h.
|
private |
Definition at line 187 of file lighting.h.
|
private |
Definition at line 188 of file lighting.h.
|
private |
Definition at line 190 of file lighting.h.
|
private |
Definition at line 185 of file lighting.h.
|
private |
Definition at line 183 of file lighting.h.