#include <sstream>
#include "map.h"
-// For g_settings
-#include "main.h"
#include "light.h"
#include "nodedef.h"
#include "nodemetadata.h"
#include "nameidmapping.h"
#include "content_mapnode.h" // For legacy name-id mapping
#include "content_nodemeta.h" // For legacy deserialization
+#include "serialization.h"
#ifndef SERVER
#include "mapblock_mesh.h"
#endif
*/
MapBlock::MapBlock(Map *parent, v3s16 pos, IGameDef *gamedef, bool dummy):
- heat(0),
- heat_time(0),
- humidity(0),
- humidity_time(0),
m_parent(parent),
m_pos(pos),
m_gamedef(gamedef),
reallocate();
#ifndef SERVER
- //mesh_mutex.Init();
mesh = NULL;
#endif
}
}
}
-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) == false)
+ return m_parent->getNodeNoEx(getPosRelative() + p, is_valid_position);
-void MapBlock::setNodeParent(v3s16 p, MapNode & n)
-{
- if(isValidPosition(p) == false)
- {
- m_parent->setNode(getPosRelative() + p, n);
- }
- else
- {
- if(data == NULL)
- throw InvalidPositionException();
- 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];
+ 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];
}
/*
#if 1
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));
+
+ 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 = true;
}
}
- catch(InvalidPositionException &e)
+ else
{
no_top_block = true;
}
else
{
- MapNode n = getNode(v3s16(x, MAP_BLOCKSIZE-1, z));
+ MapNode n = getNodeNoEx(v3s16(x, MAP_BLOCKSIZE-1, z));
if(m_gamedef->ndef()->get(n).sunlight_propagates == false)
{
no_sunlight = true;
Ignore non-transparent nodes as they always have no light
*/
- try
- {
+
if(block_below_is_valid)
{
- MapNode n = getNodeParent(v3s16(x, -1, z));
- if(nodemgr->get(n).light_propagates)
+ MapNode n = getNodeParent(v3s16(x, -1, z), &is_valid_position);
+ if (is_valid_position) {
+ if(nodemgr->get(n).light_propagates)
+ {
+ if(n.getLight(LIGHTBANK_DAY, nodemgr) == LIGHT_SUN
+ && sunlight_should_go_down == false)
+ block_below_is_valid = false;
+ else if(n.getLight(LIGHTBANK_DAY, nodemgr) != LIGHT_SUN
+ && sunlight_should_go_down == true)
+ block_below_is_valid = false;
+ }
+ }
+ else
{
- if(n.getLight(LIGHTBANK_DAY, nodemgr) == LIGHT_SUN
- && sunlight_should_go_down == false)
- block_below_is_valid = false;
- else if(n.getLight(LIGHTBANK_DAY, nodemgr) != LIGHT_SUN
- && sunlight_should_go_down == true)
- block_below_is_valid = false;
+ /*std::cout<<"InvalidBlockException for bottom block node"
+ <<std::endl;*/
+ // Just no block below, no need to panic.
}
- }//if
- }//try
- catch(InvalidPositionException &e)
- {
- /*std::cout<<"InvalidBlockException for bottom block node"
- <<std::endl;*/
- // Just no block below, no need to panic.
}
}
}
*/
// List relevant id-name pairs for ids in the block using nodedef
// Renumbers the content IDs (starting at 0 and incrementing
+// use static memory requires about 65535 * sizeof(int) ram in order to be
+// sure we can handle all content ids. But it's absolutely worth it as it's
+// a speedup of 4 for one of the major time consuming functions on storing
+// mapblocks.
+static content_t getBlockNodeIdMapping_mapping[USHRT_MAX];
static void getBlockNodeIdMapping(NameIdMapping *nimap, MapNode *nodes,
INodeDefManager *nodedef)
{
- std::map<content_t, content_t> mapping;
+ memset(getBlockNodeIdMapping_mapping, 0xFF, USHRT_MAX * sizeof(content_t));
+
std::set<content_t> unknown_contents;
content_t id_counter = 0;
for(u32 i=0; i<MAP_BLOCKSIZE*MAP_BLOCKSIZE*MAP_BLOCKSIZE; i++)
content_t id = CONTENT_IGNORE;
// Try to find an existing mapping
- std::map<content_t, content_t>::iterator j = mapping.find(global_id);
- if(j != mapping.end())
- {
- id = j->second;
+ if (getBlockNodeIdMapping_mapping[global_id] != 0xFFFF) {
+ id = getBlockNodeIdMapping_mapping[global_id];
}
else
{
// We have to assign a new mapping
id = id_counter++;
- mapping.insert(std::make_pair(global_id, id));
+ getBlockNodeIdMapping_mapping[global_id] = id;
const ContentFeatures &f = nodedef->get(global_id);
const std::string &name = f.name;
if(net_proto_version >= 21){
int version = 1;
writeU8(os, version);
- writeF1000(os, heat);
- writeF1000(os, humidity);
+ writeF1000(os, 0); // deprecated heat
+ writeF1000(os, 0); // deprecated humidity
}
}
//if(version != 1)
// throw SerializationError("unsupported MapBlock version");
if(version >= 1) {
- heat = readF1000(is);
- humidity = readF1000(is);
+ readF1000(is); // deprecated heat
+ readF1000(is); // deprecated humidity
}
}
catch(SerializationError &e)
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;