diff --git a/src/map.cpp b/src/map.cpp index 5bed3de..77d1b16 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -340,7 +340,7 @@ void Map::unspreadLight(enum LightBank bank, /* And the neighbor is transparent and it has some light */ - if (n2.light_propagates() && n2.getLight(bank) != 0) { + if (content_features(n2).light_propagates && n2.getLight(bank) != 0) { /* Set light to 0 and add to queue */ @@ -516,7 +516,7 @@ void Map::spreadLight(enum LightBank bank, would spread on it, add to list */ if (n2.getLight(bank) < newlight) { - if (n2.light_propagates()) { + if (content_features(n2).light_propagates) { n2.setLight(bank, newlight); block->setNode(relpos, n2); lighted_nodes.insert(n2pos, true); @@ -621,15 +621,14 @@ s16 Map::propagateSunlight(v3s16 start, if (!is_valid_position) continue; - if (n.sunlight_propagates()) { - n.setLight(LIGHTBANK_DAY, LIGHT_SUN); - block->setNode(relpos, n); - - modified_blocks.insert(blockpos, block); - }else{ - // Sunlight goes no further + // Sunlight goes no further + if (!content_features(n).sunlight_propagates) break; - } + + n.setLight(LIGHTBANK_DAY, LIGHT_SUN); + block->setNode(relpos, n); + + modified_blocks.insert(blockpos, block); } return y + 1; } diff --git a/src/mapblock.cpp b/src/mapblock.cpp index 3cec362..36aed2e 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -217,21 +217,18 @@ bool MapBlock::propagateSunlight(core::map & light_sources, v3s16 pos_relative = getPosRelative(); - for(s16 x=0; x & light_sources, // No sunlight here //no_sunlight = true; } -#endif -#if 0 // Doesn't work; nothing gets light. - bool no_sunlight = true; - bool no_top_block = false; - // Check if node above block has sunlight - try{ - MapNode n = getNodeParent(v3s16(x, MAP_BLOCKSIZE, z)); - if(n.getLight(LIGHTBANK_DAY) == LIGHT_SUN) - { - no_sunlight = false; - } - } - catch(InvalidPositionException &e) - { - no_top_block = true; - } -#endif - - /*std::cout<<"("<>4)&0x0f; } - if(light_source() > lightday) - lightday = light_source(); - if(light_source() > lightnight) - lightnight = light_source(); + if (f.light_source > lightday) + lightday = f.light_source; + if (f.light_source > lightnight) + lightnight = f.light_source; return (lightday&0x0f) | ((lightnight<<4)&0xf0); } @@ -889,17 +869,16 @@ struct MapNode { // Select the brightest of [light source, propagated light] u8 light = 0; - if(content_features(*this).param_type == CPT_LIGHT) - { - if(bank == LIGHTBANK_DAY) + ContentFeatures &f = content_features(content); + if (f.param_type == CPT_LIGHT) { + if (bank == LIGHTBANK_DAY) { light = param1 & 0x0f; - else if(bank == LIGHTBANK_NIGHT) + }else if (bank == LIGHTBANK_NIGHT) { light = (param1>>4)&0x0f; - else - assert(0); + } } - if(light_source() > light) - light = light_source(); + if (f.light_source > light) + light = f.light_source; return light; } @@ -917,35 +896,19 @@ struct MapNode l = max; return l; } - /*// 0 <= daylight_factor <= 1000 - // 0 <= return value <= 255 - u8 getLightBlend(u32 daylight_factor) - { - u8 daylight = decode_light(getLight(LIGHTBANK_DAY)); - u8 nightlight = decode_light(getLight(LIGHTBANK_NIGHT)); - u8 mix = ((daylight_factor * daylight - + (1000-daylight_factor) * nightlight) - )/1000; - return mix; - }*/ void setLight(enum LightBank bank, u8 a_light) { // If node doesn't contain light data, ignore this - if(content_features(*this).param_type != CPT_LIGHT) + if (content_features(content).param_type != CPT_LIGHT) return; - if(bank == LIGHTBANK_DAY) - { + if (bank == LIGHTBANK_DAY) { param1 &= 0xf0; param1 |= a_light & 0x0f; - } - else if(bank == LIGHTBANK_NIGHT) - { + }else if(bank == LIGHTBANK_NIGHT) { param1 &= 0x0f; param1 |= (a_light & 0x0f)<<4; } - else - assert(0); } v3s16 getRotation(v3s16 dir = v3s16(1,1,1)); s16 getRotationAngle(); diff --git a/src/test.cpp b/src/test.cpp index fb60a72..937e597 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -233,9 +233,9 @@ struct TestMapNode // Transparency n.setContent(CONTENT_AIR); - assert(n.light_propagates() == true); + assert(content_features(n).light_propagates == true); n.setContent(CONTENT_STONE); - assert(n.light_propagates() == false); + assert(content_features(n).light_propagates == false); } }; diff --git a/src/voxel.cpp b/src/voxel.cpp index d7b89ac..ea30b70 100644 --- a/src/voxel.cpp +++ b/src/voxel.cpp @@ -318,14 +318,13 @@ void VoxelManipulator::unspreadLight(enum LightBank bank, v3s16 p, u8 oldlight, emerge(VoxelArea(p - v3s16(1,1,1), p + v3s16(1,1,1))); // Loop through 6 neighbors - for(u16 i=0; i<6; i++) - { + for (u16 i=0; i<6; i++) { // Get the position of the neighbor node v3s16 n2pos = p + dirs[i]; u32 n2i = m_area.index(n2pos); - if(m_flags[n2i] & VOXELFLAG_INEXISTENT) + if (m_flags[n2i] & VOXELFLAG_INEXISTENT) continue; MapNode &n2 = m_data[n2i]; @@ -335,13 +334,11 @@ void VoxelManipulator::unspreadLight(enum LightBank bank, v3s16 p, u8 oldlight, as oldlight (the light of the previous node) */ u8 light2 = n2.getLight(bank); - if(light2 < oldlight) - { + if (light2 < oldlight) { /* And the neighbor is transparent and it has some light */ - if(n2.light_propagates() && light2 != 0) - { + if (content_features(n2).light_propagates && light2 != 0) { /* Set light to 0 and add to queue */ @@ -360,8 +357,7 @@ void VoxelManipulator::unspreadLight(enum LightBank bank, v3s16 p, u8 oldlight, light_sources.remove(n2pos); }*/ } - } - else{ + }else{ light_sources.insert(n2pos, true); } } @@ -531,7 +527,7 @@ void VoxelManipulator::spreadLight(enum LightBank bank, v3s16 p) u32 i = m_area.index(p); - if(m_flags[i] & VOXELFLAG_INEXISTENT) + if (m_flags[i] & VOXELFLAG_INEXISTENT) return; MapNode &n = m_data[i]; @@ -540,14 +536,13 @@ void VoxelManipulator::spreadLight(enum LightBank bank, v3s16 p) u8 newlight = diminish_light(oldlight); // Loop through 6 neighbors - for(u16 i=0; i<6; i++) - { + for (u16 i=0; i<6; i++) { // Get the position of the neighbor node v3s16 n2pos = p + dirs[i]; u32 n2i = m_area.index(n2pos); - if(m_flags[n2i] & VOXELFLAG_INEXISTENT) + if (m_flags[n2i] & VOXELFLAG_INEXISTENT) continue; MapNode &n2 = m_data[n2i]; @@ -557,21 +552,15 @@ void VoxelManipulator::spreadLight(enum LightBank bank, v3s16 p) If the neighbor is brighter than the current node, add to list (it will light up this node on its turn) */ - if(light2 > undiminish_light(oldlight)) - { + if (light2 > undiminish_light(oldlight)) spreadLight(bank, n2pos); - } /* If the neighbor is dimmer than how much light this node would spread on it, add to list */ - if(light2 < newlight) - { - if(n2.light_propagates()) - { - n2.setLight(bank, newlight); - spreadLight(bank, n2pos); - } + if (light2 < newlight && content_features(n2).light_propagates) { + n2.setLight(bank, newlight); + spreadLight(bank, n2pos); } } } @@ -587,17 +576,15 @@ void VoxelManipulator::spreadLight(enum LightBank bank, v3s16 p) void VoxelManipulator::spreadLight(enum LightBank bank, core::map & from_nodes) { - if(from_nodes.size() == 0) + if (from_nodes.size() == 0) return; core::map lighted_nodes; core::map::Iterator j; j = from_nodes.getIterator(); - for(; j.atEnd() == false; j++) - { + for (; j.atEnd() == false; j++) { v3s16 pos = j.getNode()->getKey(); - spreadLight(bank, pos); } } @@ -620,22 +607,21 @@ void VoxelManipulator::spreadLight(enum LightBank bank, v3s16(-1,0,0), // left }; - if(from_nodes.size() == 0) + if (from_nodes.size() == 0) return; core::map lighted_nodes; core::map::Iterator j; j = from_nodes.getIterator(); - for(; j.atEnd() == false; j++) - { + for (; j.atEnd() == false; j++) { v3s16 pos = j.getNode()->getKey(); emerge(VoxelArea(pos - v3s16(1,1,1), pos + v3s16(1,1,1))); u32 i = m_area.index(pos); - if(m_flags[i] & VOXELFLAG_INEXISTENT) + if (m_flags[i] & VOXELFLAG_INEXISTENT) continue; MapNode &n = m_data[i]; @@ -644,16 +630,14 @@ void VoxelManipulator::spreadLight(enum LightBank bank, u8 newlight = diminish_light(oldlight); // Loop through 6 neighbors - for(u16 i=0; i<6; i++) - { + for (u16 i=0; i<6; i++) { // Get the position of the neighbor node v3s16 n2pos = pos + dirs[i]; - try - { + try{ u32 n2i = m_area.index(n2pos); - if(m_flags[n2i] & VOXELFLAG_INEXISTENT) + if (m_flags[n2i] & VOXELFLAG_INEXISTENT) continue; MapNode &n2 = m_data[n2i]; @@ -663,25 +647,17 @@ void VoxelManipulator::spreadLight(enum LightBank bank, If the neighbor is brighter than the current node, add to list (it will light up this node on its turn) */ - if(light2 > undiminish_light(oldlight)) - { + if (light2 > undiminish_light(oldlight)) lighted_nodes.insert(n2pos, true); - } /* If the neighbor is dimmer than how much light this node would spread on it, add to list */ - if(light2 < newlight) - { - if(n2.light_propagates()) - { - n2.setLight(bank, newlight); - lighted_nodes.insert(n2pos, true); - } + if (light2 < newlight && content_features(n2).light_propagates) { + n2.setLight(bank, newlight); + lighted_nodes.insert(n2pos, true); } - } - catch(InvalidPositionException &e) - { + }catch(InvalidPositionException &e) { continue; } } @@ -692,7 +668,7 @@ void VoxelManipulator::spreadLight(enum LightBank bank, <<" for "< 0) + if (lighted_nodes.size() > 0) spreadLight(bank, lighted_nodes); } #endif