Minetest 5.10.0-dev
 
Loading...
Searching...
No Matches
voxalgo Namespace Reference

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 Documentation

◆ direction

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.

◆ mapblock_v3

Position of a map block (block coordinates). One block_pos unit is as long as 16 node position units.

◆ relative_v3

Relative node position. This represents a node's position in its map block. All coordinates must be between 0 and 15.

◆ 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.

◆ 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.

Function Documentation

◆ blit_back_with_light()

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.

Parameters
modified_blocksoutput, 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fill_with_sunlight() [1/2]

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.

Parameters
lightincoming 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.

+ Here is the call graph for this function:

◆ fill_with_sunlight() [2/2]

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.

Parameters
offsetcontains the least x and z node coordinates of the map sector.
lightincoming 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ finish_bulk_light_update()

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.

Parameters
minblockleast coordinates of the changed area in block coordinates
maxblockgreatest coordinates of the changed area in block coordinates
unlightthe first queue is for day light, the second is for night light. Contains all nodes on the borders that need to be unlit.
relightthe 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_blocksthe 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ is_light_locally_correct()

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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ is_sunlight_above()

bool voxalgo::is_sunlight_above ( Map * map,
v3s16 pos,
const NodeDefManager * ndef )

Returns true if the node gets sunlight from the node above it.

Parameters
posposition 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ is_sunlight_above_block()

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.

Parameters
posposition of the map block that gets the sunlight.
lightincoming 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ propagate_block_sunlight()

bool voxalgo::propagate_block_sunlight ( Map * map,
const NodeDefManager * ndef,
SunlightPropagationData * data,
UnlightQueue * unlight,
ReLightQueue * relight )

Propagates sunlight down in a given map block.

Parameters
datacontains incoming sunlight and shadow and the coordinates of the target block.
unlightpropagated shadow is inserted here
relightpropagated sunlight is inserted here
Returns
true if the block was modified, false otherwise.

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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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.

Parameters
blockthe 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ spread_light()

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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ step_rel_block_pos()

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.

Parameters
dirthe direction of the transformation
rel_posthe node's relative position in its map block
block_posposition of the node's block

References dir(), and MAP_BLOCKSIZE.

Referenced by spread_light(), and unspread_light().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 )

◆ update_block_border_lighting()

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.

Parameters
blockthe block to update
modified_blocksoutput, 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update_lighting_nodes()

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!

Parameters
oldnodescontains the MapNodes that were replaced by the new MapNodes and their positions
modified_blocksoutput, 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ banks

◆ block_borders

const VoxelArea voxalgo::block_borders[]
static
Initial value:
= {
VoxelArea(v3s16(B_1, 0, 0), v3s16(B_1, B_1, B_1)),
VoxelArea(v3s16(0, B_1, 0), v3s16(B_1, B_1, B_1)),
VoxelArea(v3s16(0, 0, B_1), v3s16(B_1, B_1, B_1)),
VoxelArea(v3s16(0, 0, 0), v3s16(B_1, B_1, 0)),
VoxelArea(v3s16(0, 0, 0), v3s16(B_1, 0, B_1)),
VoxelArea(v3s16(0, 0, 0), v3s16(0, B_1, B_1))
}
Definition voxel.h:59
core::vector3d< s16 > v3s16
Definition irr_v3d.h:28
#define B_1
Definition voxelalgorithms.cpp:649

Referenced by update_block_border_lighting().

◆ block_pad

const VoxelArea voxalgo::block_pad[]
Initial value:
= {
VoxelArea(v3s16(15, 0, 0), v3s16(15, 15, 15)),
VoxelArea(v3s16(1, 15, 0), v3s16(14, 15, 15)),
VoxelArea(v3s16(1, 1, 15), v3s16(14, 14, 15)),
VoxelArea(v3s16(1, 1, 0), v3s16(14, 14, 0)),
VoxelArea(v3s16(1, 0, 0), v3s16(14, 0, 15)),
VoxelArea(v3s16(0, 0, 0), v3s16(0, 15, 15))
}

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().

◆ neighbor_dirs

const v3s16 voxalgo::neighbor_dirs[6]
static
Initial value:
= {
v3s16(1, 0, 0),
v3s16(0, 1, 0),
v3s16(0, 0, 1),
v3s16(0, 0, -1),
v3s16(0, -1, 0),
v3s16(-1, 0, 0),
}

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().