本文整理汇总了C++中MapBlock::setLightingExpired方法的典型用法代码示例。如果您正苦于以下问题:C++ MapBlock::setLightingExpired方法的具体用法?C++ MapBlock::setLightingExpired怎么用?C++ MapBlock::setLightingExpired使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MapBlock
的用法示例。
在下文中一共展示了MapBlock::setLightingExpired方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: transformLiquidsReal
//.........这里部分代码省略.........
u16 ii = liquid_random_map[(loopcount + loop_rand + 5) % 4][ir];
if (neighbors[ii].liquid)
must_reflow_second.push_back(neighbors[i].pos + liquid_flow_dirs[ii]);
//must_reflow_second[neighbors[i].pos + liquid_flow_dirs[ii]] = 1;
}
}
#if LIQUID_DEBUG
if (liquid_levels_want[i] > 0)
flowed += liquid_levels_want[i];
#endif
if (liquid_levels[i] == liquid_levels_want[i]) {
continue;
}
if (neighbors[i].drop) {// && level_max > 1 && total_level >= level_max - 1
m_server->getEnv().getScriptIface()->node_drop(neighbors[i].pos, 2);
}
neighbors[i].node.setContent(liquid_kind_flowing);
neighbors[i].node.setLevel(nodemgr, liquid_levels_want[i], 1);
try {
setNode(neighbors[i].pos, neighbors[i].node);
} catch(InvalidPositionException &e) {
verbosestream << "transformLiquidsReal: setNode() failed:" << neighbors[i].pos << ":" << e.what() << std::endl;
}
// If node emits light, MapBlock requires lighting update
// or if node removed
v3POS blockpos = getNodeBlockPos(neighbors[i].pos);
MapBlock *block = getBlockNoCreateNoEx(blockpos, true); // remove true if light bugs
if(block) {
block->setLightingExpired(true);
//modified_blocks[blockpos] = block;
//if(!nodemgr->get(neighbors[i].node).light_propagates || nodemgr->get(neighbors[i].node).light_source) // better to update always
// lighting_modified_blocks.set_try(block->getPos(), block);
}
// fmtodo: make here random %2 or..
if (total_level < level_max * can_liquid)
must_reflow.push_back(neighbors[i].pos);
}
#if LIQUID_DEBUG
//if (total_was != flowed) {
if (total_was > flowed) {
infostream << " volume changed! flowed=" << flowed << " total_was=" << total_was << " want_level=" << want_level;
for (u16 rr = 0; rr <= 6; rr++) {
infostream << " i=" << rr << ",b" << (int)liquid_levels[rr] << ",a" << (int)liquid_levels_want[rr];
}
infostream << std::endl;
}
#endif
/* //for better relax only same level
if (changed) for (u16 ii = D_SELF + 1; ii < D_TOP; ++ii) {
if (!neighbors[ii].l) continue;
must_reflow.push_back(p0 + dirs[ii]);
}*/
//g_profiler->graphAdd("liquids", 1);
}
u32 ret = loopcount >= initial_size ? 0 : transforming_liquid_size();
if (ret || loopcount > m_liquid_step_flow)
m_liquid_step_flow += (m_liquid_step_flow > loopcount ? -1 : 1) * (int)loopcount / 10;
/*
示例2: updateLighting
u32 Map::updateLighting(concurrent_map<v3POS, MapBlock*> & a_blocks,
std::map<v3POS, MapBlock*> & modified_blocks, unsigned int max_cycle_ms) {
INodeDefManager *nodemgr = m_gamedef->ndef();
int ret = 0;
int loopcount = 0;
TimeTaker timer("updateLighting");
// For debugging
//bool debug=true;
//u32 count_was = modified_blocks.size();
//std::unordered_set<v3POS, v3POSHash, v3POSEqual> light_sources;
//std::unordered_map<v3POS, u8, v3POSHash, v3POSEqual> unlight_from_day, unlight_from_night;
std::set<v3POS> light_sources;
std::map<v3POS, u8> unlight_from_day, unlight_from_night;
unordered_map_v3POS<int> processed;
int num_bottom_invalid = 0;
//MutexAutoLock lock2(m_update_lighting_mutex);
#if !ENABLE_THREADS
auto lock = m_nothread_locker.lock_unique_rec();
#endif
{
//TimeTaker t("updateLighting: first stuff");
u32 end_ms = porting::getTimeMs() + max_cycle_ms;
for(auto i = a_blocks.begin();
i != a_blocks.end(); ++i) {
auto block = getBlockNoCreateNoEx(i->first);
for(;;) {
// Don't bother with dummy blocks.
if(!block || block->isDummy())
break;
auto lock = block->try_lock_unique_rec();
if (!lock->owns_lock())
break; // may cause dark areas
v3POS pos = block->getPos();
if (processed.count(pos) && processed[pos] <= i->first.Y ) {
break;
}
++loopcount;
processed[pos] = i->first.Y;
v3POS posnodes = block->getPosRelative();
//modified_blocks[pos] = block;
block->setLightingExpired(true);
block->lighting_broken = true;
/*
Clear all light from block
*/
for(s16 z = 0; z < MAP_BLOCKSIZE; z++)
for(s16 x = 0; x < MAP_BLOCKSIZE; x++)
for(s16 y = 0; y < MAP_BLOCKSIZE; y++) {
v3POS p(x, y, z);
bool is_valid_position;
MapNode n = block->getNode(p, &is_valid_position);
if (!is_valid_position) {
/* This would happen when dealing with a
dummy block.
*/
infostream << "updateLighting(): InvalidPositionException"
<< std::endl;
continue;
}
u8 oldlight_day = n.getLight(LIGHTBANK_DAY, nodemgr);
u8 oldlight_night = n.getLight(LIGHTBANK_NIGHT, nodemgr);
n.setLight(LIGHTBANK_DAY, 0, nodemgr);
n.setLight(LIGHTBANK_NIGHT, 0, nodemgr);
block->setNode(p, n);
// If node sources light, add to list
//u8 source = nodemgr->get(n).light_source;
if(nodemgr->get(n).light_source)
light_sources.insert(p + posnodes);
v3POS p_map = p + posnodes;
// Collect borders for unlighting
if(x == 0 || x == MAP_BLOCKSIZE - 1
|| y == 0 || y == MAP_BLOCKSIZE - 1
|| z == 0 || z == MAP_BLOCKSIZE - 1) {
if(oldlight_day)
unlight_from_day[p_map] = oldlight_day;
if(oldlight_night)
unlight_from_night[p_map] = oldlight_night;
}
}
lock->unlock();
//.........这里部分代码省略.........