Classes | |
struct | ChangingLight |
Contains information about a node whose light is about to change. More... | |
struct | LightQueue |
struct | SunlightPropagationData |
struct | SunlightPropagationUnit |
struct | VoxelLineIterator |
Typedefs | |
typedef u8 | direction |
typedef v3s16 | relative_v3 |
typedef v3s16 | mapblock_v3 |
typedef LightQueue | UnlightQueue |
typedef LightQueue | ReLightQueue |
Functions | |
bool | step_rel_block_pos (direction dir, relative_v3 &rel_pos, mapblock_v3 &block_pos) |
void | unspread_light (Map *map, const NodeDefManager *nodemgr, LightBank bank, UnlightQueue &from_nodes, ReLightQueue &light_sources, std::map< v3s16, MapBlock * > &modified_blocks) |
void | spread_light (Map *map, const NodeDefManager *nodemgr, LightBank bank, LightQueue &light_sources, std::map< v3s16, MapBlock * > &modified_blocks) |
bool | is_sunlight_above (Map *map, v3s16 pos, const NodeDefManager *ndef) |
void | update_lighting_nodes (Map *map, const std::vector< std::pair< v3s16, MapNode > > &oldnodes, std::map< v3s16, MapBlock * > &modified_blocks) |
bool | is_light_locally_correct (Map *map, const NodeDefManager *ndef, LightBank bank, v3s16 pos) |
void | update_block_border_lighting (Map *map, MapBlock *block, std::map< v3s16, MapBlock * > &modified_blocks) |
void | fill_with_sunlight (MMVManip *vm, const NodeDefManager *ndef, v2s16 offset, bool light[MAP_BLOCKSIZE][MAP_BLOCKSIZE]) |
void | is_sunlight_above_block (Map *map, mapblock_v3 pos, const NodeDefManager *ndef, bool light[MAP_BLOCKSIZE][MAP_BLOCKSIZE]) |
bool | propagate_block_sunlight (Map *map, const NodeDefManager *ndef, SunlightPropagationData *data, UnlightQueue *unlight, ReLightQueue *relight) |
void | finish_bulk_light_update (Map *map, mapblock_v3 minblock, mapblock_v3 maxblock, UnlightQueue unlight[2], ReLightQueue relight[2], std::map< v3s16, MapBlock * > *modified_blocks) |
void | blit_back_with_light (Map *map, MMVManip *vm, std::map< v3s16, MapBlock * > *modified_blocks) |
void | fill_with_sunlight (MapBlock *block, const NodeDefManager *ndef, bool light[MAP_BLOCKSIZE][MAP_BLOCKSIZE]) |
void | repair_block_light (Map *map, MapBlock *block, std::map< v3s16, MapBlock * > *modified_blocks) |
Variables | |
static const v3s16 | neighbor_dirs [6] |
static constexpr LightBank | banks [] = { LIGHTBANK_DAY, LIGHTBANK_NIGHT } |
static const VoxelArea | block_borders [] |
const VoxelArea | block_pad [] |
typedef u8 voxalgo::direction |
A direction. 0=X+ 1=Y+ 2=Z+ 3=Z- 4=Y- 5=X- 6=no direction Two directions are opposite only if their sum is 5.
typedef v3s16 voxalgo::mapblock_v3 |
Position of a map block (block coordinates). One block_pos unit is as long as 16 node position units.
typedef v3s16 voxalgo::relative_v3 |
Relative node position. This represents a node's position in its map block. All coordinates must be between 0 and 15.
typedef LightQueue voxalgo::ReLightQueue |
This type of light queue is for spreading lights. While spreading lights, all the nodes in it must have the same light as the light level the ChangingLights were pushed into this queue with. This prevents unnecessary re-pushing of the nodes into the queue. If a node doesn't let light trough but emits light, it can be added too.
typedef LightQueue voxalgo::UnlightQueue |
This type of light queue is for unlighting. A node can be pushed in it only if its raw light is zero. This prevents pushing nodes twice into this queue. The light of the pushed ChangingLight must be the light of the node before unlighting it.
void voxalgo::blit_back_with_light | ( | Map * | map, |
MMVManip * | vm, | ||
std::map< v3s16, MapBlock * > * | modified_blocks ) |
Copies back nodes from a voxel manipulator to the map and updates lighting. For server use only.
modified_blocks | output, contains all map blocks that the function modified |
References banks, MMVManip::blitBackAll(), block_pad, voxalgo::SunlightPropagationData::data, fill_with_sunlight(), finish_bulk_light_update(), Map::getBlockNoCreateNoEx(), MapNode::getLight(), NodeDefManager::getLightingFlags(), getNodeBlockPos(), Map::getNodeDefManager(), MapBlock::getNodeNoCheck(), VoxelManipulator::getNodeNoExNoEmerge(), MapBlock::getPosRelative(), ContentLightingFlags::has_light, VoxelArea::hasEmptyExtent(), is_sunlight_above_block(), ContentLightingFlags::light_source, LIGHT_SUN, VoxelManipulator::m_area, MAP_BLOCKSIZE, VoxelArea::MaxEdge, VoxelArea::MinEdge, propagate_block_sunlight(), voxalgo::LightQueue::push(), and voxalgo::SunlightPropagationData::target_block.
Referenced by LuaVoxelManip::l_write_to_map(), Schematic::placeOnMap(), treegen::spawn_ltree(), TEST_CASE(), and TestVoxelAlgorithms::testLighting().
void voxalgo::fill_with_sunlight | ( | MapBlock * | block, |
const NodeDefManager * | ndef, | ||
bool | light[MAP_BLOCKSIZE][MAP_BLOCKSIZE] ) |
Resets the lighting of the given map block to complete darkness and full sunlight.
light | incoming sunlight, light[x][z] is true if there is sunlight above the map block at the given x-z coordinates. The array's indices are relative node coordinates in the block. After the procedure returns, this contains outgoing light at the bottom of the map block. |
References CONTENT_IGNORE, MapNode::getContent(), NodeDefManager::getLightingFlags(), MapBlock::getNodeNoCheck(), LIGHTBANK_DAY, LIGHTBANK_NIGHT, MAP_BLOCKSIZE, MapNode::setLight(), MapBlock::setNodeNoCheck(), and ContentLightingFlags::sunlight_propagates.
void voxalgo::fill_with_sunlight | ( | MMVManip * | vm, |
const NodeDefManager * | ndef, | ||
v2s16 | offset, | ||
bool | light[MAP_BLOCKSIZE][MAP_BLOCKSIZE] ) |
Resets the lighting of the given VoxelManipulator to complete darkness and full sunlight. Operates in one map sector.
offset | contains the least x and z node coordinates of the map sector. |
light | incoming sunlight, light[x][z] is true if there is sunlight above the voxel manipulator at the given x-z coordinates. The array's indices are relative node coordinates in the sector. After the procedure returns, this contains outgoing light at the bottom of the voxel manipulator. |
References CONTENT_IGNORE, MapNode::getContent(), VoxelArea::getExtent(), NodeDefManager::getLightingFlags(), VoxelArea::index(), LIGHTBANK_DAY, LIGHTBANK_NIGHT, VoxelManipulator::m_area, VoxelManipulator::m_data, VoxelManipulator::m_flags, MAP_BLOCKSIZE, VoxelArea::MaxEdge, VoxelArea::MinEdge, MapNode::setLight(), ContentLightingFlags::sunlight_propagates, and VOXELFLAG_NO_DATA.
Referenced by blit_back_with_light(), and repair_block_light().
void voxalgo::finish_bulk_light_update | ( | Map * | map, |
mapblock_v3 | minblock, | ||
mapblock_v3 | maxblock, | ||
UnlightQueue | unlight[2], | ||
ReLightQueue | relight[2], | ||
std::map< v3s16, MapBlock * > * | modified_blocks ) |
The common part of bulk light updates - it is always executed. The procedure takes the nodes that should be unlit, and the full modified area.
The procedure handles the correction of all lighting except direct sunlight spreading.
minblock | least coordinates of the changed area in block coordinates |
maxblock | greatest coordinates of the changed area in block coordinates |
unlight | the first queue is for day light, the second is for night light. Contains all nodes on the borders that need to be unlit. |
relight | the first queue is for day light, the second is for night light. Contains nodes that were not modified, but got sunlight because the changes. |
modified_blocks | the procedure adds all modified blocks to this map |
References banks, Map::getBlockNoCreateNoEx(), MapNode::getLight(), NodeDefManager::getLightingFlags(), Map::getNodeDefManager(), MapBlock::getNodeNoCheck(), ContentLightingFlags::has_light, LIGHT_MAX, ContentLightingFlags::light_source, LIGHT_SUN, voxalgo::LightQueue::lights, MAP_BLOCKSIZE, voxalgo::LightQueue::push(), MapNode::setLight(), spread_light(), and unspread_light().
Referenced by blit_back_with_light(), and repair_block_light().
bool voxalgo::is_light_locally_correct | ( | Map * | map, |
const NodeDefManager * | ndef, | ||
LightBank | bank, | ||
v3s16 | pos ) |
Returns true if: -the node has unloaded neighbors -the node doesn't have light -the node's light is the same as the maximum of its light source and its brightest neighbor minus one.
References MapNode::getLight(), NodeDefManager::getLightingFlags(), Map::getNode(), ContentLightingFlags::has_light, LIGHT_MAX, ContentLightingFlags::light_source, LIGHT_SUN, and neighbor_dirs.
Referenced by update_block_border_lighting().
bool voxalgo::is_sunlight_above | ( | Map * | map, |
v3s16 | pos, | ||
const NodeDefManager * | ndef ) |
Returns true if the node gets sunlight from the node above it.
pos | position of the node. |
References CONTENT_IGNORE, Map::getBlockNoCreateNoEx(), MapNode::getContent(), MapBlock::getIsUnderground(), MapNode::getLight(), NodeDefManager::getLightingFlags(), getNodeBlockPos(), getNodeBlockPosWithOffset(), MapBlock::getNodeNoCheck(), LIGHT_SUN, and LIGHTBANK_DAY.
Referenced by update_lighting_nodes().
void voxalgo::is_sunlight_above_block | ( | Map * | map, |
mapblock_v3 | pos, | ||
const NodeDefManager * | ndef, | ||
bool | light[MAP_BLOCKSIZE][MAP_BLOCKSIZE] ) |
Returns incoming sunlight for one map block. If block above is not found, it is loaded.
pos | position of the map block that gets the sunlight. |
light | incoming sunlight, light[z][x] is true if there is sunlight above the block at the given z-x relative node coordinates. |
References Map::emergeBlock(), Map::getBlockNoCreateNoEx(), MapBlock::getIsUnderground(), MapNode::getLight(), NodeDefManager::getLightingFlags(), MapBlock::getNodeNoCheck(), MapBlock::isGenerated(), LIGHT_SUN, LIGHTBANK_DAY, and MAP_BLOCKSIZE.
Referenced by blit_back_with_light(), and repair_block_light().
bool voxalgo::propagate_block_sunlight | ( | Map * | map, |
const NodeDefManager * | ndef, | ||
SunlightPropagationData * | data, | ||
UnlightQueue * | unlight, | ||
ReLightQueue * | relight ) |
Propagates sunlight down in a given map block.
data | contains incoming sunlight and shadow and the coordinates of the target block. |
unlight | propagated shadow is inserted here |
relight | propagated sunlight is inserted here |
References voxalgo::SunlightPropagationData::data, Map::getBlockNoCreateNoEx(), NodeDefManager::getLightingFlags(), MapNode::getLightRaw(), MapBlock::getNodeNoCheck(), voxalgo::SunlightPropagationUnit::is_sunlit, LIGHT_SUN, LIGHTBANK_DAY, MAP_BLOCKSIZE, voxalgo::LightQueue::push(), voxalgo::SunlightPropagationUnit::relative_pos, MapNode::setLight(), MapBlock::setNodeNoCheck(), ContentLightingFlags::sunlight_propagates, and voxalgo::SunlightPropagationData::target_block.
Referenced by blit_back_with_light(), and repair_block_light().
void voxalgo::repair_block_light | ( | Map * | map, |
MapBlock * | block, | ||
std::map< v3s16, MapBlock * > * | modified_blocks ) |
Corrects the light in a map block. For server use only.
block | the block to update |
References banks, block_pad, voxalgo::SunlightPropagationData::data, fill_with_sunlight(), finish_bulk_light_update(), Map::getBlockNoCreateNoEx(), MapNode::getLight(), NodeDefManager::getLightingFlags(), Map::getNodeDefManager(), MapBlock::getNodeNoCheck(), MapBlock::getPos(), ContentLightingFlags::has_light, is_sunlight_above_block(), ContentLightingFlags::light_source, LIGHT_SUN, MAP_BLOCKSIZE, propagate_block_sunlight(), voxalgo::LightQueue::push(), and voxalgo::SunlightPropagationData::target_block.
Referenced by ServerMap::repairBlockLight().
void voxalgo::spread_light | ( | Map * | map, |
const NodeDefManager * | nodemgr, | ||
LightBank | bank, | ||
LightQueue & | light_sources, | ||
std::map< v3s16, MapBlock * > & | modified_blocks ) |
References voxalgo::ChangingLight::block, voxalgo::ChangingLight::block_position, Map::getBlockNoCreateNoEx(), NodeDefManager::getLightingFlags(), MapNode::getLightRaw(), MapBlock::getNodeNoCheck(), ContentLightingFlags::light_propagates, voxalgo::LightQueue::next(), voxalgo::LightQueue::push(), voxalgo::ChangingLight::rel_position, MapNode::setLight(), MapBlock::setLightingComplete(), MapBlock::setNodeNoCheck(), voxalgo::ChangingLight::source_direction, and step_rel_block_pos().
Referenced by finish_bulk_light_update(), update_block_border_lighting(), and update_lighting_nodes().
bool voxalgo::step_rel_block_pos | ( | direction | dir, |
relative_v3 & | rel_pos, | ||
mapblock_v3 & | block_pos ) |
Transforms the given map block offset by one node towards the specified direction.
dir | the direction of the transformation |
rel_pos | the node's relative position in its map block |
block_pos | position of the node's block |
References dir(), and MAP_BLOCKSIZE.
Referenced by spread_light(), and unspread_light().
void voxalgo::unspread_light | ( | Map * | map, |
const NodeDefManager * | nodemgr, | ||
LightBank | bank, | ||
UnlightQueue & | from_nodes, | ||
ReLightQueue & | light_sources, | ||
std::map< v3s16, MapBlock * > & | modified_blocks ) |
References voxalgo::ChangingLight::block, voxalgo::ChangingLight::block_position, Map::getBlockNoCreateNoEx(), MapNode::getContent(), NodeDefManager::getLightingFlags(), MapNode::getLightRaw(), MapBlock::getNodeNoCheck(), ContentLightingFlags::light_propagates, ContentLightingFlags::light_source, voxalgo::LightQueue::next(), voxalgo::LightQueue::push(), voxalgo::ChangingLight::rel_position, MapNode::setLight(), MapBlock::setLightingComplete(), MapBlock::setNodeNoCheck(), voxalgo::ChangingLight::source_direction, and step_rel_block_pos().
Referenced by finish_bulk_light_update(), update_block_border_lighting(), and update_lighting_nodes().
void voxalgo::update_block_border_lighting | ( | Map * | map, |
MapBlock * | block, | ||
std::map< v3s16, MapBlock * > & | modified_blocks ) |
Updates borders of the given mapblock. Only updates if the block was marked with incomplete lighting and the neighbor is also loaded.
block | the block to update |
modified_blocks | output, contains all map blocks that the function modified |
References banks, block_borders, voxalgo::LightQueue::clear(), Map::getBlockNoCreateNoEx(), MapNode::getLight(), NodeDefManager::getLightingFlags(), Map::getNodeDefManager(), MapBlock::getNodeNoCheck(), MapBlock::getPos(), MapBlock::getPosRelative(), is_light_locally_correct(), MapBlock::isLightingComplete(), LIGHT_SUN, voxalgo::LightQueue::lights, VoxelArea::MaxEdge, VoxelArea::MinEdge, neighbor_dirs, voxalgo::LightQueue::push(), MapNode::setLight(), MapBlock::setLightingComplete(), MapBlock::setNodeNoCheck(), spread_light(), and unspread_light().
Referenced by ServerMap::loadBlock().
void voxalgo::update_lighting_nodes | ( | Map * | map, |
const std::vector< std::pair< v3s16, MapNode > > & | oldnodes, | ||
std::map< v3s16, MapBlock * > & | modified_blocks ) |
Updates the lighting on the map. The result will be correct only if no nodes were changed except the given ones. Before calling this procedure make sure that all new nodes on the map have zero light level!
oldnodes | contains the MapNodes that were replaced by the new MapNodes and their positions |
modified_blocks | output, contains all map blocks that the function modified |
References banks, voxalgo::LightQueue::clear(), Map::getBlockNoCreateNoEx(), MapNode::getLight(), NodeDefManager::getLightingFlags(), Map::getNode(), getNodeBlockPosWithOffset(), Map::getNodeDefManager(), MapBlock::getNodeNoCheck(), is_sunlight_above(), ContentLightingFlags::light_propagates, ContentLightingFlags::light_source, LIGHT_SUN, LIGHTBANK_DAY, voxalgo::LightQueue::lights, neighbor_dirs, p(), voxalgo::LightQueue::push(), MapNode::setLight(), Map::setNode(), MapBlock::setNodeNoCheck(), spread_light(), ContentLightingFlags::sunlight_propagates, and unspread_light().
Referenced by Map::addNodeAndUpdate(), and ServerMap::transformLiquids().
|
staticconstexpr |
|
static |
Referenced by update_block_border_lighting().
const VoxelArea voxalgo::block_pad[] |
Borders of a map block in relative node coordinates. The areas do not overlap. Compatible with type 'direction'.
Referenced by blit_back_with_light(), and repair_block_light().
|
static |
neighbor_dirs[i] points towards the direction i. See the definition of the type "direction"
Referenced by is_light_locally_correct(), update_block_border_lighting(), and update_lighting_nodes().