diff options
author | Perttu Ahola <celeron55@gmail.com> | 2011-06-26 02:34:36 +0300 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2011-06-26 02:34:36 +0300 |
commit | bb940a946dbca49dc03af83fe55d195bd9fdc62e (patch) | |
tree | 0f78d66110f1d3d477875ae47927a8e7e6d20ec3 /src/map.cpp | |
parent | 2915bd5518150955ed1581110527f4bb4adadfe8 (diff) | |
download | minetest-bb940a946dbca49dc03af83fe55d195bd9fdc62e.tar.gz minetest-bb940a946dbca49dc03af83fe55d195bd9fdc62e.tar.bz2 minetest-bb940a946dbca49dc03af83fe55d195bd9fdc62e.zip |
even more code refactoring
Diffstat (limited to 'src/map.cpp')
-rw-r--r-- | src/map.cpp | 84 |
1 files changed, 57 insertions, 27 deletions
diff --git a/src/map.cpp b/src/map.cpp index d8cc34ca7..3164028b7 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "serverobject.h" #include "content_mapnode.h" #include "mapgen.h" +#include "nodemetadata.h" extern "C" { #include "sqlite3.h" @@ -141,19 +142,6 @@ MapBlock * Map::getBlockNoCreate(v3s16 p3d) return block; } - -/*MapBlock * Map::getBlockCreate(v3s16 p3d) -{ - v2s16 p2d(p3d.X, p3d.Z); - MapSector * sector = getSectorCreate(p2d); - assert(sector); - MapBlock *block = sector->getBlockNoCreate(p3d.Y); - if(block) - return block; - block = sector->createBlankBlock(p3d.Y); - return block; -}*/ - bool Map::isNodeUnderground(v3s16 p) { v3s16 blockpos = getNodeBlockPos(p); @@ -167,6 +155,45 @@ bool Map::isNodeUnderground(v3s16 p) } } +bool Map::isValidPosition(v3s16 p) +{ + v3s16 blockpos = getNodeBlockPos(p); + MapBlock *block = getBlockNoCreate(blockpos); + return (block != NULL); +} + +// Returns a CONTENT_IGNORE node if not found +MapNode Map::getNodeNoEx(v3s16 p) +{ + v3s16 blockpos = getNodeBlockPos(p); + MapBlock *block = getBlockNoCreateNoEx(blockpos); + if(block == NULL) + return MapNode(CONTENT_IGNORE); + v3s16 relpos = p - blockpos*MAP_BLOCKSIZE; + return block->getNodeNoCheck(relpos); +} + +// throws InvalidPositionException if not found +MapNode Map::getNode(v3s16 p) +{ + v3s16 blockpos = getNodeBlockPos(p); + MapBlock *block = getBlockNoCreateNoEx(blockpos); + if(block == NULL) + throw InvalidPositionException(); + v3s16 relpos = p - blockpos*MAP_BLOCKSIZE; + return block->getNodeNoCheck(relpos); +} + +// throws InvalidPositionException if not found +void Map::setNode(v3s16 p, MapNode & n) +{ + v3s16 blockpos = getNodeBlockPos(p); + MapBlock *block = getBlockNoCreate(blockpos); + v3s16 relpos = p - blockpos*MAP_BLOCKSIZE; + block->setNodeNoCheck(relpos, n); +} + + /* Goes recursively through the neighbours of the node. @@ -2096,22 +2123,25 @@ MapBlock* ServerMap::finishBlockMake(mapgen::BlockMakeData *data, /* Update lighting */ - - core::map<v3s16, MapBlock*> lighting_update_blocks; - // Center block - lighting_update_blocks.insert(block->getPos(), block); -#if 0 - // All modified blocks - for(core::map<v3s16, MapBlock*>::Iterator - i = changed_blocks.getIterator(); - i.atEnd() == false; i++) { - lighting_update_blocks.insert(i.getNode()->getKey(), - i.getNode()->getValue()); + TimeTaker t("finishBlockMake lighting update"); + + core::map<v3s16, MapBlock*> lighting_update_blocks; + // Center block + lighting_update_blocks.insert(block->getPos(), block); + #if 0 + // All modified blocks + for(core::map<v3s16, MapBlock*>::Iterator + i = changed_blocks.getIterator(); + i.atEnd() == false; i++) + { + lighting_update_blocks.insert(i.getNode()->getKey(), + i.getNode()->getValue()); + } + #endif + updateLighting(lighting_update_blocks, changed_blocks); } -#endif - updateLighting(lighting_update_blocks, changed_blocks); - + /* Add random objects to block */ |