本文整理汇总了C++中MapBlock::getIsUnderground方法的典型用法代码示例。如果您正苦于以下问题:C++ MapBlock::getIsUnderground方法的具体用法?C++ MapBlock::getIsUnderground怎么用?C++ MapBlock::getIsUnderground使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MapBlock
的用法示例。
在下文中一共展示了MapBlock::getIsUnderground方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: propagateSunlight
bool Map::propagateSunlight(v3POS pos, std::set<v3POS> & light_sources,
bool remove_light) {
MapBlock *block = getBlockNoCreateNoEx(pos);
INodeDefManager *nodemgr = m_gamedef->ndef();
// Whether the sunlight at the top of the bottom block is valid
bool block_below_is_valid = true;
v3POS pos_relative = block->getPosRelative();
for(s16 x = 0; x < MAP_BLOCKSIZE; ++x) {
for(s16 z = 0; z < MAP_BLOCKSIZE; ++z) {
bool no_sunlight = false;
// Check if node above block has sunlight
MapNode n = getNode(pos_relative + v3POS(x, MAP_BLOCKSIZE, z));
if (n) {
if(n.getLight(LIGHTBANK_DAY, m_gamedef->ndef()) != LIGHT_SUN) {
no_sunlight = true;
}
} else {
// NOTE: This makes over-ground roofed places sunlighted
// Assume sunlight, unless is_underground==true
if(block->getIsUnderground()) {
no_sunlight = true;
} else {
MapNode n = block->getNode(v3POS(x, MAP_BLOCKSIZE - 1, z));
if(n && m_gamedef->ndef()->get(n).sunlight_propagates == false)
no_sunlight = true;
}
// NOTE: As of now, this just would make everything dark.
// No sunlight here
//no_sunlight = true;
}
s16 y = MAP_BLOCKSIZE - 1;
// This makes difference to diminishing in water.
//bool stopped_to_solid_object = false;
u8 current_light = no_sunlight ? 0 : LIGHT_SUN;
for(; y >= 0; --y) {
v3POS pos(x, y, z);
MapNode n = block->getNode(pos);
if(current_light == 0) {
// Do nothing
} else if(current_light == LIGHT_SUN && nodemgr->get(n).sunlight_propagates) {
// Do nothing: Sunlight is continued
} else if(nodemgr->get(n).light_propagates == false) {
// A solid object is on the way.
//stopped_to_solid_object = true;
// Light stops.
current_light = 0;
} else {
// Diminish light
current_light = diminish_light(current_light);
}
u8 old_light = n.getLight(LIGHTBANK_DAY, nodemgr);
if(current_light > old_light || remove_light) {
n.setLight(LIGHTBANK_DAY, current_light, nodemgr);
block->setNode(pos, n);
}
if(diminish_light(current_light) != 0) {
light_sources.insert(pos_relative + pos);
}
}
// Whether or not the block below should see LIGHT_SUN
bool sunlight_should_go_down = (current_light == LIGHT_SUN);
/*
If the block below hasn't already been marked invalid:
Check if the node below the block has proper sunlight at top.
If not, the block below is invalid.
Ignore non-transparent nodes as they always have no light
*/
if(block_below_is_valid) {
MapNode n = getNode(pos_relative + v3POS(x, -1, z));
if (n) {
if(nodemgr->get(n).light_propagates) {
if(n.getLight(LIGHTBANK_DAY, nodemgr) == LIGHT_SUN
&& sunlight_should_go_down == false)
block_below_is_valid = false;
else if(n.getLight(LIGHTBANK_DAY, nodemgr) != LIGHT_SUN
&& sunlight_should_go_down == true)
block_below_is_valid = false;
}
//.........这里部分代码省略.........