#include "database.h"
#include "database-dummy.h"
#include "database-sqlite3.h"
+#include <deque>
#if USE_LEVELDB
#include "database-leveldb.h"
#endif
v3s16 n2pos = pos + dirs[i];
// Get the block where the node is located
- v3s16 blockpos = getNodeBlockPos(n2pos);
+ v3s16 blockpos, relpos;
+ getNodeBlockPosWithOffset(n2pos, blockpos, relpos);
// Only fetch a new block if the block position has changed
try {
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);
}
/*infostream<<"unspreadLight(): Changed block "
- <<blockchangecount<<" times"
- <<" for "<<from_nodes.size()<<" nodes"
- <<std::endl;*/
+ <<blockchangecount<<" times"
+ <<" for "<<from_nodes.size()<<" nodes"
+ <<std::endl;*/
if(!unlighted_nodes.empty())
unspreadLight(bank, unlighted_nodes, light_sources, modified_blocks);
*/
v3s16 blockpos_last;
MapBlock *block = NULL;
- // Cache this a bit, too
+ // Cache this a bit, too
bool block_checked_in_modified = false;
for(std::set<v3s16>::iterator j = from_nodes.begin();
j != from_nodes.end(); ++j)
{
v3s16 pos = *j;
- v3s16 blockpos = getNodeBlockPos(pos);
+ v3s16 blockpos, relpos;
+
+ getNodeBlockPosWithOffset(pos, blockpos, relpos);
// Only fetch a new block if the block position has changed
try {
if(block->isDummy())
continue;
- // Calculate relative position in block
- v3s16 relpos = pos - blockpos_last * MAP_BLOCKSIZE;
-
// Get node straight from the block
bool is_valid_position;
MapNode n = block->getNode(relpos, &is_valid_position);
v3s16 n2pos = pos + dirs[i];
// Get the block where the node is located
- v3s16 blockpos = getNodeBlockPos(n2pos);
+ v3s16 blockpos, relpos;
+ getNodeBlockPosWithOffset(n2pos, blockpos, relpos);
// Only fetch a new block if the block position has changed
try {
continue;
}
- // 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)
//bool debug=true;
//u32 count_was = modified_blocks.size();
- std::map<v3s16, MapBlock*> blocks_to_update;
+ //std::map<v3s16, MapBlock*> blocks_to_update;
std::set<v3s16> light_sources;
v3s16 pos = block->getPos();
v3s16 posnodes = block->getPosRelative();
modified_blocks[pos] = block;
- blocks_to_update[pos] = block;
+ //blocks_to_update[pos] = block;
/*
Clear all light from block
infostream<<"transformLiquids(): initial_size="<<initial_size<<std::endl;*/
// list of nodes that due to viscosity have not reached their max level height
- UniqueQueue<v3s16> must_reflow;
+ std::deque<v3s16> must_reflow;
// List of MapBlocks that will require a lighting update (due to lava)
std::map<v3s16, MapBlock*> lighting_modified_blocks;
}
}
//infostream<<"Map::transformLiquids(): loopcount="<<loopcount<<std::endl;
- while (must_reflow.size() > 0)
- {
- m_transforming_liquid.push_back(must_reflow.front());
- must_reflow.pop_front();
- }
+
+ for (std::deque<v3s16>::iterator iter = must_reflow.begin(); iter != must_reflow.end(); ++iter)
+ m_transforming_liquid.push_back(*iter);
+
updateLighting(lighting_modified_blocks, modified_blocks);
}
}
}
+ void raiseModified(u32 mod, const char *reason)
+ {
+ if (mod > m_modified){
+ m_modified = mod;
+ m_modified_reason = reason;
+ m_modified_reason_too_long = false;
+
+ if (m_modified >= MOD_STATE_WRITE_AT_UNLOAD){
+ m_disk_timestamp = m_timestamp;
+ }
+ }
+ else if (mod == m_modified){
+ if (!m_modified_reason_too_long){
+ if (m_modified_reason.size() < 40)
+ m_modified_reason += ", " + std::string(reason);
+ else{
+ m_modified_reason += "...";
+ m_modified_reason_too_long = true;
+ }
+ }
+ }
+ }
+
u32 getModified()
{
return m_modified;
return getContainerPos(y, MAP_BLOCKSIZE);
}
+inline void getNodeBlockPosWithOffset(const v3s16 &p, v3s16 &block, v3s16 &offset)
+{
+ getContainerPosWithOffset(p, MAP_BLOCKSIZE, block, offset);
+}
+
+inline void getNodeSectorPosWithOffset(const v2s16 &p, v2s16 &block, v2s16 &offset)
+{
+ getContainerPosWithOffset(p, MAP_BLOCKSIZE, block, offset);
+}
+
/*
Get a quick string to describe what a block actually contains
*/
);
}
+inline void getContainerPosWithOffset(s16 p, s16 d, s16 &container, s16 &offset)
+{
+ container = (p >= 0 ? p : p - d + 1) / d;
+ offset = p & (d - 1);
+}
+
+inline void getContainerPosWithOffset(const v2s16 &p, s16 d, v2s16 &container, v2s16 &offset)
+{
+ getContainerPosWithOffset(p.X, d, container.X, offset.X);
+ getContainerPosWithOffset(p.Y, d, container.Y, offset.Y);
+}
+
+inline void getContainerPosWithOffset(const v3s16 &p, s16 d, v3s16 &container, v3s16 &offset)
+{
+ getContainerPosWithOffset(p.X, d, container.X, offset.X);
+ getContainerPosWithOffset(p.Y, d, container.Y, offset.Y);
+ getContainerPosWithOffset(p.Z, d, container.Z, offset.Z);
+}
+
+
inline bool isInArea(v3s16 p, s16 d)
{
return (