some map speedups

This commit is contained in:
darkrose 2014-11-13 05:00:14 +10:00
parent 283bb004b2
commit a5ecddd983
7 changed files with 415 additions and 657 deletions

View File

@ -236,58 +236,54 @@ collisionMoveResult collisionMoveSimple(Map *map,
for(s16 z = min_z; z <= max_z; z++)
{
v3s16 p(x,y,z);
try{
// Object collides into walkable nodes
MapNode n = map->getNode(p);
const ContentFeatures &f = content_features(n);
if(f.walkable == false)
continue;
bool pos_ok;
// Object collides into walkable nodes
MapNode n = map->getNodeNoEx(p,&pos_ok);
if (!pos_ok) {
// Collide with unloaded nodes
aabb3f box = getNodeBox(p, BS);
cboxes.push_back(box);
is_unloaded.push_back(true);
is_step_up.push_back(false);
node_positions.push_back(p);
is_object.push_back(false);
continue;
}
const ContentFeatures &f = content_features(n);
if(f.walkable == false)
continue;
std::vector<aabb3f> nodeboxes = f.getNodeBoxes(n);
std::vector<aabb3f> nodeboxes = f.getNodeBoxes(n);
#ifndef SERVER
if (f.draw_type == CDT_FENCELIKE || f.draw_type == CDT_WALLLIKE) {
static const int boxcheck[4][2] = {
{0,2},
{0,3},
{1,2},
{1,3}
};
int bps = ((nodeboxes.size()-2)/4); // boxes per section
u8 np = 1;
{
aabb3f box = nodeboxes[0];
box.MinEdge += v3f(x, y, z)*BS;
if (f.jumpable == false)
box.MaxEdge.Y = 1.0*BS;
box.MaxEdge += v3f(x, y, z)*BS;
cboxes.push_back(box);
is_unloaded.push_back(false);
is_step_up.push_back(false);
node_positions.push_back(p);
is_object.push_back(false);
}
for (int k=0; k<8; k++) {
if ((n.param2&(np<<k)) == 0)
continue;
if (k > 3) {
for (int j=0; j<2; j++) {
for (int i=0; i<bps; i++) {
aabb3f box = nodeboxes[i+2+(bps*boxcheck[k%4][j])];
box.MinEdge += v3f(x, y, z)*BS;
if (f.jumpable == false)
box.MaxEdge.Y = 1.0*BS;
box.MaxEdge += v3f(x, y, z)*BS;
cboxes.push_back(box);
is_unloaded.push_back(false);
is_step_up.push_back(false);
node_positions.push_back(p);
is_object.push_back(false);
}
}
}else{
if (f.draw_type == CDT_FENCELIKE || f.draw_type == CDT_WALLLIKE) {
static const int boxcheck[4][2] = {
{0,2},
{0,3},
{1,2},
{1,3}
};
int bps = ((nodeboxes.size()-2)/4); // boxes per section
u8 np = 1;
{
aabb3f box = nodeboxes[0];
box.MinEdge += v3f(x, y, z)*BS;
if (f.jumpable == false)
box.MaxEdge.Y = 1.0*BS;
box.MaxEdge += v3f(x, y, z)*BS;
cboxes.push_back(box);
is_unloaded.push_back(false);
is_step_up.push_back(false);
node_positions.push_back(p);
is_object.push_back(false);
}
for (int k=0; k<8; k++) {
if ((n.param2&(np<<k)) == 0)
continue;
if (k > 3) {
for (int j=0; j<2; j++) {
for (int i=0; i<bps; i++) {
aabb3f box = nodeboxes[i+2+(bps*(k%4))];
aabb3f box = nodeboxes[i+2+(bps*boxcheck[k%4][j])];
box.MinEdge += v3f(x, y, z)*BS;
if (f.jumpable == false)
box.MaxEdge.Y = 1.0*BS;
@ -299,38 +295,41 @@ collisionMoveResult collisionMoveSimple(Map *map,
is_object.push_back(false);
}
}
}else{
for (int i=0; i<bps; i++) {
aabb3f box = nodeboxes[i+2+(bps*(k%4))];
box.MinEdge += v3f(x, y, z)*BS;
if (f.jumpable == false)
box.MaxEdge.Y = 1.0*BS;
box.MaxEdge += v3f(x, y, z)*BS;
cboxes.push_back(box);
is_unloaded.push_back(false);
is_step_up.push_back(false);
node_positions.push_back(p);
is_object.push_back(false);
}
}
nodeboxes.clear();
}else
#endif
{
for(std::vector<aabb3f>::iterator
i = nodeboxes.begin();
i != nodeboxes.end(); i++)
{
aabb3f box = *i;
box.MinEdge += v3f(x, y, z)*BS;
if (f.jumpable == false)
box.MaxEdge.Y = 1.0*BS;
box.MaxEdge += v3f(x, y, z)*BS;
cboxes.push_back(box);
is_unloaded.push_back(false);
is_step_up.push_back(false);
node_positions.push_back(p);
is_object.push_back(false);
}
nodeboxes.clear();
}
}
catch(InvalidPositionException &e)
nodeboxes.clear();
}else
#endif
{
// Collide with unloaded nodes
aabb3f box = getNodeBox(p, BS);
cboxes.push_back(box);
is_unloaded.push_back(true);
is_step_up.push_back(false);
node_positions.push_back(p);
is_object.push_back(false);
for(std::vector<aabb3f>::iterator
i = nodeboxes.begin();
i != nodeboxes.end(); i++)
{
aabb3f box = *i;
box.MinEdge += v3f(x, y, z)*BS;
if (f.jumpable == false)
box.MaxEdge.Y = 1.0*BS;
box.MaxEdge += v3f(x, y, z)*BS;
cboxes.push_back(box);
is_unloaded.push_back(false);
is_step_up.push_back(false);
node_positions.push_back(p);
is_object.push_back(false);
}
nodeboxes.clear();
}
}
} // tt2

View File

@ -672,7 +672,8 @@ bool ServerEnvironment::searchNear(v3s16 pos, v3s16 radius_min, v3s16 radius_max
MapNode n_test;
bp = getNodeBlockPos(p);
if (bp == blockpos) {
n_test = block->getNodeNoCheck(p-relpos);
bool pos_ok;
n_test = block->getNodeNoCheck(p-relpos,&pos_ok);
}else{
n_test = m_map->getNodeNoEx(p);
}
@ -707,7 +708,8 @@ bool ServerEnvironment::searchNearInv(v3s16 pos, v3s16 radius_min, v3s16 radius_
MapNode n_test;
bp = getNodeBlockPos(p);
if (bp == blockpos) {
n_test = block->getNodeNoCheck(p-relpos);
bool pos_ok;
n_test = block->getNodeNoCheck(p-relpos,&pos_ok);
}else{
n_test = m_map->getNodeNoEx(p);
}
@ -775,24 +777,22 @@ void ServerEnvironment::step(float dtime)
if (footprints) {
// Get node that is at BS/4 under player
v3s16 bottompos = floatToInt(playerpos + v3f(0,-BS/4,0), BS);
try{
MapNode n = m_map->getNode(bottompos);
if (n.getContent() == CONTENT_GRASS) {
n.setContent(CONTENT_GRASS_FOOTSTEPS);
m_map->setNode(bottompos, n);
}else{
bottompos.Y += 1;
MapNode n = m_map->getNode(bottompos);
if (
n.getContent() == CONTENT_CIRCUIT_PRESSUREPLATE_STONE
|| n.getContent() == CONTENT_CIRCUIT_PRESSUREPLATE_WOOD
) {
NodeMetadata *meta = m_map->getNodeMetadata(bottompos);
if (meta && !meta->getEnergy())
meta->energise(ENERGY_MAX,bottompos,bottompos,bottompos);
}
MapNode n = m_map->getNodeNoEx(bottompos);
if (n.getContent() == CONTENT_GRASS) {
n.setContent(CONTENT_GRASS_FOOTSTEPS);
m_map->setNode(bottompos, n);
}else{
bottompos.Y += 1;
MapNode n = m_map->getNodeNoEx(bottompos);
if (
n.getContent() == CONTENT_CIRCUIT_PRESSUREPLATE_STONE
|| n.getContent() == CONTENT_CIRCUIT_PRESSUREPLATE_WOOD
) {
NodeMetadata *meta = m_map->getNodeMetadata(bottompos);
if (meta && !meta->getEnergy())
meta->energise(ENERGY_MAX,bottompos,bottompos,bottompos);
}
}catch (InvalidPositionException &e) {}
}
}
/*
Get player block positions
@ -3832,12 +3832,14 @@ void ClientEnvironment::step(float dtime)
// Update lighting on all players on client
u8 light = LIGHT_MAX;
try{
{
// Get node at head
bool pos_ok;
v3s16 p = player->getLightPosition();
MapNode n = m_map->getNode(p);
light = n.getLightBlend(getDayNightRatio());
}catch(InvalidPositionException &e) {}
MapNode n = m_map->getNodeNoEx(p,&pos_ok);
if (pos_ok)
light = n.getLightBlend(getDayNightRatio());
}
player->updateLight(light);
/*
@ -3846,20 +3848,18 @@ void ClientEnvironment::step(float dtime)
if (footprints) {
// Get node that is at BS/4 under player
v3s16 bottompos = floatToInt(playerpos + v3f(0,-BS/4,0), BS);
try{
MapNode n = m_map->getNode(bottompos);
if (n.getContent() == CONTENT_GRASS) {
n.setContent(CONTENT_GRASS_FOOTSTEPS);
m_map->setNode(bottompos, n);
// Update mesh on client
if (m_map->mapType() == MAPTYPE_CLIENT) {
v3s16 p_blocks = getNodeBlockPos(bottompos);
MapBlock *b = m_map->getBlockNoCreate(p_blocks);
//b->updateMesh(getDayNightRatio());
b->setMeshExpired(true);
}
MapNode n = m_map->getNodeNoEx(bottompos);
if (n.getContent() == CONTENT_GRASS) {
n.setContent(CONTENT_GRASS_FOOTSTEPS);
m_map->setNode(bottompos, n);
// Update mesh on client
if (m_map->mapType() == MAPTYPE_CLIENT) {
v3s16 p_blocks = getNodeBlockPos(bottompos);
MapBlock *b = m_map->getBlockNoCreate(p_blocks);
//b->updateMesh(getDayNightRatio());
b->setMeshExpired(true);
}
}catch(InvalidPositionException &e) {}
}
}
}
@ -3873,14 +3873,12 @@ void ClientEnvironment::step(float dtime)
obj->step(dtime, this);
if (m_active_object_light_update_interval.step(dtime, 0.21)) {
// Update lighting
u8 light = 0;
try{
// Get node at head
v3s16 p = obj->getLightPosition();
MapNode n = m_map->getNode(p);
bool pos_ok;
v3s16 p = obj->getLightPosition();
MapNode n = m_map->getNodeNoEx(p,&pos_ok);
if (pos_ok)
light = n.getLightBlend(getDayNightRatio());
}catch(InvalidPositionException &e) {}
obj->updateLight(light);
}
}
@ -3960,13 +3958,11 @@ u16 ClientEnvironment::addActiveObject(ClientActiveObject *object)
object->addToScene(m_smgr);
{ // Update lighting immediately
u8 light = 0;
try{
// Get node at head
v3s16 p = object->getLightPosition();
MapNode n = m_map->getNode(p);
bool pos_ok;
v3s16 p = object->getLightPosition();
MapNode n = m_map->getNodeNoEx(p,&pos_ok);
if (pos_ok)
light = n.getLightBlend(getDayNightRatio());
}
catch(InvalidPositionException &e) {}
object->updateLight(light);
}
return object->getId();
@ -4233,7 +4229,8 @@ bool ClientEnvironment::searchNear(v3s16 pos, v3s16 radius_min, v3s16 radius_max
MapNode n_test;
bp = getNodeBlockPos(p);
if (bp == blockpos) {
n_test = block->getNodeNoCheck(p-relpos);
bool pos_ok;
n_test = block->getNodeNoCheck(p-relpos,&pos_ok);
}else{
n_test = m_map->getNodeNoEx(p);
}
@ -4268,7 +4265,8 @@ bool ClientEnvironment::searchNearInv(v3s16 pos, v3s16 radius_min, v3s16 radius_
MapNode n_test;
bp = getNodeBlockPos(p);
if (bp == blockpos) {
n_test = block->getNodeNoCheck(p-relpos);
bool pos_ok;
n_test = block->getNodeNoCheck(p-relpos,&pos_ok);
}else{
n_test = m_map->getNodeNoEx(p);
}

View File

@ -178,14 +178,21 @@ bool Map::isValidPosition(v3s16 p)
}
// Returns a CONTENT_IGNORE node if not found
MapNode Map::getNodeNoEx(v3s16 p)
MapNode Map::getNodeNoEx(v3s16 p, bool *is_valid_position)
{
v3s16 blockpos = getNodeBlockPos(p);
MapBlock *block = getBlockNoCreateNoEx(blockpos);
if(block == NULL)
if (block == NULL) {
if (is_valid_position)
*is_valid_position = false;
return MapNode(CONTENT_IGNORE);
}
v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
return block->getNodeNoCheck(relpos);
bool is_valid_p;
MapNode node = block->getNodeNoCheck(relpos, &is_valid_p);
if (is_valid_position != NULL)
*is_valid_position = is_valid_p;
return node;
}
// throws InvalidPositionException if not found
@ -193,10 +200,14 @@ MapNode Map::getNode(v3s16 p)
{
v3s16 blockpos = getNodeBlockPos(p);
MapBlock *block = getBlockNoCreateNoEx(blockpos);
if(block == NULL)
if (block == NULL)
throw InvalidPositionException();
v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
return block->getNodeNoCheck(relpos);
bool is_valid_position;
MapNode node = block->getNodeNoCheck(relpos, &is_valid_position);
if (!is_valid_position)
throw InvalidPositionException();
return node;
}
// throws InvalidPositionException if not found
@ -277,108 +288,92 @@ void Map::unspreadLight(enum LightBank bank,
continue;
}
if(block->isDummy())
if (block->isDummy())
continue;
// Calculate relative position in block
v3s16 relpos = pos - blockpos_last * MAP_BLOCKSIZE;
// Get node straight from the block
MapNode n = block->getNode(relpos);
u8 oldlight = j.getNode()->getValue();
// 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];
// Get the block where the node is located
v3s16 blockpos = getNodeBlockPos(n2pos);
try
{
// Only fetch a new block if the block position has changed
try{
if(block == NULL || blockpos != blockpos_last){
block = getBlockNoCreate(blockpos);
blockpos_last = blockpos;
// Only fetch a new block if the block position has changed
try{
if (block == NULL || blockpos != blockpos_last) {
block = getBlockNoCreate(blockpos);
blockpos_last = blockpos;
block_checked_in_modified = false;
blockchangecount++;
}
block_checked_in_modified = false;
blockchangecount++;
}
catch(InvalidPositionException &e)
{
continue;
}
// Calculate relative position in block
v3s16 relpos = n2pos - blockpos * MAP_BLOCKSIZE;
// Get node straight from the block
MapNode n2 = block->getNode(relpos);
bool changed = false;
//TODO: Optimize output by optimizing light_sources?
/*
If the neighbor is dimmer than what was specified
as oldlight (the light of the previous node)
*/
if(n2.getLight(bank) < oldlight)
{
/*
And the neighbor is transparent and it has some light
*/
if(n2.light_propagates() && n2.getLight(bank) != 0)
{
/*
Set light to 0 and add to queue
*/
u8 current_light = n2.getLight(bank);
n2.setLight(bank, 0);
block->setNode(relpos, n2);
unlighted_nodes.insert(n2pos, current_light);
changed = true;
/*
Remove from light_sources if it is there
NOTE: This doesn't happen nearly at all
*/
/*if(light_sources.find(n2pos))
{
infostream<<"Removed from light_sources"<<std::endl;
light_sources.remove(n2pos);
}*/
}
/*// DEBUG
if(light_sources.find(n2pos) != NULL)
light_sources.remove(n2pos);*/
}
else{
light_sources.insert(n2pos, true);
}
// Add to modified_blocks
if(changed == true && block_checked_in_modified == false)
{
// If the block is not found in modified_blocks, add.
if(modified_blocks.find(blockpos) == NULL)
{
modified_blocks.insert(blockpos, block);
}
block_checked_in_modified = true;
}
}
catch(InvalidPositionException &e)
{
}catch(InvalidPositionException &e) {
continue;
}
// Calculate relative position in block
v3s16 relpos = n2pos - blockpos * MAP_BLOCKSIZE;
// Get node straight from the block
bool is_valid_position;
MapNode n2 = block->getNode(relpos, &is_valid_position);
if (!is_valid_position)
continue;
bool changed = false;
//TODO: Optimize output by optimizing light_sources?
/*
If the neighbor is dimmer than what was specified
as oldlight (the light of the previous node)
*/
if (n2.getLight(bank) < oldlight) {
/*
And the neighbor is transparent and it has some light
*/
if (n2.light_propagates() && n2.getLight(bank) != 0) {
/*
Set light to 0 and add to queue
*/
u8 current_light = n2.getLight(bank);
n2.setLight(bank, 0);
block->setNode(relpos, n2);
unlighted_nodes.insert(n2pos, current_light);
changed = true;
/*
Remove from light_sources if it is there
NOTE: This doesn't happen nearly at all
*/
/*if(light_sources.find(n2pos))
{
infostream<<"Removed from light_sources"<<std::endl;
light_sources.remove(n2pos);
}*/
}
/*// DEBUG
if(light_sources.find(n2pos) != NULL)
light_sources.remove(n2pos);*/
}else{
light_sources.insert(n2pos, true);
}
// Add to modified_blocks
if (changed == true && block_checked_in_modified == false) {
// If the block is not found in modified_blocks, add.
if (modified_blocks.find(blockpos) == NULL)
modified_blocks.insert(blockpos, block);
block_checked_in_modified = true;
}
}
}
@ -469,82 +464,70 @@ void Map::spreadLight(enum LightBank bank,
v3s16 relpos = pos - blockpos_last * MAP_BLOCKSIZE;
// Get node straight from the block
MapNode n = block->getNode(relpos);
bool is_valid_position;
MapNode n = block->getNode(relpos, &is_valid_position);
u8 oldlight = n.getLight(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];
// Get the block where the node is located
v3s16 blockpos = getNodeBlockPos(n2pos);
try
{
// Only fetch a new block if the block position has changed
try{
if(block == NULL || blockpos != blockpos_last){
block = getBlockNoCreate(blockpos);
blockpos_last = blockpos;
// Only fetch a new block if the block position has changed
try{
if (block == NULL || blockpos != blockpos_last) {
block = getBlockNoCreate(blockpos);
blockpos_last = blockpos;
block_checked_in_modified = false;
blockchangecount++;
}
}
catch(InvalidPositionException &e)
{
continue;
block_checked_in_modified = false;
blockchangecount++;
}
}catch(InvalidPositionException &e) {
continue;
}
// Calculate relative position in block
v3s16 relpos = n2pos - blockpos * MAP_BLOCKSIZE;
// Get node straight from the block
MapNode n2 = block->getNode(relpos);
// Calculate relative position in block
v3s16 relpos = n2pos - blockpos * MAP_BLOCKSIZE;
// Get node straight from the block
MapNode n2 = block->getNode(relpos, &is_valid_position);
if (!is_valid_position)
continue;
bool changed = false;
/*
If the neighbor is brighter than the current node,
add to list (it will light up this node on its turn)
*/
if(n2.getLight(bank) > undiminish_light(oldlight))
{
bool changed = false;
/*
If the neighbor is brighter than the current node,
add to list (it will light up this node on its turn)
*/
if (n2.getLight(bank) > undiminish_light(oldlight)) {
lighted_nodes.insert(n2pos, true);
//lighted_nodes.push_back(n2pos);
changed = true;
}
/*
If the neighbor is dimmer than how much light this node
would spread on it, add to list
*/
if (n2.getLight(bank) < newlight) {
if (n2.light_propagates()) {
n2.setLight(bank, newlight);
block->setNode(relpos, n2);
lighted_nodes.insert(n2pos, true);
//lighted_nodes.push_back(n2pos);
changed = true;
}
/*
If the neighbor is dimmer than how much light this node
would spread on it, add to list
*/
if(n2.getLight(bank) < newlight)
{
if(n2.light_propagates())
{
n2.setLight(bank, newlight);
block->setNode(relpos, n2);
lighted_nodes.insert(n2pos, true);
//lighted_nodes.push_back(n2pos);
changed = true;
}
}
// Add to modified_blocks
if(changed == true && block_checked_in_modified == false)
{
// If the block is not found in modified_blocks, add.
if(modified_blocks.find(blockpos) == NULL)
{
modified_blocks.insert(blockpos, block);
}
block_checked_in_modified = true;
}
}
catch(InvalidPositionException &e)
{
continue;
// Add to modified_blocks
if (changed == true && block_checked_in_modified == false) {
// If the block is not found in modified_blocks, add.
if (modified_blocks.find(blockpos) == NULL)
modified_blocks.insert(blockpos, block);
block_checked_in_modified = true;
}
}
}
@ -554,7 +537,7 @@ void Map::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, modified_blocks);
}
@ -589,15 +572,11 @@ v3s16 Map::getBrightestNeighbour(enum LightBank bank, v3s16 p)
for(u16 i=0; i<6; i++){
// Get the position of the neighbor node
v3s16 n2pos = p + dirs[i];
MapNode n2;
try{
n2 = getNode(n2pos);
}
catch(InvalidPositionException &e)
{
bool pos_ok;
MapNode n2 = getNodeNoEx(n2pos,&pos_ok);
if (!pos_ok)
continue;
}
if(n2.getLight(bank) > brightest_light || found_something == false){
if (n2.getLight(bank) > brightest_light || found_something == false) {
brightest_light = n2.getLight(bank);
brightest_pos = n2pos;
found_something = true;
@ -622,40 +601,29 @@ s16 Map::propagateSunlight(v3s16 start,
core::map<v3s16, MapBlock*> & modified_blocks)
{
s16 y = start.Y;
for(; ; y--)
{
for (; ; y--) {
v3s16 pos(start.X, y, start.Z);
v3s16 blockpos = getNodeBlockPos(pos);
MapBlock *block;
try{
block = getBlockNoCreate(blockpos);
}
catch(InvalidPositionException &e)
{
}catch(InvalidPositionException &e) {
break;
}
v3s16 relpos = pos - blockpos*MAP_BLOCKSIZE;
MapNode n = block->getNode(relpos);
bool is_valid_position;
MapNode n = block->getNode(relpos, &is_valid_position);
if (!is_valid_position)
continue;
if(n.sunlight_propagates())
{
if (n.sunlight_propagates()) {
n.setLight(LIGHTBANK_DAY, LIGHT_SUN);
block->setNode(relpos, n);
modified_blocks.insert(blockpos, block);
}
else
{
/*// Turn mud into grass
if(n.getContent() == CONTENT_MUD)
{
n.setContent(CONTENT_GRASS);
block->setNode(relpos, n);
modified_blocks.insert(blockpos, block);
}*/
}else{
// Sunlight goes no further
break;
}
@ -672,10 +640,6 @@ void Map::updateLighting(enum LightBank bank,
//TimeTaker timer("updateLighting");
// For debugging
//bool debug=true;
//u32 count_was = modified_blocks.size();
core::map<v3s16, MapBlock*> blocks_to_update;
core::map<v3s16, bool> light_sources;
@ -684,14 +648,12 @@ void Map::updateLighting(enum LightBank bank,
core::map<v3s16, MapBlock*>::Iterator i;
i = a_blocks.getIterator();
for(; i.atEnd() == false; i++)
{
for (; i.atEnd() == false; i++) {
MapBlock *block = i.getNode()->getValue();
for(;;)
{
for (;;) {
// Don't bother with dummy blocks.
if(block->isDummy())
if (block->isDummy())
break;
v3s16 pos = block->getPos();
@ -702,124 +664,58 @@ void Map::updateLighting(enum LightBank bank,
/*
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++)
{
try{
for (s16 z=0; z<MAP_BLOCKSIZE; z++)
for (s16 x=0; x<MAP_BLOCKSIZE; x++)
for (s16 y=0; y<MAP_BLOCKSIZE; y++) {
v3s16 p(x,y,z);
MapNode n = block->getNode(v3s16(x,y,z));
bool is_valid_position;
MapNode n = block->getNode(v3s16(x,y,z),&is_valid_position);
if (!is_valid_position)
continue;
u8 oldlight = n.getLight(bank);
n.setLight(bank, 0);
block->setNode(v3s16(x,y,z), n);
// Collect borders for unlighting
if(x==0 || x == MAP_BLOCKSIZE-1
|| y==0 || y == MAP_BLOCKSIZE-1
|| z==0 || z == MAP_BLOCKSIZE-1)
{
if (
x==0 || x == MAP_BLOCKSIZE-1
|| y==0 || y == MAP_BLOCKSIZE-1
|| z==0 || z == MAP_BLOCKSIZE-1
) {
v3s16 p_map = p + v3s16(
MAP_BLOCKSIZE*pos.X,
MAP_BLOCKSIZE*pos.Y,
MAP_BLOCKSIZE*pos.Z);
unlight_from.insert(p_map, oldlight);
}
}
catch(InvalidPositionException &e)
{
/*
This would happen when dealing with a
dummy block.
*/
//assert(0);
infostream<<"updateLighting(): InvalidPositionException"
<<std::endl;
}
}
if(bank == LIGHTBANK_DAY)
{
if (bank == LIGHTBANK_DAY) {
bool bottom_valid = block->propagateSunlight(light_sources);
// If bottom is valid, we're done.
if(bottom_valid)
break;
}
else if(bank == LIGHTBANK_NIGHT)
{
}else if (bank == LIGHTBANK_NIGHT) {
// For night lighting, sunlight is not propagated
break;
}
else
{
}else{
// Invalid lighting bank
assert(0);
}
/*infostream<<"Bottom for sunlight-propagated block ("
<<pos.X<<","<<pos.Y<<","<<pos.Z<<") not valid"
<<std::endl;*/
// Bottom sunlight is not valid; get the block and loop to it
pos.Y--;
try{
block = getBlockNoCreate(pos);
}
catch(InvalidPositionException &e)
{
}catch(InvalidPositionException &e) {
assert(0);
}
}
}
/*
Enable this to disable proper lighting for speeding up map
generation for testing or whatever
*/
#if 0
//if(g_settings->get(""))
{
core::map<v3s16, MapBlock*>::Iterator i;
i = blocks_to_update.getIterator();
for(; i.atEnd() == false; i++)
{
MapBlock *block = i.getNode()->getValue();
v3s16 p = block->getPos();
block->setLightingExpired(false);
}
return;
}
#endif
#if 0
{
TimeTaker timer("unspreadLight");
unspreadLight(bank, unlight_from, light_sources, modified_blocks);
}
if(debug)
{
u32 diff = modified_blocks.size() - count_was;
count_was = modified_blocks.size();
infostream<<"unspreadLight modified "<<diff<<std::endl;
}
{
TimeTaker timer("spreadLight");
spreadLight(bank, light_sources, modified_blocks);
}
if(debug)
{
u32 diff = modified_blocks.size() - count_was;
count_was = modified_blocks.size();
infostream<<"spreadLight modified "<<diff<<std::endl;
}
#endif
{
//MapVoxelManipulator vmanip(this);
@ -828,34 +724,13 @@ void Map::updateLighting(enum LightBank bank,
ManualMapVoxelManipulator vmanip(this);
core::map<v3s16, MapBlock*>::Iterator i;
i = blocks_to_update.getIterator();
for(; i.atEnd() == false; i++)
{
for (; i.atEnd() == false; i++) {
MapBlock *block = i.getNode()->getValue();
v3s16 p = block->getPos();
// Add all surrounding blocks
vmanip.initialEmerge(p - v3s16(1,1,1), p + v3s16(1,1,1));
/*
Add all surrounding blocks that have up-to-date lighting
NOTE: This doesn't quite do the job (not everything
appropriate is lighted)
*/
/*for(s16 z=-1; z<=1; z++)
for(s16 y=-1; y<=1; y++)
for(s16 x=-1; x<=1; x++)
{
v3s16 p(x,y,z);
MapBlock *block = getBlockNoCreateNoEx(p);
if(block == NULL)
continue;
if(block->isDummy())
continue;
if(block->getLightingExpired())
continue;
vmanip.initialEmerge(p, p);
}*/
// Lighting of block will be updated completely
block->setLightingExpired(false);
}
@ -872,8 +747,6 @@ void Map::updateLighting(enum LightBank bank,
//TimeTaker timer("blitBack");
vmanip.blitBack(modified_blocks);
}
/*infostream<<"emerge_time="<<emerge_time<<std::endl;
emerge_time = 0;*/
}
//m_dout<<"Done ("<<getTimestamp()<<")"<<std::endl;
@ -925,34 +798,25 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
Otherwise there probably is.
*/
try{
MapNode topnode = getNode(toppos);
if(topnode.getLight(LIGHTBANK_DAY) != LIGHT_SUN)
node_under_sunlight = false;
}
catch(InvalidPositionException &e)
{
bool pos_ok;
MapNode topnode = getNodeNoEx(toppos,&pos_ok);
if (pos_ok && topnode.getLight(LIGHTBANK_DAY) != LIGHT_SUN)
node_under_sunlight = false;
}
#if 0
/*
If the new node is solid and there is grass below, change it to mud
*/
if(content_features(n).walkable == true)
{
try{
MapNode bottomnode = getNode(bottompos);
if (content_features(n).walkable == true) {
bool pos_ok;
MapNode bottomnode = getNodeNoEx(bottompos,&pos_ok);
if(bottomnode.getContent() == CONTENT_GRASS
|| bottomnode.getContent() == CONTENT_GRASS_FOOTSTEPS)
{
bottomnode.setContent(CONTENT_MUD);
setNode(bottompos, bottomnode);
}
}
catch(InvalidPositionException &e)
{
if (pos_ok && (bottomnode.getContent() == CONTENT_GRASS || bottomnode.getContent() == CONTENT_GRASS_FOOTSTEPS)) {
bottomnode.setContent(CONTENT_MUD);
setNode(bottompos, bottomnode);
}
}
#endif
@ -1005,10 +869,8 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
If node lets sunlight through and is under sunlight, it has
sunlight too.
*/
if(node_under_sunlight && content_features(n).sunlight_propagates)
{
if (node_under_sunlight && content_features(n).sunlight_propagates)
n.setLight(LIGHTBANK_DAY, LIGHT_SUN);
}
/*
Set the node on the map
@ -1021,8 +883,7 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
*/
NodeMetadata *meta_proto = content_features(n).initial_metadata;
if(meta_proto)
{
if (meta_proto) {
NodeMetadata *meta = meta_proto->clone();
meta->setOwner(player_name);
setNodeMetadata(p, meta);
@ -1035,24 +896,18 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
TODO: This could be optimized by mass-unlighting instead
of looping
*/
if(node_under_sunlight && !content_features(n).sunlight_propagates)
{
if (node_under_sunlight && !content_features(n).sunlight_propagates) {
s16 y = p.Y - 1;
for(;; y--){
for (;; y--) {
//m_dout<<DTIME<<"y="<<y<<std::endl;
v3s16 n2pos(p.X, y, p.Z);
bool pos_ok;
MapNode n2;
try{
n2 = getNode(n2pos);
}
catch(InvalidPositionException &e)
{
MapNode n2 = getNodeNoEx(n2pos,&pos_ok);
if (!pos_ok)
break;
}
if(n2.getLight(LIGHTBANK_DAY) == LIGHT_SUN)
{
if (n2.getLight(LIGHTBANK_DAY) == LIGHT_SUN) {
unLightNeighbors(LIGHTBANK_DAY,
n2pos, n2.getLight(LIGHTBANK_DAY),
light_sources, modified_blocks);
@ -1064,8 +919,7 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
}
}
for(s32 i=0; i<2; i++)
{
for (s32 i=0; i<2; i++) {
enum LightBank bank = banks[i];
/*
@ -1098,22 +952,12 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
v3s16(0,-1,0), // bottom
v3s16(-1,0,0), // left
};
for(u16 i=0; i<7; i++)
{
try
{
for (u16 i=0; i<7; i++) {
v3s16 p2 = p + dirs[i];
MapNode n2 = getNode(p2);
if(content_liquid(n2.getContent()) || n2.getContent() == CONTENT_AIR)
{
bool pos_ok;
MapNode n2 = getNodeNoEx(p2,&pos_ok);
if (pos_ok && (content_liquid(n2.getContent()) || n2.getContent() == CONTENT_AIR))
m_transforming_liquid.push_back(p2);
}
}catch(InvalidPositionException &e)
{
}
}
}
@ -1137,25 +981,21 @@ void Map::removeNodeAndUpdate(v3s16 p,
If there is a node at top and it doesn't have sunlight,
there will be no sunlight going down.
*/
try{
MapNode topnode = getNode(toppos);
if(topnode.getLight(LIGHTBANK_DAY) != LIGHT_SUN)
node_under_sunlight = false;
}
catch(InvalidPositionException &e)
{
bool pos_ok;
MapNode topnode = getNodeNoEx(toppos,&pos_ok);
if (pos_ok && topnode.getLight(LIGHTBANK_DAY) != LIGHT_SUN)
node_under_sunlight = false;
}
core::map<v3s16, bool> light_sources;
enum LightBank banks[] =
{
enum LightBank banks[] = {
LIGHTBANK_DAY,
LIGHTBANK_NIGHT
};
for(s32 i=0; i<2; i++)
{
for (s32 i=0; i<2; i++) {
enum LightBank bank = banks[i];
/*
@ -1181,8 +1021,7 @@ void Map::removeNodeAndUpdate(v3s16 p,
n.setContent(replace_material);
setNode(p, n);
for(s32 i=0; i<2; i++)
{
for (s32 i=0; i<2; i++) {
enum LightBank bank = banks[i];
/*
@ -1202,50 +1041,39 @@ void Map::removeNodeAndUpdate(v3s16 p,
sunlight down from it and then light all neighbors
of the propagated blocks.
*/
if(node_under_sunlight)
{
if (node_under_sunlight) {
s16 ybottom = propagateSunlight(p, modified_blocks);
/*m_dout<<DTIME<<"Node was under sunlight. "
"Propagating sunlight";
m_dout<<DTIME<<" -> ybottom="<<ybottom<<std::endl;*/
s16 y = p.Y;
for(; y >= ybottom; y--)
{
for (; y >= ybottom; y--) {
v3s16 p2(p.X, y, p.Z);
/*m_dout<<DTIME<<"lighting neighbors of node ("
<<p2.X<<","<<p2.Y<<","<<p2.Z<<")"
<<std::endl;*/
lightNeighbors(LIGHTBANK_DAY, p2, modified_blocks);
}
}
else
{
}else{
// Set the lighting of this node to 0
// TODO: Is this needed? Lighting is cleared up there already.
try{
MapNode n = getNode(p);
bool pos_ok;
MapNode n = getNodeNoEx(p,&pos_ok);
if (pos_ok) {
n.setLight(LIGHTBANK_DAY, 0);
setNode(p, n);
}
catch(InvalidPositionException &e)
{
assert(0);
}
}
for(s32 i=0; i<2; i++)
{
for (s32 i=0; i<2; i++) {
enum LightBank bank = banks[i];
// Get the brightest neighbour node and propagate light from it
v3s16 n2p = getBrightestNeighbour(bank, p);
try{
MapNode n2 = getNode(n2p);
bool pos_ok;
MapNode n2 = getNodeNoEx(n2p,&pos_ok);
if (pos_ok)
lightNeighbors(bank, n2p, modified_blocks);
}
catch(InvalidPositionException &e)
{
}
}
/*
@ -1272,22 +1100,14 @@ void Map::removeNodeAndUpdate(v3s16 p,
v3s16(-1,0,0), // left
v3s16(0,0,0), // self
};
for(u16 i=0; i<7; i++)
{
try
{
for (u16 i=0; i<7; i++) {
bool pos_ok;
v3s16 p2 = p + dirs[i];
MapNode n2 = getNode(p2);
if(content_liquid(n2.getContent()) || n2.getContent() == CONTENT_AIR)
{
MapNode n2 = getNodeNoEx(p2,&pos_ok);
if (pos_ok && (content_liquid(n2.getContent()) || n2.getContent() == CONTENT_AIR))
m_transforming_liquid.push_back(p2);
}
}catch(InvalidPositionException &e)
{
}
}
}
@ -4370,10 +4190,9 @@ void MapVoxelManipulator::emerge(VoxelArea a, s32 caller_id)
This will make it interfere less with important stuff if
run on background.
*/
void MapVoxelManipulator::blitBack
(core::map<v3s16, MapBlock*> & modified_blocks)
void MapVoxelManipulator::blitBack(core::map<v3s16, MapBlock*> & modified_blocks)
{
if(m_area.getExtent() == v3s16(0,0,0))
if (m_area.getExtent() == v3s16(0,0,0))
return;
//TimeTaker timer1("blitBack");
@ -4388,50 +4207,42 @@ void MapVoxelManipulator::blitBack
MapBlock *block = NULL;
bool block_checked_in_modified = false;
for(s32 z=m_area.MinEdge.Z; z<=m_area.MaxEdge.Z; z++)
for(s32 y=m_area.MinEdge.Y; y<=m_area.MaxEdge.Y; y++)
for(s32 x=m_area.MinEdge.X; x<=m_area.MaxEdge.X; x++)
{
for (s32 z=m_area.MinEdge.Z; z<=m_area.MaxEdge.Z; z++)
for (s32 y=m_area.MinEdge.Y; y<=m_area.MaxEdge.Y; y++)
for (s32 x=m_area.MinEdge.X; x<=m_area.MaxEdge.X; x++) {
v3s16 p(x,y,z);
u8 f = m_flags[m_area.index(p)];
if(f & (VOXELFLAG_NOT_LOADED|VOXELFLAG_INEXISTENT))
if (f & (VOXELFLAG_NOT_LOADED|VOXELFLAG_INEXISTENT))
continue;
MapNode &n = m_data[m_area.index(p)];
v3s16 blockpos = getNodeBlockPos(p);
try
{
// Get block
if(block == NULL || blockpos != blockpos_last){
block = m_map->getBlockNoCreate(blockpos);
blockpos_last = blockpos;
block_checked_in_modified = false;
}
// Calculate relative position in block
v3s16 relpos = p - blockpos * MAP_BLOCKSIZE;
// Don't continue if nothing has changed here
if(block->getNode(relpos) == n)
continue;
//m_map->setNode(m_area.MinEdge + p, n);
block->setNode(relpos, n);
/*
Make sure block is in modified_blocks
*/
if(block_checked_in_modified == false)
{
modified_blocks[blockpos] = block;
block_checked_in_modified = true;
}
if (block == NULL || blockpos != blockpos_last) {
block = m_map->getBlockNoCreate(blockpos);
blockpos_last = blockpos;
block_checked_in_modified = false;
}
catch(InvalidPositionException &e)
{
// Calculate relative position in block
v3s16 relpos = p - blockpos * MAP_BLOCKSIZE;
// Don't continue if nothing has changed here
bool is_valid_position;
if (block->getNode(relpos,&is_valid_position) == n || !is_valid_position)
continue;
//m_map->setNode(m_area.MinEdge + p, n);
block->setNode(relpos, n);
/*
Make sure block is in modified_blocks
*/
if (block_checked_in_modified == false) {
modified_blocks[blockpos] = block;
block_checked_in_modified = true;
}
}
}

View File

@ -173,7 +173,7 @@ public:
void setNode(v3s16 p, MapNode & n);
// Returns a CONTENT_IGNORE node if not found
MapNode getNodeNoEx(v3s16 p);
MapNode getNodeNoEx(v3s16 p, bool *is_valid_position = NULL);
void unspreadLight(enum LightBank bank,
core::map<v3s16, u8> & from_nodes,

View File

@ -79,65 +79,34 @@ MapBlock::~MapBlock()
bool MapBlock::isValidPositionParent(v3s16 p)
{
if(isValidPosition(p))
{
if (isValidPosition(p.X,p.Y,p.Z))
return true;
}
else{
return m_parent->isValidPosition(getPosRelative() + p);
}
return m_parent->isValidPosition(getPosRelative() + p);
}
MapNode MapBlock::getNodeParent(v3s16 p)
MapNode MapBlock::getNodeParent(v3s16 p, bool *is_valid_position)
{
if(isValidPosition(p) == false)
{
return m_parent->getNode(getPosRelative() + p);
}
else
{
if(data == NULL)
throw InvalidPositionException();
return data[p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X];
if (isValidPosition(p.X,p.Y,p.Z) == false)
return m_parent->getNodeNoEx(getPosRelative() + p, is_valid_position);
if (data == NULL) {
if (is_valid_position)
*is_valid_position = false;
return MapNode(CONTENT_IGNORE);
}
if (is_valid_position)
*is_valid_position = true;
return data[p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X];
}
void MapBlock::setNodeParent(v3s16 p, MapNode & n)
{
if(isValidPosition(p) == false)
{
if (isValidPosition(p.X,p.Y,p.Z) == false) {
m_parent->setNode(getPosRelative() + p, n);
}
else
{
if(data == NULL)
throw InvalidPositionException();
}else{
data[p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X] = n;
}
}
MapNode MapBlock::getNodeParentNoEx(v3s16 p)
{
if(isValidPosition(p) == false)
{
try{
return m_parent->getNode(getPosRelative() + p);
}
catch(InvalidPositionException &e)
{
return MapNode(CONTENT_IGNORE);
}
}
else
{
if(data == NULL)
{
return MapNode(CONTENT_IGNORE);
}
return data[p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X];
}
}
#ifndef SERVER
#if 1
@ -248,36 +217,27 @@ bool MapBlock::propagateSunlight(core::map<v3s16, bool> & light_sources,
bool no_sunlight = false;
bool no_top_block = false;
// Check if node above block has sunlight
try{
MapNode n = getNodeParent(v3s16(x, MAP_BLOCKSIZE, z));
if(n.getContent() == CONTENT_IGNORE)
{
bool is_valid_position;
MapNode n = getNodeParent(v3s16(x, MAP_BLOCKSIZE, z), &is_valid_position);
if (is_valid_position) {
if (n.getContent() == CONTENT_IGNORE) {
// Trust heuristics
no_sunlight = is_underground;
}
else if(n.getLight(LIGHTBANK_DAY) != LIGHT_SUN)
{
}else if (n.getLight(LIGHTBANK_DAY) != LIGHT_SUN) {
no_sunlight = true;
}
}
catch(InvalidPositionException &e)
{
}else{
no_top_block = true;
// NOTE: This makes over-ground roofed places sunlighted
// Assume sunlight, unless is_underground==true
if(is_underground)
{
if (is_underground) {
no_sunlight = true;
}
else
{
MapNode n = getNode(v3s16(x, MAP_BLOCKSIZE-1, z));
}else{
MapNode n = getNodeNoEx(v3s16(x, MAP_BLOCKSIZE-1, z));
//if(n.getContent() == CONTENT_WATER || n.getContent() == CONTENT_WATERSOURCE)
if(content_features(n).sunlight_propagates == false)
{
if (content_features(n).sunlight_propagates == false)
no_sunlight = true;
}
}
// NOTE: As of now, this just would make everything dark.
// No sunlight here
@ -948,7 +908,7 @@ std::string analyze_block(MapBlock *block)
for(s16 x0=0; x0<MAP_BLOCKSIZE; x0++)
{
v3s16 p(x0,y0,z0);
MapNode n = block->getNode(p);
MapNode n = block->getNodeNoEx(p);
content_t c = n.getContent();
if(c == CONTENT_IGNORE)
some_ignore = true;

View File

@ -288,46 +288,43 @@ public:
Regular MapNode get-setters
*/
bool isValidPosition(v3s16 p)
bool isValidPosition(s16 x, s16 y, s16 z)
{
if(data == NULL)
if (data == NULL)
return false;
return (p.X >= 0 && p.X < MAP_BLOCKSIZE
&& p.Y >= 0 && p.Y < MAP_BLOCKSIZE
&& p.Z >= 0 && p.Z < MAP_BLOCKSIZE);
return (
x >= 0 && x < MAP_BLOCKSIZE
&& y >= 0 && y < MAP_BLOCKSIZE
&& z >= 0 && z < MAP_BLOCKSIZE
);
}
MapNode getNode(s16 x, s16 y, s16 z)
MapNode getNode(s16 x, s16 y, s16 z, bool *valid_position)
{
if(data == NULL)
throw InvalidPositionException();
if(x < 0 || x >= MAP_BLOCKSIZE) throw InvalidPositionException();
if(y < 0 || y >= MAP_BLOCKSIZE) throw InvalidPositionException();
if(z < 0 || z >= MAP_BLOCKSIZE) throw InvalidPositionException();
*valid_position = isValidPosition(x, y, z);
if (!*valid_position)
return MapNode(CONTENT_IGNORE);
return data[z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + y*MAP_BLOCKSIZE + x];
}
MapNode getNode(v3s16 p)
MapNode getNode(v3s16 p, bool *valid_position)
{
return getNode(p.X, p.Y, p.Z);
return getNode(p.X, p.Y, p.Z, valid_position);
}
MapNode getNodeNoEx(v3s16 p)
{
try{
return getNode(p.X, p.Y, p.Z);
}catch(InvalidPositionException &e){
bool is_valid;
MapNode node = getNode(p.X, p.Y, p.Z, &is_valid);
if (!is_valid)
return MapNode(CONTENT_IGNORE);
}
return node;
}
void setNode(s16 x, s16 y, s16 z, MapNode & n)
{
if(data == NULL)
if (!isValidPosition(x,y,z))
throw InvalidPositionException();
if(x < 0 || x >= MAP_BLOCKSIZE) throw InvalidPositionException();
if(y < 0 || y >= MAP_BLOCKSIZE) throw InvalidPositionException();
if(z < 0 || z >= MAP_BLOCKSIZE) throw InvalidPositionException();
data[z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + y*MAP_BLOCKSIZE + x] = n;
raiseModified(MOD_STATE_WRITE_NEEDED);
}
@ -339,13 +336,7 @@ public:
void incNodeTicks(v3s16 p)
{
if (data == NULL)
return;
if (p.X < 0 || p.X >= MAP_BLOCKSIZE)
return;
if (p.Y < 0 || p.Y >= MAP_BLOCKSIZE)
return;
if (p.Z < 0 || p.Z >= MAP_BLOCKSIZE)
if (!isValidPosition(p.X,p.Y,p.Z))
return;
data[p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X].envticks++;
}
@ -354,16 +345,17 @@ public:
Non-checking variants of the above
*/
MapNode getNodeNoCheck(s16 x, s16 y, s16 z)
MapNode getNodeNoCheck(s16 x, s16 y, s16 z, bool *valid_position)
{
if(data == NULL)
throw InvalidPositionException();
*valid_position = isValidPosition(x, y, z);
if (!*valid_position)
return MapNode(CONTENT_IGNORE);
return data[z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + y*MAP_BLOCKSIZE + x];
}
MapNode getNodeNoCheck(v3s16 p)
MapNode getNodeNoCheck(v3s16 p, bool *valid_position)
{
return getNodeNoCheck(p.X, p.Y, p.Z);
return getNodeNoCheck(p.X, p.Y, p.Z, valid_position);
}
void setNodeNoCheck(s16 x, s16 y, s16 z, MapNode & n)
@ -384,9 +376,8 @@ public:
is not valid on this MapBlock.
*/
bool isValidPositionParent(v3s16 p);
MapNode getNodeParent(v3s16 p);
MapNode getNodeParent(v3s16 p, bool *is_valid_position = NULL);
void setNodeParent(v3s16 p, MapNode & n);
MapNode getNodeParentNoEx(v3s16 p);
void drawbox(s16 x0, s16 y0, s16 z0, s16 w, s16 h, s16 d, MapNode node)
{
@ -414,8 +405,8 @@ public:
u8 getFaceLight2(u32 daynight_ratio, v3s16 p, v3s16 face_dir)
{
return getFaceLight(daynight_ratio,
getNodeParentNoEx(p),
getNodeParentNoEx(p + face_dir),
getNodeParent(p),
getNodeParent(p + face_dir),
face_dir);
}

View File

@ -86,9 +86,8 @@ public:
v3f getEyeOffset()
{
// This is at the height of the eyes of the current figure
// return v3f(0, BS+BS/2, 0);
// This is more like in minecraft
return v3f(0,BS+(5*BS)/8,0);
v3f s = getScale();
return v3f(0,(BS+((5*BS)/8))*s.Y,0);
}
v3f getEyePosition()