aboutsummaryrefslogtreecommitdiff
path: root/src
ModeNameSize
-rw-r--r--CMakeLists.txt25585logplain
-rw-r--r--activeobject.h3371logplain
-rw-r--r--activeobjectmgr.h1842logplain
-rw-r--r--ban.cpp3577logplain
-rw-r--r--ban.h1478logplain
-rw-r--r--chat.cpp17970logplain
-rw-r--r--chat.h7854logplain
-rw-r--r--chat_interface.h1880logplain
-rw-r--r--chatmessage.h1416logplain
d---------client3147logplain
-rw-r--r--clientiface.cpp23173logplain
-rw-r--r--clientiface.h19990logplain
-rw-r--r--cloudparams.h941logplain
-rw-r--r--cmake_config.h.in1237logplain
-rw-r--r--cmake_config_githash.h.in169logplain
-rw-r--r--collision.cpp18384logplain
-rw-r--r--collision.h2496logplain
-rw-r--r--config.h651logplain
-rw-r--r--constants.h3466logplain
d---------content266logplain
-rw-r--r--content_mapnode.cpp5081logplain
-rw-r--r--content_mapnode.h1171logplain
-rw-r--r--content_nodemeta.cpp5345logplain
-rw-r--r--content_nodemeta.h1072logplain
-rw-r--r--convert_json.cpp2378logplain
-rw-r--r--convert_json.h972logplain
-rw-r--r--craftdef.cpp29692logplain
-rw-r--r--craftdef.h13710logplain
d---------database678logplain
-rw-r--r--daynightratio.h1948logplain
-rw-r--r--debug.cpp5530logplain
-rw-r--r--debug.h2829logplain
-rw-r--r--defaultsettings.cpp22808logplain
-rw-r--r--defaultsettings.h929logplain
-rw-r--r--emerge.cpp17159logplain
-rw-r--r--emerge.h5740logplain
-rw-r--r--environment.cpp9464logplain
-rw-r--r--environment.h4348logplain
-rw-r--r--exceptions.h3139logplain
-rw-r--r--face_position_cache.cpp3452logplain
-rw-r--r--face_position_cache.h1272logplain
-rw-r--r--filesys.cpp18348logplain
-rw-r--r--filesys.h4424logplain
-rw-r--r--gamedef.h2789logplain
-rw-r--r--gameparams.h1361logplain
-rw-r--r--gettext.cpp7396logplain
-rw-r--r--gettext.h2111logplain
-rw-r--r--gettime.h1236logplain
d---------gui2667logplain
-rw-r--r--httpfetch.cpp21213logplain
-rw-r--r--httpfetch.h3755logplain
-rw-r--r--hud.cpp2142logplain
-rw-r--r--hud.h2991logplain
-rw-r--r--inventory.cpp21472logplain
-rw-r--r--inventory.h9408logplain
-rw-r--r--inventorymanager.cpp28283logplain
-rw-r--r--inventorymanager.h5715logplain
-rw-r--r--irr_aabb3d.h891logplain
-rw-r--r--irr_ptr.h5984logplain
-rw-r--r--irr_v2d.h1028logplain
-rw-r--r--irr_v3d.h1025logplain
d---------irrlicht_changes248logplain
-rw-r--r--irrlichttypes.h2115logplain
-rw-r--r--irrlichttypes_bloated.h919logplain
-rw-r--r--irrlichttypes_extrabloated.h1150logplain
-rw-r--r--itemdef.cpp16223logplain
-rw-r--r--itemdef.h5718logplain
-rw-r--r--itemgroup.h1103logplain
-rw-r--r--itemstackmetadata.cpp3288logplain
-rw-r--r--itemstackmetadata.h1530logplain
-rw-r--r--light.cpp3095logplain
-rw-r--r--light.h2283logplain
-rw-r--r--log.cpp10222logplain
-rw-r--r--log.h5204logplain
-rw-r--r--main.cpp32190logplain
-rw-r--r--map.cpp52826logplain
-rw-r--r--map.h11696logplain
-rw-r--r--map_settings_manager.cpp4890logplain
-rw-r--r--map_settings_manager.h2619logplain
-rw-r--r--mapblock.cpp21989logplain
-rw-r--r--mapblock.h14955logplain
d---------mapgen1372logplain
-rw-r--r--mapnode.cpp20924logplain
-rw-r--r--mapnode.h8298logplain
-rw-r--r--mapsector.cpp2774logplain
-rw-r--r--mapsector.h1982logplain
-rw-r--r--metadata.cpp2735logplain
-rw-r--r--metadata.h1933logplain
-rw-r--r--modchannels.cpp3920logplain
-rw-r--r--modchannels.h2753logplain
-rw-r--r--modifiedstate.h1117logplain
-rw-r--r--mtevent.h1830logplain
-rw-r--r--nameidmapping.cpp1490logplain
-rw-r--r--nameidmapping.h2173logplain
d---------network869logplain
-rw-r--r--nodedef.cpp49558logplain
-rw-r--r--nodedef.h22639logplain
-rw-r--r--nodemetadata.cpp5608logplain
-rw-r--r--nodemetadata.h2827logplain
-rw-r--r--nodetimer.cpp3831logplain
-rw-r--r--nodetimer.h3753logplain
-rw-r--r--noise.cpp19828logplain
-rw-r--r--noise.h6706logplain
-rw-r--r--objdef.cpp4539logplain
-rw-r--r--objdef.h3580logplain
-rw-r--r--object_properties.cpp6805logplain
-rw-r--r--object_properties.h2363logplain
-rw-r--r--particles.cpp2021logplain
-rw-r--r--particles.h2368logplain
-rw-r--r--pathfinder.cpp40327logplain
-rw-r--r--pathfinder.h2452logplain
-rw-r--r--player.cpp4969logplain
-rw-r--r--player.h5267logplain
-rw-r--r--porting.cpp18097logplain
-rw-r--r--porting.h8366logplain
-rw-r--r--porting_android.cpp8845logplain
-rw-r--r--porting_android.h2122logplain
-rw-r--r--profiler.cpp4059logplain
-rw-r--r--profiler.h2591logplain
-rw-r--r--raycast.cpp3811logplain
-rw-r--r--raycast.h2623logplain
-rw-r--r--reflowscan.cpp7050logplain
-rw-r--r--reflowscan.h1469logplain
-rw-r--r--remoteplayer.cpp4965logplain
-rw-r--r--remoteplayer.h4413logplain
-rw-r--r--rollback.cpp27394logplain
-rw-r--r--rollback.h3519logplain
-rw-r--r--rollback_interface.cpp7099logplain
-rw-r--r--rollback_interface.h4009logplain
d---------script429logplain
-rw-r--r--serialization.cpp6459logplain
-rw-r--r--serialization.h3498logplain
-rw-r--r--server.cpp105130logplain
-rw-r--r--server.h22595logplain
d---------server648logplain
-rw-r--r--serverenvironment.cpp69286logplain
-rw-r--r--serverenvironment.h14267logplain
-rw-r--r--serverlist.cpp3956logplain
-rw-r--r--serverlist.h1345logplain
-rw-r--r--settings.cpp22437logplain
-rw-r--r--settings.h7965logplain
-rw-r--r--settings_translation_file.cpp78038logplain
-rw-r--r--skyparams.h2766logplain
-rw-r--r--sound.h1681logplain
-rw-r--r--staticobject.cpp2620logplain
-rw-r--r--staticobject.h2220logplain
-rw-r--r--terminal_chat_console.cpp11894logplain
-rw-r--r--terminal_chat_console.h2961logplain
-rw-r--r--texture_override.cpp4704logplain
-rw-r--r--texture_override.h2308logplain
d---------threading313logplain
-rw-r--r--tileanimation.cpp3697logplain
-rw-r--r--tileanimation.h1717logplain
-rw-r--r--tool.cpp8417logplain
-rw-r--r--tool.h3369logplain
-rw-r--r--translation.cpp4013logplain
-rw-r--r--translation.h1194logplain
d---------unittest1944logplain
d---------util1659logplain
-rw-r--r--version.cpp1465logplain
-rw-r--r--version.h904logplain
-rw-r--r--voxel.cpp8345logplain
-rw-r--r--voxel.h10952logplain
-rw-r--r--voxelalgorithms.cpp42874logplain
-rw-r--r--voxelalgorithms.h4608logplain
/span> { // The light the current node can provide to its neighbors. u8 spreading_light; // The ChangingLight for the current node. ChangingLight current; // Position of the current neighbor. mapblock_v3 neighbor_block_pos; relative_v3 neighbor_rel_pos; // A dummy boolean. bool is_valid_position; while (light_sources.next(spreading_light, current)) { spreading_light--; for (direction i = 0; i < 6; i++) { // This node can't light up its light source if (current.source_direction + i == 5) { continue; } // Get the neighbor's position and block neighbor_rel_pos = current.rel_position; neighbor_block_pos = current.block_position; MapBlock *neighbor_block; if (step_rel_block_pos(i, neighbor_rel_pos, neighbor_block_pos)) { neighbor_block = map->getBlockNoCreateNoEx(neighbor_block_pos); if (neighbor_block == NULL) { current.block->setLightingComplete(bank, i, false); continue; } } else { neighbor_block = current.block; } // Get the neighbor itself MapNode neighbor = neighbor_block->getNodeNoCheck(neighbor_rel_pos, &is_valid_position); const ContentFeatures &f = nodemgr->get(neighbor.getContent()); if (f.light_propagates) { // Light up the neighbor, if it has less light than it should. u8 neighbor_light = neighbor.getLightRaw(bank, f); if (neighbor_light < spreading_light) { neighbor.setLight(bank, spreading_light, f); neighbor_block->setNodeNoCheck(neighbor_rel_pos, neighbor); light_sources.push(spreading_light, neighbor_rel_pos, neighbor_block_pos, neighbor_block, i); // The current node was modified earlier, so its block // is in modified_blocks. if (current.block != neighbor_block) { modified_blocks[neighbor_block_pos] = neighbor_block; } } } } } } struct SunlightPropagationUnit{ v2s16 relative_pos; bool is_sunlit; SunlightPropagationUnit(v2s16 relpos, bool sunlit): relative_pos(relpos), is_sunlit(sunlit) {} }; struct SunlightPropagationData{ std::vector<SunlightPropagationUnit> data; v3s16 target_block; }; /*! * Returns true if the node gets sunlight from the * node above it. * * \param pos position of the node. */ bool is_sunlight_above(Map *map, v3s16 pos, const NodeDefManager *ndef) { bool sunlight = true; mapblock_v3 source_block_pos; relative_v3 source_rel_pos; getNodeBlockPosWithOffset(pos + v3s16(0, 1, 0), source_block_pos, source_rel_pos); // If the node above has sunlight, this node also can get it. MapBlock *source_block = map->getBlockNoCreateNoEx(source_block_pos); if (source_block == NULL) { // But if there is no node above, then use heuristics MapBlock *node_block = map->getBlockNoCreateNoEx(getNodeBlockPos(pos)); if (node_block == NULL) { sunlight = false; } else { sunlight = !node_block->getIsUnderground(); } } else { bool is_valid_position; MapNode above = source_block->getNodeNoCheck(source_rel_pos, &is_valid_position); if (is_valid_position) { if (above.getContent() == CONTENT_IGNORE) { // Trust heuristics if (source_block->getIsUnderground()) { sunlight = false; } } else if (above.getLight(LIGHTBANK_DAY, ndef) != LIGHT_SUN) { // If the node above doesn't have sunlight, this // node is in shadow. sunlight = false; } } } return sunlight; } static const LightBank banks[] = { LIGHTBANK_DAY, LIGHTBANK_NIGHT }; void update_lighting_nodes(Map *map, std::vector<std::pair<v3s16, MapNode> > &oldnodes, std::map<v3s16, MapBlock*> &modified_blocks) { const NodeDefManager *ndef = map->getNodeDefManager(); // For node getter functions bool is_valid_position; // Process each light bank separately for (LightBank bank : banks) { UnlightQueue disappearing_lights(256); ReLightQueue light_sources(256); // Nodes that are brighter than the brightest modified node was // won't change, since they didn't get their light from a // modified node. u8 min_safe_light = 0; for (std::vector<std::pair<v3s16, MapNode> >::iterator it = oldnodes.begin(); it < oldnodes.end(); ++it) { u8 old_light = it->second.getLight(bank, ndef); if (old_light > min_safe_light) { min_safe_light = old_light; } } // If only one node changed, even nodes with the same brightness // didn't get their light from the changed node. if (oldnodes.size() > 1) { min_safe_light++; } // For each changed node process sunlight and initialize for (std::vector<std::pair<v3s16, MapNode> >::iterator it = oldnodes.begin(); it < oldnodes.end(); ++it) { // Get position and block of the changed node v3s16 p = it->first; relative_v3 rel_pos; mapblock_v3 block_pos; getNodeBlockPosWithOffset(p, block_pos, rel_pos); MapBlock *block = map->getBlockNoCreateNoEx(block_pos); if (block == NULL || block->isDummy()) { continue; } // Get the new node MapNode n = block->getNodeNoCheck(rel_pos, &is_valid_position); if (!is_valid_position) { break; } // Light of the old node u8 old_light = it->second.getLight(bank, ndef); // Add the block of the added node to modified_blocks modified_blocks[block_pos] = block; // Get new light level of the node u8 new_light = 0; if (ndef->get(n).light_propagates) { if (bank == LIGHTBANK_DAY && ndef->get(n).sunlight_propagates && is_sunlight_above(map, p, ndef)) { new_light = LIGHT_SUN; } else { new_light = ndef->get(n).light_source; for (const v3s16 &neighbor_dir : neighbor_dirs) { v3s16 p2 = p + neighbor_dir; bool is_valid; MapNode n2 = map->getNodeNoEx(p2, &is_valid); if (is_valid) { u8 spread = n2.getLight(bank, ndef); // If it is sure that the neighbor won't be // unlighted, its light can spread to this node. if (spread > new_light && spread >= min_safe_light) { new_light = spread - 1; } } } } } else { // If this is an opaque node, it still can emit light. new_light = ndef->get(n).light_source; } if (new_light > 0) { light_sources.push(new_light, rel_pos, block_pos, block, 6); } if (new_light < old_light) { // The node became opaque or doesn't provide as much // light as the previous one, so it must be unlighted. // Add to unlight queue n.setLight(bank, 0, ndef); block->setNodeNoCheck(rel_pos, n); disappearing_lights.push(old_light, rel_pos, block_pos, block, 6); // Remove sunlight, if there was any if (bank == LIGHTBANK_DAY && old_light == LIGHT_SUN) { for (s16 y = p.Y - 1;; y--) { v3s16 n2pos(p.X, y, p.Z); MapNode n2; n2 = map->getNodeNoEx(n2pos, &is_valid_position); if (!is_valid_position) break; // If this node doesn't have sunlight, the nodes below // it don't have too. if (n2.getLight(LIGHTBANK_DAY, ndef) != LIGHT_SUN) { break; } // Remove sunlight and add to unlight queue. n2.setLight(LIGHTBANK_DAY, 0, ndef); map->setNode(n2pos, n2); relative_v3 rel_pos2; mapblock_v3 block_pos2; getNodeBlockPosWithOffset(n2pos, block_pos2, rel_pos2); MapBlock *block2 = map->getBlockNoCreateNoEx( block_pos2); disappearing_lights.push(LIGHT_SUN, rel_pos2, block_pos2, block2, 4 /* The node above caused the change */); } } } else if (new_light > old_light) { // It is sure that the node provides more light than the previous // one, unlighting is not necessary. // Propagate sunlight if (bank == LIGHTBANK_DAY && new_light == LIGHT_SUN) { for (s16 y = p.Y - 1;; y--) { v3s16 n2pos(p.X, y, p.Z); MapNode n2; n2 = map->getNodeNoEx(n2pos, &is_valid_position); if (!is_valid_position) break; // This should not happen, but if the node has sunlight // then the iteration should stop. if (n2.getLight(LIGHTBANK_DAY, ndef) == LIGHT_SUN) { break; } // If the node terminates sunlight, stop. if (!ndef->get(n2).sunlight_propagates) { break; } relative_v3 rel_pos2; mapblock_v3 block_pos2; getNodeBlockPosWithOffset(n2pos, block_pos2, rel_pos2); MapBlock *block2 = map->getBlockNoCreateNoEx( block_pos2); // Mark node for lighting. light_sources.push(LIGHT_SUN, rel_pos2, block_pos2, block2, 4); } } } } // Remove lights unspread_light(map, ndef, bank, disappearing_lights, light_sources, modified_blocks); // Initialize light values for light spreading. for (u8 i = 0; i <= LIGHT_SUN; i++) { const std::vector<ChangingLight> &lights = light_sources.lights[i]; for (std::vector<ChangingLight>::const_iterator it = lights.begin(); it < lights.end(); ++it) { MapNode n = it->block->getNodeNoCheck(it->rel_position, &is_valid_position); n.setLight(bank, i, ndef); it->block->setNodeNoCheck(it->rel_position, n); } } // Spread lights. spread_light(map, ndef, bank, light_sources, modified_blocks); } } /*! * Borders of a map block in relative node coordinates. * Compatible with type 'direction'. */ const VoxelArea block_borders[] = { VoxelArea(v3s16(15, 0, 0), v3s16(15, 15, 15)), //X+ VoxelArea(v3s16(0, 15, 0), v3s16(15, 15, 15)), //Y+ VoxelArea(v3s16(0, 0, 15), v3s16(15, 15, 15)), //Z+ VoxelArea(v3s16(0, 0, 0), v3s16(15, 15, 0)), //Z- VoxelArea(v3s16(0, 0, 0), v3s16(15, 0, 15)), //Y- VoxelArea(v3s16(0, 0, 0), v3s16(0, 15, 15)) //X- }; /*! * 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. * . */ bool is_light_locally_correct(Map *map, const NodeDefManager *ndef, LightBank bank, v3s16 pos) { bool is_valid_position; MapNode n = map->getNodeNoEx(pos, &is_valid_position); const ContentFeatures &f = ndef->get(n); if (f.param_type != CPT_LIGHT) { return true; } u8 light = n.getLightNoChecks(bank, &f); assert(f.light_source <= LIGHT_MAX); u8 brightest_neighbor = f.light_source + 1; for (const v3s16 &neighbor_dir : neighbor_dirs) { MapNode n2 = map->getNodeNoEx(pos + neighbor_dir, &is_valid_position); u8 light2 = n2.getLight(bank, ndef); if (brightest_neighbor < light2) { brightest_neighbor = light2; } } assert(light <= LIGHT_SUN); return brightest_neighbor == light + 1; } void update_block_border_lighting(Map *map, MapBlock *block, std::map<v3s16, MapBlock*> &modified_blocks) { const NodeDefManager *ndef = map->getNodeDefManager(); bool is_valid_position; for (LightBank bank : banks) { // Since invalid light is not common, do not allocate // memory if not needed. UnlightQueue disappearing_lights(0); ReLightQueue light_sources(0); // Get incorrect lights for (direction d = 0; d < 6; d++) { // For each direction // Get neighbor block v3s16 otherpos = block->getPos() + neighbor_dirs[d]; MapBlock *other = map->getBlockNoCreateNoEx(otherpos); if (other == NULL) { continue; } // Only update if lighting was not completed. if (block->isLightingComplete(bank, d) && other->isLightingComplete(bank, 5 - d)) continue; // Reset flags block->setLightingComplete(bank, d, true); other->setLightingComplete(bank, 5 - d, true); // The two blocks and their connecting surfaces MapBlock *blocks[] = {block, other}; VoxelArea areas[] = {block_borders[d], block_borders[5 - d]}; // For both blocks for (u8 blocknum = 0; blocknum < 2; blocknum++) { MapBlock *b = blocks[blocknum]; VoxelArea a = areas[blocknum]; // For all nodes for (s32 x = a.MinEdge.X; x <= a.MaxEdge.X; x++) for (s32 z = a.MinEdge.Z; z <= a.MaxEdge.Z; z++) for (s32 y = a.MinEdge.Y; y <= a.MaxEdge.Y; y++) { MapNode n = b->getNodeNoCheck(x, y, z, &is_valid_position); u8 light = n.getLight(bank, ndef); // Sunlight is fixed if (light < LIGHT_SUN) { // Unlight if not correct if (!is_light_locally_correct(map, ndef, bank, v3s16(x, y, z) + b->getPosRelative())) { // Initialize for unlighting n.setLight(bank, 0, ndef); b->setNodeNoCheck(x, y, z, n); modified_blocks[b->getPos()]=b; disappearing_lights.push(light, relative_v3(x, y, z), b->getPos(), b, 6); } } } } } // Remove lights unspread_light(map, ndef, bank, disappearing_lights, light_sources, modified_blocks); // Initialize light values for light spreading. for (u8 i = 0; i <= LIGHT_SUN; i++) { const std::vector<ChangingLight> &lights = light_sources.lights[i]; for (std::vector<ChangingLight>::const_iterator it = lights.begin(); it < lights.end(); ++it) { MapNode n = it->block->getNodeNoCheck(it->rel_position, &is_valid_position); n.setLight(bank, i, ndef); it->block->setNodeNoCheck(it->rel_position, n); } } // Spread lights. spread_light(map, ndef, bank, light_sources, modified_blocks); } } /*! * Resets the lighting of the given VoxelManipulator to * complete darkness and full sunlight. * Operates in one map sector. * * \param offset contains the least x and z node coordinates * of the map sector. * \param 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. */ void fill_with_sunlight(MMVManip *vm, const NodeDefManager *ndef, v2s16 offset, bool light[MAP_BLOCKSIZE][MAP_BLOCKSIZE]) { // Distance in array between two nodes on top of each other. s16 ystride = vm->m_area.getExtent().X; // Cache the ignore node. MapNode ignore = MapNode(CONTENT_IGNORE); // For each column of nodes: for (s16 z = 0; z < MAP_BLOCKSIZE; z++) for (s16 x = 0; x < MAP_BLOCKSIZE; x++) { // Position of the column on the map. v2s16 realpos = offset + v2s16(x, z); // Array indices in the voxel manipulator s32 maxindex = vm->m_area.index(realpos.X, vm->m_area.MaxEdge.Y, realpos.Y); s32 minindex = vm->m_area.index(realpos.X, vm->m_area.MinEdge.Y, realpos.Y); // True if the current node has sunlight. bool lig = light[z][x]; // For each node, downwards: for (s32 i = maxindex; i >= minindex; i -= ystride) { MapNode *n; if (vm->m_flags[i] & VOXELFLAG_NO_DATA) n = &ignore; else n = &vm->m_data[i]; // Ignore IGNORE nodes, these are not generated yet. if(n->getContent() == CONTENT_IGNORE) continue; const ContentFeatures &f = ndef->get(n->getContent()); if (lig && !f.sunlight_propagates) // Sunlight is stopped. lig = false; // Reset light n->setLight(LIGHTBANK_DAY, lig ? 15 : 0, f); n->setLight(LIGHTBANK_NIGHT, 0, f); } // Output outgoing light. light[z][x] = lig; } } /*! * Returns incoming sunlight for one map block. * If block above is not found, it is loaded. * * \param pos position of the map block that gets the sunlight. * \param light incoming sunlight, light[z][x] is true if there * is sunlight above the block at the given z-x relative * node coordinates. */ void is_sunlight_above_block(ServerMap *map, mapblock_v3 pos, const NodeDefManager *ndef, bool light[MAP_BLOCKSIZE][MAP_BLOCKSIZE]) { mapblock_v3 source_block_pos = pos + v3s16(0, 1, 0); // Get or load source block. // It might take a while to load, but correcting incorrect // sunlight may be even slower. MapBlock *source_block = map->emergeBlock(source_block_pos, false); // Trust only generated blocks. if (source_block == NULL || source_block->isDummy() || !source_block->isGenerated()) { // But if there is no block above, then use heuristics bool sunlight = true; MapBlock *node_block = map->getBlockNoCreateNoEx(pos); if (node_block == NULL) // This should not happen. sunlight = false; else sunlight = !node_block->getIsUnderground(); for (s16 z = 0; z < MAP_BLOCKSIZE; z++) for (s16 x = 0; x < MAP_BLOCKSIZE; x++) light[z][x] = sunlight; } else { // Dummy boolean, the position is valid. bool is_valid_position; // For each column: for (s16 z = 0; z < MAP_BLOCKSIZE; z++) for (s16 x = 0; x < MAP_BLOCKSIZE; x++) { // Get the bottom block. MapNode above = source_block->getNodeNoCheck(x, 0, z, &is_valid_position); light[z][x] = above.getLight(LIGHTBANK_DAY, ndef) == LIGHT_SUN; } } } /*! * Propagates sunlight down in a given map block. * * \param data contains incoming sunlight and shadow and * the coordinates of the target block. * \param unlight propagated shadow is inserted here * \param relight propagated sunlight is inserted here * * \returns true if the block was modified, false otherwise. */ bool propagate_block_sunlight(Map *map, const NodeDefManager *ndef, SunlightPropagationData *data, UnlightQueue *unlight, ReLightQueue *relight) { bool modified = false; // Get the block. MapBlock *block = map->getBlockNoCreateNoEx(data->target_block); if (block == NULL || block->isDummy()) { // The work is done if the block does not contain data. data->data.clear(); return false; } // Dummy boolean bool is_valid; // For each changing column of nodes: size_t index; for (index = 0; index < data->data.size(); index++) { SunlightPropagationUnit it = data->data[index]; // Relative position of the currently inspected node. relative_v3 current_pos(it.relative_pos.X, MAP_BLOCKSIZE - 1, it.relative_pos.Y); if (it.is_sunlit) { // Propagate sunlight. // For each node downwards: for (; current_pos.Y >= 0; current_pos.Y--) { MapNode n = block->getNodeNoCheck(current_pos, &is_valid); const ContentFeatures &f = ndef->get(n); if (n.getLightRaw(LIGHTBANK_DAY, f) < LIGHT_SUN && f.sunlight_propagates) { // This node gets sunlight. n.setLight(LIGHTBANK_DAY, LIGHT_SUN, f); block->setNodeNoCheck(current_pos, n); modified = true; relight->push(LIGHT_SUN, current_pos, data->target_block, block, 4); } else { // Light already valid, propagation stopped. break; } } } else { // Propagate shadow. // For each node downwards: for (; current_pos.Y >= 0; current_pos.Y--) { MapNode n = block->getNodeNoCheck(current_pos, &is_valid); const ContentFeatures &f = ndef->get(n); if (n.getLightRaw(LIGHTBANK_DAY, f) == LIGHT_SUN) { // The sunlight is no longer valid. n.setLight(LIGHTBANK_DAY, 0, f); block->setNodeNoCheck(current_pos, n); modified = true; unlight->push(LIGHT_SUN, current_pos, data->target_block, block, 4); } else { // Reached shadow, propagation stopped. break; } } } if (current_pos.Y >= 0) { // Propagation stopped, remove from data. data->data[index] = data->data.back(); data->data.pop_back(); index--; } } return modified; } /*! * Borders of a map block in relative node coordinates. * The areas do not overlap. * Compatible with type 'direction'. */ const VoxelArea block_pad[] = { VoxelArea(v3s16(15, 0, 0), v3s16(15, 15, 15)), //X+ VoxelArea(v3s16(1, 15, 0), v3s16(14, 15, 15)), //Y+ VoxelArea(v3s16(1, 1, 15), v3s16(14, 14, 15)), //Z+ VoxelArea(v3s16(1, 1, 0), v3s16(14, 14, 0)), //Z- VoxelArea(v3s16(1, 0, 0), v3s16(14, 0, 15)), //Y- VoxelArea(v3s16(0, 0, 0), v3s16(0, 15, 15)) //X- }; /*! * 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. * * \param minblock least coordinates of the changed area in block * coordinates * \param maxblock greatest coordinates of the changed area in block * coordinates * \param 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. * \param 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. * \param modified_blocks the procedure adds all modified blocks to * this map */ 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) { const NodeDefManager *ndef = map->getNodeDefManager(); // dummy boolean bool is_valid; // --- STEP 1: Do unlighting for (size_t bank = 0; bank < 2; bank++) { LightBank b = banks[bank]; unspread_light(map, ndef, b, unlight[bank], relight[bank], *modified_blocks); } // --- STEP 2: Get all newly inserted light sources // For each block: v3s16 blockpos; v3s16 relpos; for (blockpos.X = minblock.X; blockpos.X <= maxblock.X; blockpos.X++) for (blockpos.Y = minblock.Y; blockpos.Y <= maxblock.Y; blockpos.Y++) for (blockpos.Z = minblock.Z; blockpos.Z <= maxblock.Z; blockpos.Z++) { MapBlock *block = map->getBlockNoCreateNoEx(blockpos); if (!block || block->isDummy()) // Skip not existing blocks continue; // For each node in the block: for (relpos.X = 0; relpos.X < MAP_BLOCKSIZE; relpos.X++) for (relpos.Z = 0; relpos.Z < MAP_BLOCKSIZE; relpos.Z++) for (relpos.Y = 0; relpos.Y < MAP_BLOCKSIZE; relpos.Y++) { MapNode node = block->getNodeNoCheck(relpos.X, relpos.Y, relpos.Z, &is_valid); const ContentFeatures &f = ndef->get(node); // For each light bank for (size_t b = 0; b < 2; b++) { LightBank bank = banks[b]; u8 light = f.param_type == CPT_LIGHT ? node.getLightNoChecks(bank, &f): f.light_source; if (light > 1) relight[b].push(light, relpos, blockpos, block, 6); } // end of banks } // end of nodes } // end of blocks