forked from oerkki/voxelands
clean out some cruft
This commit is contained in:
parent
9b47c8af4c
commit
0909bd9e47
19
src/map.cpp
19
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;
|
||||
}
|
||||
|
|
142
src/mapblock.cpp
142
src/mapblock.cpp
|
@ -217,21 +217,18 @@ bool MapBlock::propagateSunlight(core::map<v3s16, bool> & light_sources,
|
|||
|
||||
v3s16 pos_relative = getPosRelative();
|
||||
|
||||
for(s16 x=0; x<MAP_BLOCKSIZE; x++)
|
||||
{
|
||||
for(s16 z=0; z<MAP_BLOCKSIZE; z++)
|
||||
{
|
||||
#if 1
|
||||
for (s16 x=0; x<MAP_BLOCKSIZE; x++) {
|
||||
for (s16 z=0; z<MAP_BLOCKSIZE; z++) {
|
||||
bool no_sunlight = false;
|
||||
//bool no_top_block = false;
|
||||
// Check if node above block has sunlight
|
||||
bool is_valid_position;
|
||||
MapNode n = getNodeParent(v3s16(x, MAP_BLOCKSIZE, z), &is_valid_position);
|
||||
MapNode np = getNodeParent(v3s16(x, MAP_BLOCKSIZE, z), &is_valid_position);
|
||||
if (is_valid_position) {
|
||||
if (n.getContent() == CONTENT_IGNORE) {
|
||||
if (np.getContent() == CONTENT_IGNORE) {
|
||||
// Trust heuristics
|
||||
no_sunlight = is_underground;
|
||||
}else if (n.getLight(LIGHTBANK_DAY) != LIGHT_SUN) {
|
||||
}else if (np.getLight(LIGHTBANK_DAY) != LIGHT_SUN) {
|
||||
no_sunlight = true;
|
||||
}
|
||||
}else{
|
||||
|
@ -251,29 +248,6 @@ bool MapBlock::propagateSunlight(core::map<v3s16, bool> & 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<<"("<<x<<","<<z<<"): "
|
||||
<<"no_top_block="<<no_top_block
|
||||
<<", is_underground="<<is_underground
|
||||
<<", no_sunlight="<<no_sunlight
|
||||
<<std::endl;*/
|
||||
|
||||
s16 y = MAP_BLOCKSIZE-1;
|
||||
|
||||
|
@ -282,72 +256,34 @@ bool MapBlock::propagateSunlight(core::map<v3s16, bool> & light_sources,
|
|||
|
||||
u8 current_light = no_sunlight ? 0 : LIGHT_SUN;
|
||||
|
||||
for(; y >= 0; y--)
|
||||
{
|
||||
for (; y >= 0; y--) {
|
||||
v3s16 pos(x, y, z);
|
||||
MapNode &n = getNodeRef(pos);
|
||||
ContentFeatures &f = content_features(n);
|
||||
|
||||
if(current_light == 0)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
else if(current_light == LIGHT_SUN && n.sunlight_propagates())
|
||||
{
|
||||
// Do nothing: Sunlight is continued
|
||||
}
|
||||
else if(n.light_propagates() == false)
|
||||
{
|
||||
/*// DEPRECATED TODO: REMOVE
|
||||
if(grow_grass)
|
||||
{
|
||||
bool upper_is_air = false;
|
||||
try
|
||||
{
|
||||
if(getNodeParent(pos+v3s16(0,1,0)).getContent() == CONTENT_AIR)
|
||||
upper_is_air = true;
|
||||
}
|
||||
catch(InvalidPositionException &e)
|
||||
{
|
||||
}
|
||||
// Turn mud into grass
|
||||
if(upper_is_air && n.getContent() == CONTENT_MUD
|
||||
&& current_light == LIGHT_SUN)
|
||||
{
|
||||
n.d = CONTENT_GRASS;
|
||||
}
|
||||
}*/
|
||||
if (current_light != 0) {
|
||||
if ((current_light != LIGHT_SUN || !f.sunlight_propagates) && !f.light_propagates) {
|
||||
// A solid object is on the way.
|
||||
stopped_to_solid_object = true;
|
||||
|
||||
// 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);
|
||||
// Light stops.
|
||||
current_light = 0;
|
||||
}else{
|
||||
// Diminish light
|
||||
current_light = diminish_light(current_light);
|
||||
}
|
||||
}
|
||||
|
||||
u8 old_light = n.getLight(LIGHTBANK_DAY);
|
||||
|
||||
if(current_light > old_light || remove_light)
|
||||
{
|
||||
if (current_light > old_light || remove_light)
|
||||
n.setLight(LIGHTBANK_DAY, current_light);
|
||||
}
|
||||
|
||||
if(diminish_light(current_light) != 0)
|
||||
{
|
||||
if (diminish_light(current_light) != 0)
|
||||
light_sources.insert(pos_relative + pos, true);
|
||||
}
|
||||
|
||||
if(current_light == 0 && stopped_to_solid_object)
|
||||
{
|
||||
if(black_air_left)
|
||||
{
|
||||
*black_air_left = true;
|
||||
}
|
||||
}
|
||||
if (current_light == 0 && stopped_to_solid_object && black_air_left)
|
||||
*black_air_left = true;
|
||||
}
|
||||
|
||||
// Whether or not the block below should see LIGHT_SUN
|
||||
|
@ -361,26 +297,24 @@ bool MapBlock::propagateSunlight(core::map<v3s16, bool> & light_sources,
|
|||
|
||||
Ignore non-transparent nodes as they always have no light
|
||||
*/
|
||||
try
|
||||
{
|
||||
if(block_below_is_valid)
|
||||
{
|
||||
MapNode n = getNodeParent(v3s16(x, -1, z));
|
||||
if(n.light_propagates())
|
||||
{
|
||||
if(n.getLight(LIGHTBANK_DAY) == LIGHT_SUN
|
||||
&& sunlight_should_go_down == false)
|
||||
block_below_is_valid = false;
|
||||
else if(n.getLight(LIGHTBANK_DAY) != LIGHT_SUN
|
||||
&& sunlight_should_go_down == true)
|
||||
block_below_is_valid = false;
|
||||
try {
|
||||
if (block_below_is_valid) {
|
||||
MapNode n = getNodeParent(v3s16(x, -1, z));
|
||||
if (content_features(n).light_propagates) {
|
||||
if (
|
||||
n.getLight(LIGHTBANK_DAY) == LIGHT_SUN
|
||||
&& sunlight_should_go_down == false
|
||||
) {
|
||||
block_below_is_valid = false;
|
||||
}else if (
|
||||
n.getLight(LIGHTBANK_DAY) != LIGHT_SUN
|
||||
&& sunlight_should_go_down == true
|
||||
) {
|
||||
block_below_is_valid = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}//if
|
||||
}//try
|
||||
catch(InvalidPositionException &e)
|
||||
{
|
||||
/*std::cout<<"InvalidBlockException for bottom block node"
|
||||
<<std::endl;*/
|
||||
}catch(InvalidPositionException &e) {
|
||||
// Just no block below, no need to panic.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -848,40 +848,20 @@ struct MapNode
|
|||
envticks = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
These four are DEPRECATED I guess. -c55
|
||||
*/
|
||||
bool light_propagates()
|
||||
{
|
||||
return content_features(*this).light_propagates;
|
||||
}
|
||||
bool sunlight_propagates()
|
||||
{
|
||||
return content_features(*this).sunlight_propagates;
|
||||
}
|
||||
u8 solidness()
|
||||
{
|
||||
return content_features(*this).solidness;
|
||||
}
|
||||
u8 light_source()
|
||||
{
|
||||
return content_features(*this).light_source;
|
||||
}
|
||||
|
||||
u8 getLightBanksWithSource()
|
||||
{
|
||||
// Select the brightest of [light source, propagated light]
|
||||
u8 lightday = 0;
|
||||
u8 lightnight = 0;
|
||||
if(content_features(*this).param_type == CPT_LIGHT)
|
||||
{
|
||||
ContentFeatures &f = content_features(content);
|
||||
if (f.param_type == CPT_LIGHT) {
|
||||
lightday = param1 & 0x0f;
|
||||
lightnight = (param1>>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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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<v3s16, bool> & from_nodes)
|
||||
{
|
||||
if(from_nodes.size() == 0)
|
||||
if (from_nodes.size() == 0)
|
||||
return;
|
||||
|
||||
core::map<v3s16, bool> lighted_nodes;
|
||||
core::map<v3s16, bool>::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<v3s16, bool> lighted_nodes;
|
||||
core::map<v3s16, bool>::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 "<<from_nodes.size()<<" nodes"
|
||||
<<std::endl;*/
|
||||
|
||||
if(lighted_nodes.size() > 0)
|
||||
if (lighted_nodes.size() > 0)
|
||||
spreadLight(bank, lighted_nodes);
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue